summary refs log tree commit diff stats
path: root/tests/stdlib/txmltree.nim
blob: 4362f5ec32b2a7dfd1f26785f4d8803ffacce6d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import std/[xmltree, assertions, xmlparser]


block:
  var
    x: XmlNode

  x = <>a(href = "http://nim-lang.org", newText("Nim rules."))
  doAssert $x == """<a href="http://nim-lang.org">Nim rules.</a>"""

  x = <>outer(<>inner())
  doAssert $x == """<outer>
  <inner />
</outer>"""

  x = <>outer(<>middle(<>inner1(), <>inner2(), <>inner3(), <>inner4()))
  doAssert $x == """<outer>
  <middle>
    <inner1 />
    <inner2 />
    <inner3 />
    <inner4 />
  </middle>
</outer>"""

  x = <>l0(<>l1(<>l2(<>l3(<>l4()))))
  doAssert $x == """<l0>
  <l1>
    <l2>
      <l3>
        <l4 />
      </l3>
    </l2>
  </l1>
</l0>"""

  x = <>l0(<>l1p1(), <>l1p2(), <>l1p3())
  doAssert $x == """<l0>
  <l1p1 />
  <l1p2 />
  <l1p3 />
</l0>"""

  x = <>l0(<>l1(<>l2p1(), <>l2p2()))
  doAssert $x == """<l0>
  <l1>
    <l2p1 />
    <l2p2 />
  </l1>
</l0>"""

  x = <>l0(<>l1(<>l2_1(), <>l2_2(<>l3_1(), <>l3_2(), <>l3_3(<>l4_1(), <>l4_2(), <>l4_3())), <>l2_3(), <>l2_4()))
  doAssert $x == """<l0>
  <l1>
    <l2_1 />
    <l2_2>
      <l3_1 />
      <l3_2 />
      <l3_3>
        <l4_1 />
        <l4_2 />
        <l4_3 />
      </l3_3>
    </l2_2>
    <l2_3 />
    <l2_4 />
  </l1>
</l0>"""

  let
    innermost = newElement("innermost")
    middle = newXmlTree("middle", [innermost])
  innermost.add newText("innermost text")
  x = newXmlTree("outer", [middle])
  doAssert $x == """<outer>
  <middle>
    <innermost>innermost text</innermost>
  </middle>
</outer>"""

  x = newElement("myTag")
  x.add newText("my text")
  x.add newElement("sonTag")
  x.add newEntity("my entity")
  doAssert $x == "<myTag>my text<sonTag />&my entity;</myTag>"

block: # bug #21290
  let x = newXmlTree("foo",[
    newXmlTree("bar",[
      newText("Hola"),
      newXmlTree("qux",[
        newXmlTree("plugh",[])
      ])
    ])
  ])

  let s = $x
  doAssert $parseXml(s) == s
  doAssert s == """<foo>
  <bar>Hola<qux>    <plugh />  </qux></bar>
</foo>"""
href='#n41'>41 42 43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112














                                                                       
             
               

                   

                       
               

                                                                         


                                                
 
                
                                                            
 



                                  
                                          






                                                      

                                                        


                                                                    
                                                                          
                                             
 








                                                                              








                                                                        










                                                                                  


                            
                                                                   
 
      
                           

                                                        
             
                                                    





                                                  
         
                                                    
                                                      
 
     
                         

   
                                       

         
                                                                                                    
 
                                                                
                                  
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

NAME = ranger
VERSION = 1.0.4
PYTHON ?= python
DOCDIR ?= doc/pydoc
PREFIX ?= /usr
MANPREFIX ?= /share/man
PYOPTIMIZE ?= 1
PYTHON_SITE_DEST ?= $(shell $(PYTHON) -c 'import sys; sys.stdout.write( \
	[p for p in sys.path if "site" in p][0])' 2> /dev/null)
BMCOUNT ?= 5  # how often to run the benchmarks?

CWD = $(shell pwd)

default: compile
	@echo 'Run `make options` for a list of all options'

options: help
	@echo
	@echo 'Options:'
	@echo 'PYTHON = $(PYTHON)'
	@echo 'PYOPTIMIZE = $(PYOPTIMIZE)'
	@echo 'PYTHON_SITE_DEST = $(PYTHON_SITE_DEST)'
	@echo 'PREFIX = $(PREFIX)'
	@echo 'MANPREFIX = $(MANPREFIX)'
	@echo 'DOCDIR = $(DOCDIR)'

help:
	@echo 'make: Compile $(NAME)'
	@echo 'make doc: Create the pydoc documentation'
	@echo 'make install: Install ranger'
	@echo 'make clean: Remove the compiled files (*.pyc, *.pyo)'
	@echo 'make cleandoc: Remove the pydoc documentation'
	@echo 'make uninstall: Uninstall ranger'
	@echo 'make snapshot: Create a tar.gz of the current git revision'
	@echo 'make test: Run all unittests.'

all: test compile install

install:
	@if [ '$(PYTHON_SITE_DEST)' == '' ]; then \
		echo -n 'Cannot find a suitable destination for the files.'; \
		echo '  Please install $(NAME) manually.'; \
		false; \
	fi
	@echo "Installing $(NAME) version $(VERSION)..."
	@mkdir -p $(DESTDIR)$(PREFIX)/bin
	cp -f ranger.py $(DESTDIR)$(PREFIX)/bin/ranger
	@mkdir -p $(DESTDIR)$(PYTHON_SITE_DEST)
	cp -fruT ranger $(DESTDIR)$(PYTHON_SITE_DEST)/ranger
	@chmod 755 $(DESTDIR)$(PREFIX)/bin/ranger
	@chmod -R +rX $(DESTDIR)$(PYTHON_SITE_DEST)/ranger
	@mkdir -p $(DESTDIR)$(PREFIX)$(MANPREFIX)/man1
	cp -f doc/ranger.1 $(DESTDIR)$(PREFIX)$(MANPREFIX)/man1/ranger.1
	@chmod 644 $(DESTDIR)$(PREFIX)$(MANPREFIX)/man1/ranger.1

uninstall:
	rm -f $(PREFIX)/bin/ranger
	rm -f '$(PREFIX)$(MANPREFIX)/man1/ranger.1'
	@if [ '$(PYTHON_SITE_DEST)' == '' ]; then \
		echo 'Cannot find a possible location of rangers library files'; \
		false; \
	fi
	rm -rf '$(PYTHON_SITE_DEST)/ranger/*'
	@echo 'NOTE: By default, configuration files are stored at "~/.ranger".'
	@echo 'This script will not delete those.'

compile: clean
	@echo 'Compiling...'
	PYTHONOPTIMIZE=$(PYOPTIMIZE) python -m compileall -q ranger

clean:
	@echo 'Cleaning...'
	find . -regex .\*.py[co]\$$ -exec rm -f -- {} \;

doc: cleandoc
	@echo 'Creating pydoc html documentation...'
	mkdir -p $(DOCDIR)
	cd $(DOCDIR); \
		$(PYTHON) -c 'import pydoc, sys; \
		sys.path[0] = "$(CWD)"; \
		pydoc.writedocs("$(CWD)")'

cleandoc:
	@echo 'Removing pydoc html documentation...'
	test -d $(DOCDIR) && rm -f -- $(DOCDIR)/*.html

test:
	@./all_tests.py 1

bm:
	@./all_benchmarks.py $(BMCOUNT)

snapshot:
	git archive HEAD | gzip > $(NAME)-$(VERSION)-$(shell git rev-parse HEAD | cut -b 1-8).tar.gz

.PHONY: default options all compile clean doc cleandoc test bm \
	install uninstall snapshot