1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
11 # Test suite for `testing`.
12 module test_testing
is test
14 import saxophonit
::testing
16 class TestSaxEventLogger
19 # Constants for diff formatting.
21 # Treminal’s default formatting.
22 private var default
: String is noinit
24 # Formatting for insertions.
25 private var ins
: String is noinit
27 # Formatting for emphased insertions.
28 private var ins_em
: String is noinit
30 # Formatting for deletions.
31 private var del
: String is noinit
33 # Formatting for emphased deletions
34 private var del_em
: String is noinit
37 private var a
= new SAXEventLogger
38 private var b
= new SAXEventLogger
40 private var init_done
: Bool = false
42 fun before_test
is before
do
44 default
= a
.term_default
45 ins
= a
.term_insertion
46 ins_em
= a
.term_insertion_emphasis
48 del_em
= a
.term_deletion_emphasis
55 private fun assert_equals
(id
: Int, expected
: String, actual
: String) do
56 assert equals
: expected
== actual
else
57 sys
.stderr
.write
("\nAssert {id} failed. Expected:\n")
58 sys
.stderr
.write
(expected
)
59 sys
.stderr
.write
("\nGot:\n")
60 sys
.stderr
.write
(actual
)
61 sys
.stderr
.write
("\n")
65 fun test_diff_empty
is test
do
66 assert "" == a
.diff
(b
).to_s
67 assert "" == b
.diff
(a
).to_s
70 fun test_diff_equal1
is test
do
73 assert "" == a
.diff
(b
).to_s
74 assert "" == b
.diff
(a
).to_s
77 fun test_diff_equal2
is test
do
82 assert "" == a
.diff
(b
).to_s
83 assert "" == b
.diff
(a
).to_s
86 fun test_diff_insertion
is test
do
91 b
.start_dtd
("html", "", "")
96 a
.start_dtd
("html", "", "")
99 exp
= "= 0|start_document\n" +
100 "= 1|start_dtd; html; ; \n" +
101 "{del}< 2|{del_em}end_document{del}{default}\n" +
102 "{ins}> 2|{ins_em}end_dtd{ins}{default}\n" +
103 "{ins}> 3|{ins_em}end_document{ins}{default}\n"
104 test
= a
.diff
(b
).to_s
105 assert_equals
(1, exp
, test
)
107 exp
= "= 0|start_document\n" +
108 "= 1|start_dtd; html; ; \n" +
109 "{del}< 2|{del_em}end_dtd{del}{default}\n" +
110 "{ins}> 2|{ins_em}end_document{ins}{default}\n" +
111 "{del}< 3|{del_em}end_document{del}{default}\n"
112 test
= b
.diff
(a
).to_s
113 assert_equals
(2, exp
, test
)
116 fun test_diff_edition
is test
do
121 b
.start_dtd
("html", "", "")
126 a
.start_dtd
("html", "foo", "")
130 exp
= "= 0|start_document\n" +
131 "{del}< 1|start_dtd; html; {del_em}foo{del}; {default}\n" +
132 "{ins}> 1|start_dtd; html; {ins_em}{ins}; {default}\n" +
135 test
= a
.diff
(b
).to_s
136 assert_equals
(1, exp
, test
)
138 exp
= "= 0|start_document\n" +
139 "{del}< 1|start_dtd; html; {del_em}{del}; {default}\n" +
140 "{ins}> 1|start_dtd; html; {ins_em}foo{ins}; {default}\n" +
143 test
= b
.diff
(a
).to_s
144 assert_equals
(2, exp
, test
)