livetext 0.9.10 → 0.9.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cmdargs.rb +93 -0
  3. data/lib/errors.rb +15 -0
  4. data/lib/formatline.rb +59 -88
  5. data/lib/functions.rb +6 -2
  6. data/lib/helpers.rb +163 -0
  7. data/lib/html.rb +32 -0
  8. data/lib/livetext/importable.rb +2 -0
  9. data/lib/livetext.rb +30 -148
  10. data/lib/parser/file.rb +8 -0
  11. data/lib/parser/general.rb +38 -0
  12. data/lib/parser/import.rb +17 -0
  13. data/lib/parser/mixin.rb +53 -0
  14. data/lib/parser/set.rb +145 -0
  15. data/lib/parser/string.rb +70 -0
  16. data/lib/parser.rb +5 -0
  17. data/lib/processor.rb +23 -27
  18. data/lib/standard.rb +155 -348
  19. data/lib/userapi.rb +2 -5
  20. data/livetext.gemspec +1 -2
  21. data/plugin/bookish.rb +26 -22
  22. data/plugin/calibre.rb +1 -1
  23. data/plugin/livemagick.rb +10 -10
  24. data/plugin/markdown.rb +13 -11
  25. data/plugin/pyggish.rb +94 -84
  26. data/plugin/tutorial.rb +10 -5
  27. data/test/all.rb +3 -0
  28. data/test/snapshots/OMIT.txt +9 -0
  29. data/test/{data → snapshots}/basic_formatting/expected-error.txt +0 -0
  30. data/test/{data → snapshots}/basic_formatting/expected-output.txt +0 -0
  31. data/test/{data → snapshots}/basic_formatting/source.lt3 +0 -0
  32. data/test/{data → snapshots}/block_comment/expected-error.txt +0 -0
  33. data/test/{data → snapshots}/block_comment/expected-output.txt +0 -0
  34. data/test/{data → snapshots}/block_comment/source.lt3 +0 -0
  35. data/test/snapshots/clusion.txt +35 -0
  36. data/test/{data → snapshots}/comments_ignored_1/expected-error.txt +0 -0
  37. data/test/{data → snapshots}/comments_ignored_1/expected-output.txt +0 -0
  38. data/test/{data → snapshots}/comments_ignored_1/source.lt3 +0 -0
  39. data/test/{data → snapshots}/copy_is_raw/expected-error.txt +0 -0
  40. data/test/{data → snapshots}/copy_is_raw/expected-output.txt +0 -0
  41. data/test/{data → snapshots}/copy_is_raw/rawtext.inc +0 -0
  42. data/test/{data → snapshots}/copy_is_raw/source.lt3 +0 -0
  43. data/test/{data → snapshots}/crap +0 -0
  44. data/test/{data → snapshots}/def_method/expected-error.txt +0 -0
  45. data/test/{data → snapshots}/def_method/expected-output.txt +0 -0
  46. data/test/{data → snapshots}/def_method/source.lt3 +0 -0
  47. data/test/snapshots/error_inc_line_num/actual-error.txt +14 -0
  48. data/test/{data/error_inc_line_num/expected-output.txt → snapshots/error_inc_line_num/actual-output.txt} +0 -0
  49. data/test/snapshots/error_inc_line_num/expected-output.txt +13 -0
  50. data/test/{data → snapshots}/error_inc_line_num/file2.lt3 +0 -0
  51. data/test/snapshots/error_inc_line_num/match-error.txt +1 -0
  52. data/test/snapshots/error_inc_line_num/out-sdiff.txt +14 -0
  53. data/test/{data → snapshots}/error_inc_line_num/source.lt3 +0 -0
  54. data/test/snapshots/error_invalid_name/actual-error.txt +10 -0
  55. data/test/{data/error_no_such_mixin/expected-output.txt → snapshots/error_invalid_name/actual-output.txt} +0 -0
  56. data/test/{data → snapshots}/error_invalid_name/expected-output.txt +0 -0
  57. data/test/snapshots/error_invalid_name/match-error.txt +1 -0
  58. data/test/snapshots/error_invalid_name/out-sdiff.txt +6 -0
  59. data/test/{data → snapshots}/error_invalid_name/source.lt3 +0 -0
  60. data/test/{data → snapshots}/error_line_num/expected-output.txt +0 -0
  61. data/test/snapshots/error_line_num/match-error.txt +1 -0
  62. data/test/{data → snapshots}/error_line_num/source.lt3 +0 -0
  63. data/test/{data → snapshots}/error_mismatched_end/expected-output.txt +0 -0
  64. data/test/snapshots/error_mismatched_end/match-error.txt +1 -0
  65. data/test/{data → snapshots}/error_mismatched_end/source.lt3 +0 -0
  66. data/test/snapshots/error_missing_end/actual-error.txt +10 -0
  67. data/test/{data/example_alpha/expected-error.txt → snapshots/error_missing_end/actual-output.txt} +0 -0
  68. data/test/{data → snapshots}/error_missing_end/expected-output.txt +1 -0
  69. data/test/snapshots/error_missing_end/match-error.txt +1 -0
  70. data/test/snapshots/error_missing_end/out-sdiff.txt +6 -0
  71. data/test/{data → snapshots}/error_missing_end/source.lt3 +0 -0
  72. data/test/{data/example_alpha2/expected-error.txt → snapshots/error_name_not_permitted/expected-output.txt} +0 -0
  73. data/test/snapshots/error_name_not_permitted/match-error.txt +1 -0
  74. data/test/{data → snapshots}/error_name_not_permitted/source.lt3 +0 -0
  75. data/test/snapshots/error_no_such_copy/actual-error.txt +10 -0
  76. data/test/{data/functions/expected-error.txt → snapshots/error_no_such_copy/actual-output.txt} +0 -0
  77. data/test/{data → snapshots}/error_no_such_copy/expected-output.txt +0 -1
  78. data/test/snapshots/error_no_such_copy/match-error.txt +1 -0
  79. data/test/snapshots/error_no_such_copy/out-sdiff.txt +5 -0
  80. data/test/{data → snapshots}/error_no_such_copy/source.lt3 +0 -0
  81. data/test/snapshots/error_no_such_inc/actual-error.txt +10 -0
  82. data/test/{data/hello_world/expected-error.txt → snapshots/error_no_such_inc/actual-output.txt} +0 -0
  83. data/test/{data → snapshots}/error_no_such_inc/expected-output.txt +0 -0
  84. data/test/snapshots/error_no_such_inc/match-error.txt +1 -0
  85. data/test/snapshots/error_no_such_inc/out-sdiff.txt +6 -0
  86. data/test/{data → snapshots}/error_no_such_inc/source.lt3 +0 -0
  87. data/test/snapshots/error_no_such_mixin/actual-error.txt +37 -0
  88. data/test/{data/more_complex_vars/expected-error.txt → snapshots/error_no_such_mixin/actual-output.txt} +0 -0
  89. data/test/snapshots/error_no_such_mixin/expected-output.txt +5 -0
  90. data/test/snapshots/error_no_such_mixin/match-error.txt +1 -0
  91. data/test/snapshots/error_no_such_mixin/out-sdiff.txt +6 -0
  92. data/test/{data → snapshots}/error_no_such_mixin/source.lt3 +0 -0
  93. data/test/{data/raw_lines → snapshots/example_alpha}/expected-error.txt +0 -0
  94. data/test/{data → snapshots}/example_alpha/expected-output.txt +0 -0
  95. data/test/{data → snapshots}/example_alpha/source.lt3 +0 -0
  96. data/test/{data/raw_text_block → snapshots/example_alpha2}/expected-error.txt +0 -0
  97. data/test/{data → snapshots}/example_alpha2/expected-output.txt +0 -0
  98. data/test/{data → snapshots}/example_alpha2/source.lt3 +0 -0
  99. data/test/{data → snapshots}/fixit +0 -0
  100. data/test/{data/simple_copy → snapshots/functions}/expected-error.txt +0 -0
  101. data/test/{data → snapshots}/functions/expected-output.txt +0 -0
  102. data/test/{data → snapshots}/functions/source.lt3 +0 -0
  103. data/test/{data/simple_include → snapshots/hello_world}/expected-error.txt +0 -0
  104. data/test/{data → snapshots}/hello_world/expected-output.txt +0 -0
  105. data/test/{data → snapshots}/hello_world/source.lt3 +0 -0
  106. data/test/{data/simple_mixin → snapshots/more_complex_vars}/expected-error.txt +0 -0
  107. data/test/{data → snapshots}/more_complex_vars/expected-output.txt +0 -0
  108. data/test/{data → snapshots}/more_complex_vars/source.lt3 +0 -0
  109. data/test/{data/simple_vars → snapshots/predef_vars}/expected-error.txt +0 -0
  110. data/test/snapshots/predef_vars/match-output.txt +6 -0
  111. data/test/snapshots/predef_vars/source.lt3 +6 -0
  112. data/test/{data/single_raw_line → snapshots/raw_lines}/expected-error.txt +0 -0
  113. data/test/{data → snapshots}/raw_lines/expected-output.txt +0 -0
  114. data/test/{data → snapshots}/raw_lines/source.lt3 +0 -0
  115. data/test/{data/table_with_heredocs → snapshots/raw_text_block}/expected-error.txt +0 -0
  116. data/test/{data → snapshots}/raw_text_block/expected-output.txt +0 -0
  117. data/test/{data → snapshots}/raw_text_block/rawtext.inc +0 -0
  118. data/test/{data → snapshots}/raw_text_block/source.lt3 +0 -0
  119. data/test/{data/subset.txt → snapshots/simple_copy/expected-error.txt} +0 -0
  120. data/test/{data → snapshots}/simple_copy/expected-output.txt +0 -0
  121. data/test/{data → snapshots}/simple_copy/simplefile.inc +0 -0
  122. data/test/{data → snapshots}/simple_copy/source.lt3 +0 -0
  123. data/test/snapshots/simple_import/actual-error.txt +8 -0
  124. data/test/snapshots/simple_import/actual-output.txt +3 -0
  125. data/test/snapshots/simple_import/err-sdiff.txt +9 -0
  126. data/test/snapshots/simple_import/expected-error.txt +0 -0
  127. data/test/snapshots/simple_import/expected-output.txt +7 -0
  128. data/test/snapshots/simple_import/out-sdiff.txt +9 -0
  129. data/test/snapshots/simple_import/simple_import.rb +5 -0
  130. data/test/snapshots/simple_import/source.lt3 +7 -0
  131. data/test/snapshots/simple_include/expected-error.txt +0 -0
  132. data/test/{data → snapshots}/simple_include/expected-output.txt +0 -0
  133. data/test/{data → snapshots}/simple_include/simplefile.inc +0 -0
  134. data/test/{data → snapshots}/simple_include/source.lt3 +0 -1
  135. data/test/snapshots/simple_mixin/expected-error.txt +0 -0
  136. data/test/{data → snapshots}/simple_mixin/expected-output.txt +0 -0
  137. data/test/{data → snapshots}/simple_mixin/simple_mixin.rb +0 -0
  138. data/test/{data → snapshots}/simple_mixin/source.lt3 +0 -0
  139. data/test/snapshots/simple_vars/expected-error.txt +0 -0
  140. data/test/{data → snapshots}/simple_vars/expected-output.txt +0 -0
  141. data/test/{data → snapshots}/simple_vars/source.lt3 +0 -0
  142. data/test/snapshots/single_raw_line/expected-error.txt +0 -0
  143. data/test/{data → snapshots}/single_raw_line/expected-output.txt +0 -0
  144. data/test/{data → snapshots}/single_raw_line/source.lt3 +0 -0
  145. data/test/snapshots/subset.txt +0 -0
  146. data/test/snapshots/table_with_heredocs/expected-error.txt +0 -0
  147. data/test/{data → snapshots}/table_with_heredocs/expected-output.txt +0 -0
  148. data/test/{data → snapshots}/table_with_heredocs/source.lt3 +0 -0
  149. data/test/snapshots.rb +169 -0
  150. data/test/testlines.rb +17 -7
  151. data/test/unit/all.rb +4 -0
  152. data/test/unit/formatline.rb +650 -0
  153. data/test/unit/html.rb +38 -0
  154. data/test/unit/parser/all.rb +3 -0
  155. data/test/unit/parser/general.rb +59 -0
  156. data/test/unit/parser/importable.rb +19 -0
  157. data/test/unit/parser/mixin.rb +19 -0
  158. data/test/unit/parser/set.rb +164 -0
  159. data/test/unit/parser/string.rb +130 -0
  160. data/test/unit/parser.rb +6 -0
  161. data/test/unit/standard.rb +23 -0
  162. data/test/unit/stringparser.rb +140 -0
  163. metadata +150 -97
  164. data/test/data/error_inc_line_num/expected-err-line1match.txt +0 -1
  165. data/test/data/error_invalid_name/expected-err-line1match.txt +0 -1
  166. data/test/data/error_line_num/expected-err-line1match.txt +0 -1
  167. data/test/data/error_mismatched_end/expected-err-line1match.txt +0 -1
  168. data/test/data/error_missing_end/expected-err-line1match.txt +0 -1
  169. data/test/data/error_name_not_permitted/expected-error.txt +0 -1
  170. data/test/data/error_name_not_permitted/expected-output.txt +0 -4
  171. data/test/data/error_no_such_copy/expected-err-line1match.txt +0 -1
  172. data/test/data/error_no_such_inc/expected-err-line1match.txt +0 -1
  173. data/test/data/error_no_such_mixin/expected-err-line1match.txt +0 -1
  174. data/test/data/lines.txt +0 -120
  175. data/test/extratests.txt +0 -20
  176. data/test/formatting.rb +0 -110
  177. data/test/test.rb +0 -140
@@ -0,0 +1,59 @@
1
+
2
+ require 'minitest/autorun'
3
+
4
+ require_relative '../../../lib/parser/general'
5
+
6
+ ParseGeneral = ::Livetext::ParseGeneral
7
+
8
+ class TestParseGeneral < MiniTest::Test
9
+
10
+ def setup
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ def test_strip_quotes
17
+ assert_raises(NilValue) { ParseGeneral.new(nil).strip_quotes }
18
+ assert_raises(NullString) { ParseGeneral.new("").strip_quotes }
19
+ assert_raises(MismatchedQuotes) { ParseGeneral.new(%['test]).strip_quotes }
20
+ # assert_raises(MismatchedQuotes) { ParseGeneral.new(%[test']).strip_quotes }
21
+ assert_raises(MismatchedQuotes) { ParseGeneral.new(%["test]).strip_quotes }
22
+ # assert_raises(MismatchedQuotes) { ParseGeneral.new(%[test"]).strip_quotes }
23
+ assert_raises(MismatchedQuotes) { ParseGeneral.new(%["test']).strip_quotes }
24
+ assert_raises(MismatchedQuotes) { ParseGeneral.new(%['test"]).strip_quotes }
25
+
26
+ assert ParseGeneral.new(%[24601]).strip_quotes == "24601", "Failure 1"
27
+ assert ParseGeneral.new(%[3.14]).strip_quotes == "3.14", "Failure 2"
28
+ assert ParseGeneral.new(%[test]).strip_quotes == "test", "Failure 3"
29
+ assert ParseGeneral.new(%['test']).strip_quotes == "test", "Failure 4"
30
+ assert ParseGeneral.new(%["test"]).strip_quotes == "test", "Failure 5"
31
+ end
32
+
33
+ def test_variables
34
+ vars = ["foo 234\n", "bar 456\n"]
35
+ expect = [%w[foo 234], %w[bar 456]]
36
+ assert_equal ParseGeneral.parse_vars(vars), expect
37
+
38
+ vars = ["foo2 234", "bar2 456"] # newline irrelevant
39
+ expect = [%w[foo2 234], %w[bar2 456]]
40
+ assert_equal ParseGeneral.parse_vars(vars), expect
41
+
42
+ # quotes are not stripped... hmm
43
+ vars = ["alpha 'simple string'", 'beta "another string"']
44
+ expect = [["alpha", "'simple string'"], ["beta", '"another string"']]
45
+ assert_equal ParseGeneral.parse_vars(vars), expect
46
+
47
+ # prefix (namespacing)
48
+ vars = ["alpha 'simple string'", 'beta "another string"']
49
+ expect = [["this.alpha", "'simple string'"], ["this.beta", '"another string"']]
50
+ assert_equal ParseGeneral.parse_vars(vars, prefix: "this"), expect
51
+
52
+ # prefix (namespacing)
53
+ vars = ["alpha 'simple string'", 'beta "another string"']
54
+ expect = [["this.that.alpha", "'simple string'"], ["this.that.beta", '"another string"']]
55
+ assert_equal ParseGeneral.parse_vars(vars, prefix: "this.that"), expect
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,19 @@
1
+
2
+ require 'minitest/autorun'
3
+
4
+ require_relative '../../../lib/parser/set'
5
+
6
+ # ParseSet = Livetext::ParseSet
7
+
8
+ class TestParseSet < MiniTest::Test
9
+
10
+ def setup
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ # FIXME no tests yet
17
+ # Bad syntax? File not found? not found searching upward?
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+
2
+ require 'minitest/autorun'
3
+
4
+ require_relative '../../../lib/parser/set'
5
+
6
+ # ParseSet = Livetext::ParseSet
7
+
8
+ class TestParseSet < MiniTest::Test
9
+
10
+ def setup
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ # FIXME no tests yet
17
+ # Bad syntax? File not found? not found searching upward?
18
+
19
+ end
@@ -0,0 +1,164 @@
1
+
2
+ require 'minitest/autorun'
3
+
4
+ require_relative '../../../lib/parser/set'
5
+
6
+ ParseSet = Livetext::ParseSet
7
+
8
+ class TestParseSet < MiniTest::Test
9
+
10
+ def setup
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ def ztest_one_unquoted
17
+ set = ParseSet.new('my_var_123 = 789').parse
18
+ pair = set.first
19
+ assert_equal pair, %w[my_var_123 789]
20
+
21
+ set = ParseSet.new('var_234 = naked_string').parse
22
+ pair = set.first
23
+ assert_equal pair, %w[var_234 naked_string]
24
+ end
25
+
26
+ def ztest_one_single_quoted
27
+ set = ParseSet.new("fancy.var.name = 'simple string'").parse
28
+ pair = set.first
29
+ assert_equal pair, ["fancy.var.name", "simple string"]
30
+ end
31
+
32
+ def ztest_one_double_quoted
33
+ set = ParseSet.new('fancy.var2 = "another string"').parse
34
+ pair = set.first
35
+ assert_equal pair, ["fancy.var2", "another string"]
36
+ end
37
+
38
+ def ztest_multiple_unquoted
39
+ puts __method__
40
+ pair1, pair2 = ParseSet.new("this=345, that=678").parse
41
+ assert_equal pair1, %w[this 345]
42
+ assert_equal pair2, %w[that 678]
43
+ end
44
+
45
+ def ztest_multiple_unquoted_quoted
46
+ pair1, pair2 = ParseSet.new('alpha = 567, beta = "oh well"').parse
47
+ assert_equal pair1, %w[alpha 567]
48
+ assert_equal pair2, ["beta", "oh well"]
49
+ end
50
+
51
+ def ztest_quote_embedded_comma
52
+ set = ParseSet.new('gamma = "oh, well"').parse
53
+ pair = set.first
54
+ assert_equal pair, ["gamma", "oh, well"]
55
+ end
56
+
57
+ def ztest_get_var
58
+ @parse = ParseSet.new("foo=345")
59
+ assert_equal @parse.get_var, "foo"
60
+ @parse = ParseSet.new("foo = 345")
61
+ assert_equal @parse.get_var, "foo"
62
+ @parse = ParseSet.new("foo123 = 345")
63
+ assert_equal @parse.get_var, "foo123"
64
+ @parse = ParseSet.new("foo_bar = 345")
65
+ assert_equal @parse.get_var, "foo_bar"
66
+ @parse = ParseSet.new("Foobar = 345")
67
+ assert_equal @parse.get_var, "Foobar"
68
+ @parse = ParseSet.new("_foobar = 345")
69
+ assert_equal @parse.get_var, "_foobar"
70
+
71
+ # will not notice missing equal sign till later parsing
72
+ @parse = ParseSet.new("foo bar")
73
+ assert_equal @parse.get_var, "foo"
74
+
75
+ # can detect missing equal sign if iteration ends
76
+ @parse = ParseSet.new("foo")
77
+ assert_raises(NoEqualSign) { @parse.get_var }
78
+ @parse = ParseSet.new("foo-bar = 345")
79
+ assert_raises(BadVariableName) { @parse.get_var }
80
+ end
81
+
82
+ def ztest_skip_equal
83
+ @parse = ParseSet.new("=")
84
+ assert_nil @parse.skip_equal
85
+ @parse = ParseSet.new(" = ")
86
+ assert_nil @parse.skip_equal
87
+ @parse = ParseSet.new(" =")
88
+ assert_nil @parse.skip_equal
89
+ @parse = ParseSet.new(" = 345")
90
+ assert_equal @parse.skip_equal, "3"
91
+ @parse = ParseSet.new(" = 'meh'")
92
+ assert_equal @parse.skip_equal, "'"
93
+
94
+ @parse = ParseSet.new("no equal here")
95
+ assert_raises(NoEqualSign) { @parse.skip_equal }
96
+ @parse = ParseSet.new("")
97
+ assert_raises(NoEqualSign) { @parse.skip_equal }
98
+ end
99
+
100
+ def ztest_quoted_value
101
+ @parse = ParseSet.new(%['this'])
102
+ assert_equal @parse.quoted_value, "this"
103
+ @parse = ParseSet.new(%["that"])
104
+ assert_equal @parse.quoted_value, "that"
105
+ @parse = ParseSet.new(%[""])
106
+ assert_equal @parse.quoted_value, ""
107
+ @parse = ParseSet.new(%[''])
108
+ assert_equal @parse.quoted_value, ""
109
+
110
+ @parse = ParseSet.new(%['foo"])
111
+ assert_raises(BadQuotedString) { @parse.quoted_value }
112
+ @parse = ParseSet.new(%["bar'])
113
+ assert_raises(BadQuotedString) { @parse.quoted_value }
114
+ @parse = ParseSet.new(%['baz])
115
+ assert_raises(BadQuotedString) { @parse.quoted_value }
116
+ @parse = ParseSet.new(%["bam])
117
+ assert_raises(BadQuotedString) { @parse.quoted_value }
118
+ # LATER:
119
+ # - allow (escaped?) comma in quoted string
120
+ end
121
+
122
+ def ztest_unquoted_value
123
+ # Note: an unquoted value is still a string!
124
+ @parse = ParseSet.new(%[342 ])
125
+ assert_equal @parse.unquoted_value, "342"
126
+ @parse = ParseSet.new(%[343,])
127
+ assert_equal @parse.unquoted_value, "343"
128
+ @parse = ParseSet.new(%[344,678])
129
+ assert_equal @parse.unquoted_value, "344"
130
+ @parse = ParseSet.new(%[345.123])
131
+ assert_equal @parse.unquoted_value, "345.123"
132
+ @parse = ParseSet.new(%[whatever])
133
+ assert_equal @parse.unquoted_value, "whatever"
134
+
135
+ # LATER:
136
+ # - disallow comma in unquoted string
137
+ # - disallow quote trailing unquoted string
138
+ # - allow/disallow escaping??
139
+ end
140
+
141
+ # BUG: FormatLine doesn't know variables in this context!
142
+
143
+ def xtest_4 # FIXME
144
+ set = ParseSet.new("file = $File").parse
145
+ assert_equal set.first, "file"
146
+ assert set.last !~ /undefined/
147
+ end
148
+
149
+ # BUG: ...or functions.
150
+ # (Additional bug: Failing silently seems wrong.)
151
+
152
+ def xtest_5 # FIXME
153
+ set = ParseSet.new("date = $$date").parse
154
+ assert_equal set.first, "date"
155
+ assert set.last =~ /^\d\d.\d\d.\d\d/
156
+ end
157
+
158
+ def test_two_strings
159
+ line = %[bday="May_31", date="5/31"]
160
+ set = ParseSet.new(line).parse
161
+ assert set == [["bday", "May_31"], ["date", "5/31"]]
162
+ end
163
+
164
+ end
@@ -0,0 +1,130 @@
1
+ require 'minitest/autorun'
2
+
3
+ require_relative '../../../lib/parser/string'
4
+
5
+ class TestStringParser < MiniTest::Test
6
+
7
+ def setup
8
+ # Lengths: zero, one, arbitrary
9
+ @str0 = ""
10
+ @str1 = "x"
11
+ @strN = "This is a test"
12
+ @zero = StringParser.new(@str0)
13
+ @one = StringParser.new(@str1)
14
+ @many = StringParser.new(@strN)
15
+ end
16
+
17
+ def teardown
18
+ # Line and length are invariants
19
+ assert_equal @zero.len, 0
20
+ assert_equal @one.len, 1
21
+ assert_equal @many.len, 14
22
+ end
23
+
24
+ def test_init
25
+ assert_equal @zero.line, ""
26
+ assert @zero.eos, "EOS was initially false for #{@zero.inspect}"
27
+ assert_equal @zero.i, 0
28
+
29
+ assert_equal @one.line, "x"
30
+ refute @one.eos, "EOS was initially true for #{@one.inspect}"
31
+ assert_equal @one.i, 0
32
+
33
+ assert_equal @many.line, "This is a test"
34
+ refute @many.eos, "EOS was initially true for #{@many.inspect}"
35
+ assert_equal @many.i, 0
36
+ end
37
+
38
+ def test_grab
39
+ assert_nil @zero.grab
40
+ assert_equal @zero.i, 0 # nothing happens
41
+
42
+ assert_equal @one.grab, "x"
43
+ assert_equal @one.i, 1
44
+
45
+ assert_equal @many.grab, "T"
46
+ refute @many.eos, "EOS was true for #{@many.inspect}"
47
+ assert_equal @many.i, 1
48
+ end
49
+
50
+ def test_eos
51
+ assert @zero.eos?
52
+ refute @one.eos?
53
+ refute @many.eos?
54
+ end
55
+
56
+ def test_grab_eos
57
+ @zero.grab
58
+ assert @zero.eos?
59
+
60
+ @one.grab
61
+ assert @one.eos?
62
+ @one.grab
63
+ assert @one.eos?
64
+
65
+ @many.grab
66
+ refute @many.eos?
67
+ count = @many.len # doesn't make sense??
68
+ count.times { @many.grab }
69
+ assert @many.eos?
70
+ end
71
+
72
+ def test_peek
73
+ assert_nil @zero.peek
74
+ assert_equal @one.peek, @str1[0]
75
+ assert_equal @many.peek, @strN[0]
76
+ end
77
+
78
+ def test_grab_peek
79
+ char1 = @zero.grab
80
+ char2 = @zero.peek
81
+ assert_nil char1
82
+ assert_nil char2
83
+ assert @zero.i == 0
84
+ assert @zero.last?
85
+ assert @zero.eos?
86
+
87
+ refute @one.last? # FIXME??
88
+ char1 = @one.peek
89
+ refute @one.last? # FIXME??
90
+ char2 = @one.grab
91
+ char3 = @one.peek
92
+ assert char1
93
+ assert char2 == char1
94
+ assert char3 == @str1[1]
95
+ assert @one.i == 1
96
+ assert @one.last?
97
+ assert @one.eos? # FIXME??
98
+
99
+ char1 = @many.peek
100
+ char2 = @many.grab
101
+ char3 = @many.peek
102
+ assert char1
103
+ assert char2 == char1
104
+ assert char3 == @strN[1]
105
+ assert @many.i == 1
106
+ refute @many.last?
107
+ refute @many.eos?
108
+ end
109
+
110
+ def test_skip_spaces
111
+ none = StringParser.new("abc")
112
+ char, index = none.peek, none.i
113
+ none.skip_spaces
114
+ refute none.peek == " "
115
+ assert_equal none.peek, char
116
+ assert_equal none.i, index
117
+
118
+ one = StringParser.new(" def")
119
+ one.skip_spaces
120
+ refute one.peek == " "
121
+ assert_equal one.peek, "d"
122
+ assert_equal one.i, 1
123
+
124
+ some = StringParser.new(" xyz")
125
+ some.skip_spaces
126
+ refute some.peek == " "
127
+ assert_equal some.peek, "x"
128
+ assert_equal some.i, 3
129
+ end
130
+ end
@@ -0,0 +1,6 @@
1
+
2
+ require_relative 'parser/string'
3
+ require_relative 'parser/set'
4
+ require_relative 'parser/general'
5
+ require_relative 'parser/mixin' # currently empty
6
+ require_relative 'parser/importable' # currently empty
@@ -0,0 +1,23 @@
1
+ require 'minitest/autorun'
2
+
3
+
4
+ require_relative '../../lib/livetext'
5
+
6
+ class TestingLivetext < MiniTest::Test
7
+ include Livetext::Standard
8
+ include Livetext::UserAPI
9
+
10
+ # Only method here "really" belongs elsewhere? FIXME
11
+
12
+ def test_onoff
13
+ refute onoff('off'), "Expected onoff('off') to be false"
14
+ assert onoff('on'), "Expected onoff('on') to be true"
15
+ refute onoff('oFf'), "Expected onoff('oFf') to be false"
16
+ assert onoff('oN'), "Expected onoff('oN') to be true"
17
+ assert onoff(nil), "Expected onoff(nil) to be true"
18
+
19
+ assert_raises(ExpectedOnOff, "Should raise ExpectedOnOff") { onoff("") }
20
+ assert_raises(ExpectedOnOff, "Should raise ExpectedOnOff") { onoff(345) }
21
+ end
22
+
23
+ end
@@ -0,0 +1,140 @@
1
+ require 'minitest/autorun'
2
+
3
+ require_relative '../../lib/stringparser'
4
+
5
+ class TestStringParser < MiniTest::Test
6
+
7
+ def setup
8
+ # Lengths: zero, one, arbitrary
9
+ @str0 = ""
10
+ @str1 = "x"
11
+ @strN = "This is a test"
12
+ @zero = StringParser.new(@str0)
13
+ @one = StringParser.new(@str1)
14
+ @many = StringParser.new(@strN)
15
+ end
16
+
17
+ def teardown
18
+ # Line and length are invariants
19
+ assert_equal @zero.len, 0
20
+ assert_equal @one.len, 1
21
+ assert_equal @many.len, 14
22
+ end
23
+
24
+ def test_init
25
+ assert_equal @zero.line, ""
26
+ assert @zero.eos, "EOS was initially false for #{@zero.inspect}"
27
+ assert_equal @zero.i, 0
28
+
29
+ assert_equal @one.line, "x"
30
+ refute @one.eos, "EOS was initially true for #{@one.inspect}"
31
+ assert_equal @one.i, 0
32
+
33
+ assert_equal @many.line, "This is a test"
34
+ refute @many.eos, "EOS was initially true for #{@many.inspect}"
35
+ assert_equal @many.i, 0
36
+ end
37
+
38
+ def test_next
39
+ assert_nil @zero.next
40
+ assert_equal @zero.i, 0 # nothing happens
41
+
42
+ assert_equal @one.next, "x"
43
+ assert_equal @one.i, 1
44
+
45
+ assert_equal @many.next, "T"
46
+ refute @many.eos, "EOS was true for #{@many.inspect}"
47
+ assert_equal @many.i, 1
48
+ end
49
+
50
+ def test_eos
51
+ assert @zero.eos?
52
+ refute @one.eos?
53
+ refute @many.eos?
54
+ end
55
+
56
+ def test_next_eos
57
+ @zero.next
58
+ assert @zero.eos?
59
+
60
+ @one.eos?
61
+ refute @one.eos?
62
+ @one.next
63
+ assert @one.eos?
64
+ @one.next # One beyond the actual end
65
+ assert @one.eos? # Still the end
66
+
67
+ @many.next
68
+ refute @many.eos?
69
+ count = @many.len # doesn't make sense??
70
+ count.times { @many.next }
71
+ assert @many.eos?
72
+ end
73
+
74
+ def test_peek
75
+ assert_nil @zero.peek
76
+ assert_equal @one.peek, @str1[0]
77
+ assert_equal @many.peek, @strN[0]
78
+ end
79
+
80
+ def test_next_peek
81
+ char1 = @zero.next
82
+ char2 = @zero.peek
83
+ assert_nil char1
84
+ assert_nil char2
85
+ assert @zero.i == 0
86
+ assert @zero.last?
87
+ assert @zero.eos?
88
+
89
+ refute @one.last?
90
+ char1 = @one.peek
91
+ refute @one.last?
92
+ char2 = @one.next
93
+ assert @one.last? # One beyond the last
94
+ char3 = @one.peek
95
+ assert char1
96
+ assert char2 == char1
97
+ assert char3 == @str1[1]
98
+ assert @one.i == 1
99
+ assert @one.last?
100
+ assert @one.eos?
101
+
102
+ char1 = @many.peek
103
+ char2 = @many.next
104
+ char3 = @many.peek
105
+ assert char1
106
+ assert char2 == char1
107
+ assert char3 == @strN[1]
108
+ assert @many.i == 1
109
+ refute @many.last?
110
+ refute @many.eos?
111
+ end
112
+
113
+ def test_skip_spaces
114
+ none = StringParser.new("abc")
115
+ char, index = none.peek, none.i
116
+ none.skip_spaces
117
+ refute none.peek == " "
118
+ assert_equal none.peek, char
119
+ assert_equal none.i, index
120
+
121
+ one = StringParser.new(" def")
122
+ one.skip_spaces
123
+ refute one.peek == " "
124
+ assert_equal one.peek, "d"
125
+ assert_equal one.i, 1
126
+
127
+ some = StringParser.new(" xyz")
128
+ some.skip_spaces
129
+ refute some.peek == " "
130
+ assert_equal some.peek, "x"
131
+ assert_equal some.i, 3
132
+ end
133
+
134
+ def test_for_parse_set
135
+ str = StringParser.new('gamma = "oh, well"')
136
+ count = str.len # doesn't make sense??
137
+ count.times { print str.next; }
138
+
139
+ end
140
+ end