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_suite
14 import saxophonit
::testing
17 class TestSaxEventLogger
20 # Constants for diff formatting.
22 # Treminal’s default formatting.
23 private var default
: String is noinit
25 # Formatting for insertions.
26 private var ins
: String is noinit
28 # Formatting for emphased insertions.
29 private var ins_em
: String is noinit
31 # Formatting for deletions.
32 private var del
: String is noinit
34 # Formatting for emphased deletions
35 private var del_em
: String is noinit
38 private var a
= new SAXEventLogger
39 private var b
= new SAXEventLogger
41 private var init_done
: Bool = false
43 redef fun before_test
do
46 default
= a
.term_default
47 ins
= a
.term_insertion
48 ins_em
= a
.term_insertion_emphasis
50 del_em
= a
.term_deletion_emphasis
57 private fun assert_equals
(id
: Int, expected
: String, actual
: String) do
58 assert equals
: expected
== actual
else
59 sys
.stderr
.write
("\nAssert {id} failed. Expected:\n")
60 sys
.stderr
.write
(expected
)
61 sys
.stderr
.write
("\nGot:\n")
62 sys
.stderr
.write
(actual
)
63 sys
.stderr
.write
("\n")
67 fun test_diff_empty
do
68 assert "" == a
.diff
(b
).to_s
69 assert "" == b
.diff
(a
).to_s
72 fun test_diff_equal1
do
75 assert "" == a
.diff
(b
).to_s
76 assert "" == b
.diff
(a
).to_s
79 fun test_diff_equal2
do
84 assert "" == a
.diff
(b
).to_s
85 assert "" == b
.diff
(a
).to_s
88 fun test_diff_insertion
do
93 b
.start_dtd
("html", "", "")
98 a
.start_dtd
("html", "", "")
101 exp
= "= 0|start_document\n" +
102 "= 1|start_dtd; html; ; \n" +
103 "{del}< 2|{del_em}end_document{del}{default}\n" +
104 "{ins}> 2|{ins_em}end_dtd{ins}{default}\n" +
105 "{ins}> 3|{ins_em}end_document{ins}{default}\n"
106 test
= a
.diff
(b
).to_s
107 assert_equals
(1, exp
, test
)
109 exp
= "= 0|start_document\n" +
110 "= 1|start_dtd; html; ; \n" +
111 "{del}< 2|{del_em}end_dtd{del}{default}\n" +
112 "{ins}> 2|{ins_em}end_document{ins}{default}\n" +
113 "{del}< 3|{del_em}end_document{del}{default}\n"
114 test
= b
.diff
(a
).to_s
115 assert_equals
(2, exp
, test
)
118 fun test_diff_edition
do
123 b
.start_dtd
("html", "", "")
128 a
.start_dtd
("html", "foo", "")
132 exp
= "= 0|start_document\n" +
133 "{del}< 1|start_dtd; html; {del_em}foo{del}; {default}\n" +
134 "{ins}> 1|start_dtd; html; {ins_em}{ins}; {default}\n" +
137 test
= a
.diff
(b
).to_s
138 assert_equals
(1, exp
, test
)
140 exp
= "= 0|start_document\n" +
141 "{del}< 1|start_dtd; html; {del_em}{del}; {default}\n" +
142 "{ins}> 1|start_dtd; html; {ins_em}foo{ins}; {default}\n" +
145 test
= b
.diff
(a
).to_s
146 assert_equals
(2, exp
, test
)