wlang 0.10.2 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -121
- data/Gemfile +23 -1
- data/Gemfile.lock +32 -28
- data/LICENCE.md +18 -21
- data/Manifest.txt +4 -5
- data/README.md +100 -174
- data/Rakefile +1 -13
- data/bin/wlang +3 -29
- data/lib/wlang.rb +21 -394
- data/lib/wlang/command.rb +94 -0
- data/lib/wlang/compiler.rb +78 -0
- data/lib/wlang/compiler/autospacing.rb +60 -0
- data/lib/wlang/compiler/dialect_enforcer.rb +91 -0
- data/lib/wlang/compiler/filter.rb +32 -0
- data/lib/wlang/compiler/grammar.citrus +67 -0
- data/lib/wlang/compiler/parser.rb +26 -0
- data/lib/wlang/compiler/proc_call_removal.rb +15 -0
- data/lib/wlang/compiler/static_merger.rb +28 -0
- data/lib/wlang/compiler/strconcat_flattener.rb +25 -0
- data/lib/wlang/compiler/to_ruby_abstraction.rb +22 -0
- data/lib/wlang/compiler/to_ruby_code.rb +55 -0
- data/lib/wlang/dialect.rb +40 -237
- data/lib/wlang/dialect/dispatching.rb +51 -0
- data/lib/wlang/dialect/evaluation.rb +30 -0
- data/lib/wlang/dialect/tags.rb +50 -0
- data/lib/wlang/dummy.rb +32 -0
- data/lib/wlang/html.rb +106 -0
- data/lib/wlang/loader.rb +6 -0
- data/lib/wlang/mustang.rb +90 -0
- data/lib/wlang/scope.rb +57 -0
- data/lib/wlang/scope/binding_scope.rb +18 -0
- data/lib/wlang/scope/object_scope.rb +25 -0
- data/lib/wlang/scope/proxy_scope.rb +18 -0
- data/lib/wlang/scope/root_scope.rb +24 -0
- data/lib/wlang/template.rb +16 -86
- data/lib/wlang/version.rb +9 -8
- data/spec/fixtures/dialect/foobar.rb +31 -0
- data/spec/fixtures/dialect/upcasing.rb +13 -0
- data/spec/fixtures/templates/hello.tpl +1 -0
- data/spec/integration/examples/1-basics.txt +65 -0
- data/spec/integration/examples/2-imperative.txt +51 -0
- data/spec/integration/examples/3-partials.txt +76 -0
- data/spec/integration/examples/4-recursion.txt +16 -0
- data/spec/integration/html/test_ampersand.rb +15 -0
- data/spec/integration/html/test_bang.rb +38 -0
- data/spec/integration/html/test_caret.rb +33 -0
- data/spec/integration/html/test_dollar.rb +16 -0
- data/spec/integration/html/test_greater.rb +23 -0
- data/spec/integration/html/test_modulo.rb +16 -0
- data/spec/integration/html/test_plus.rb +48 -0
- data/spec/integration/html/test_question.rb +33 -0
- data/spec/integration/html/test_sharp.rb +21 -0
- data/spec/integration/html/test_slash.rb +16 -0
- data/spec/integration/html/test_star.rb +37 -0
- data/spec/integration/test_dummy.rb +51 -0
- data/spec/integration/test_examples.rb +29 -0
- data/spec/integration/test_mustang.rb +120 -0
- data/spec/integration/test_readme.rb +56 -0
- data/spec/integration/test_upcasing.rb +22 -0
- data/spec/spec_helper.rb +62 -1
- data/spec/test_wlang.rb +101 -0
- data/spec/unit/compiler/autospacing/test_right_strip.rb +30 -0
- data/spec/unit/compiler/autospacing/test_unindent.rb +30 -0
- data/spec/unit/compiler/test_dialect_enforcer.rb +168 -0
- data/spec/unit/compiler/test_grammar.rb +207 -0
- data/spec/unit/compiler/test_parser.rb +69 -0
- data/spec/unit/compiler/test_proc_call_removal.rb +24 -0
- data/spec/unit/compiler/test_static_merger.rb +29 -0
- data/spec/unit/compiler/test_strconcat_flattener.rb +30 -0
- data/spec/unit/compiler/test_to_ruby_abstraction.rb +59 -0
- data/spec/unit/compiler/test_to_ruby_code.rb +24 -0
- data/spec/unit/dialect/test_compile.rb +52 -0
- data/spec/unit/dialect/test_dispatching.rb +19 -0
- data/spec/unit/dialect/test_evaluate.rb +41 -0
- data/spec/unit/dialect/test_render.rb +33 -0
- data/spec/unit/dialect/test_tags.rb +32 -0
- data/spec/unit/dialect/test_with_scope.rb +18 -0
- data/spec/unit/scope/test_binding_scope.rb +27 -0
- data/spec/unit/scope/test_coerce.rb +22 -0
- data/spec/unit/scope/test_object_scope.rb +38 -0
- data/spec/unit/scope/test_proxy_scope.rb +22 -0
- data/spec/unit/scope/test_root_scope.rb +22 -0
- data/spec/unit/test_assumptions.rb +29 -0
- data/spec/unit/test_scope.rb +57 -0
- data/tasks/debug_mail.rake +42 -45
- data/tasks/gem.rake +22 -17
- data/tasks/spec_test.rake +9 -17
- data/tasks/unit_test.rake +11 -12
- data/tasks/yard.rake +13 -13
- data/wlang.gemspec +36 -32
- data/wlang.noespec +27 -35
- metadata +268 -451
- data/doc/specification/about.rdoc +0 -61
- data/doc/specification/analytics.wtpl +0 -13
- data/doc/specification/dialect.wtpl +0 -14
- data/doc/specification/dialects.wtpl +0 -3
- data/doc/specification/examples.rb +0 -3
- data/doc/specification/glossary.wtpl +0 -14
- data/doc/specification/hosting.rdoc +0 -0
- data/doc/specification/overview.rdoc +0 -116
- data/doc/specification/rulesets.wtpl +0 -87
- data/doc/specification/specification.css +0 -53
- data/doc/specification/specification.html +0 -1690
- data/doc/specification/specification.js +0 -8
- data/doc/specification/specification.wtpl +0 -42
- data/doc/specification/specification.yml +0 -432
- data/doc/specification/symbols.wtpl +0 -16
- data/lib/wlang/dialect_dsl.rb +0 -141
- data/lib/wlang/dialect_loader.rb +0 -74
- data/lib/wlang/dialects/bluecloth_dialect.rb +0 -16
- data/lib/wlang/dialects/coderay_dialect.rb +0 -45
- data/lib/wlang/dialects/hosted_dialect.rb +0 -50
- data/lib/wlang/dialects/plain_text_dialect.rb +0 -69
- data/lib/wlang/dialects/rdoc_dialect.rb +0 -33
- data/lib/wlang/dialects/redcloth_dialect.rb +0 -16
- data/lib/wlang/dialects/ruby_dialect.rb +0 -118
- data/lib/wlang/dialects/sql_dialect.rb +0 -38
- data/lib/wlang/dialects/standard_dialects.rb +0 -181
- data/lib/wlang/dialects/xhtml_dialect.rb +0 -63
- data/lib/wlang/dialects/yaml_dialect.rb +0 -30
- data/lib/wlang/encoder.rb +0 -62
- data/lib/wlang/encoder_set.rb +0 -122
- data/lib/wlang/errors.rb +0 -80
- data/lib/wlang/ext/hash_methodize.rb +0 -13
- data/lib/wlang/ext/string.rb +0 -44
- data/lib/wlang/hash_scope.rb +0 -89
- data/lib/wlang/hosted_language.rb +0 -146
- data/lib/wlang/intelligent_buffer.rb +0 -94
- data/lib/wlang/parser.rb +0 -332
- data/lib/wlang/parser_state.rb +0 -94
- data/lib/wlang/rule.rb +0 -66
- data/lib/wlang/rule_set.rb +0 -106
- data/lib/wlang/rulesets/basic_ruleset.rb +0 -83
- data/lib/wlang/rulesets/buffering_ruleset.rb +0 -115
- data/lib/wlang/rulesets/context_ruleset.rb +0 -111
- data/lib/wlang/rulesets/encoding_ruleset.rb +0 -73
- data/lib/wlang/rulesets/imperative_ruleset.rb +0 -132
- data/lib/wlang/rulesets/ruleset_utils.rb +0 -317
- data/lib/wlang/wlang_command.rb +0 -51
- data/lib/wlang/wlang_command_options.rb +0 -163
- data/spec/basic_object.spec +0 -40
- data/spec/coderay_dialect.spec +0 -8
- data/spec/dialect/apply_post_transform.spec +0 -16
- data/spec/global_extensions.rb +0 -2
- data/spec/hash_scope.spec +0 -76
- data/spec/redcloth_dialect.spec +0 -24
- data/spec/test_all.rb +0 -8
- data/spec/wlang.spec +0 -53
- data/spec/wlang_spec.rb +0 -8
- data/spec/xhtml_dialect.spec +0 -22
- data/tasks/genspec.rake +0 -5
- data/test/blackbox/basic/execution_1.exp +0 -1
- data/test/blackbox/basic/execution_1.tpl +0 -1
- data/test/blackbox/basic/execution_2.exp +0 -1
- data/test/blackbox/basic/execution_2.tpl +0 -1
- data/test/blackbox/basic/execution_3.exp +0 -1
- data/test/blackbox/basic/execution_3.tpl +0 -1
- data/test/blackbox/basic/execution_4.exp +0 -1
- data/test/blackbox/basic/execution_4.tpl +0 -1
- data/test/blackbox/basic/inclusion_1.exp +0 -1
- data/test/blackbox/basic/inclusion_1.tpl +0 -1
- data/test/blackbox/basic/inclusion_2.exp +0 -1
- data/test/blackbox/basic/inclusion_2.tpl +0 -1
- data/test/blackbox/basic/injection_1.exp +0 -1
- data/test/blackbox/basic/injection_1.tpl +0 -1
- data/test/blackbox/basic/injection_2.exp +0 -1
- data/test/blackbox/basic/injection_2.tpl +0 -1
- data/test/blackbox/basic/modulation_1.exp +0 -1
- data/test/blackbox/basic/modulation_1.tpl +0 -1
- data/test/blackbox/basic/modulation_2.exp +0 -1
- data/test/blackbox/basic/modulation_2.tpl +0 -1
- data/test/blackbox/basic/recursive_app_1.exp +0 -1
- data/test/blackbox/basic/recursive_app_1.tpl +0 -1
- data/test/blackbox/basic/recursive_app_2.exp +0 -1
- data/test/blackbox/basic/recursive_app_2.tpl +0 -1
- data/test/blackbox/buffering/data_1.rb +0 -1
- data/test/blackbox/buffering/data_assignment_1.exp +0 -1
- data/test/blackbox/buffering/data_assignment_1.tpl +0 -1
- data/test/blackbox/buffering/data_assignment_2.exp +0 -1
- data/test/blackbox/buffering/data_assignment_2.tpl +0 -1
- data/test/blackbox/buffering/data_assignment_3.exp +0 -1
- data/test/blackbox/buffering/data_assignment_3.tpl +0 -1
- data/test/blackbox/buffering/data_assignment_4.exp +0 -1
- data/test/blackbox/buffering/data_assignment_4.tpl +0 -1
- data/test/blackbox/buffering/input_1.exp +0 -1
- data/test/blackbox/buffering/input_1.tpl +0 -1
- data/test/blackbox/buffering/input_2.exp +0 -1
- data/test/blackbox/buffering/input_2.tpl +0 -1
- data/test/blackbox/buffering/input_3.exp +0 -1
- data/test/blackbox/buffering/input_3.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion.exp +0 -1
- data/test/blackbox/buffering/input_inclusion.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_1.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_1.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_2.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_2.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_3.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_3.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_4.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_4.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_5.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_5.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_6.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_6.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_7.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_7.tpl +0 -1
- data/test/blackbox/buffering/text_1.txt +0 -1
- data/test/blackbox/buffering/wlang.txt +0 -1
- data/test/blackbox/context/assignment_1.exp +0 -1
- data/test/blackbox/context/assignment_1.tpl +0 -1
- data/test/blackbox/context/assignment_2.exp +0 -1
- data/test/blackbox/context/assignment_2.tpl +0 -1
- data/test/blackbox/context/assignment_3.exp +0 -2
- data/test/blackbox/context/assignment_3.tpl +0 -2
- data/test/blackbox/context/assignment_4.exp +0 -1
- data/test/blackbox/context/assignment_4.tpl +0 -1
- data/test/blackbox/context/block_assignment_1.exp +0 -1
- data/test/blackbox/context/block_assignment_1.tpl +0 -1
- data/test/blackbox/context/block_assignment_2.exp +0 -1
- data/test/blackbox/context/block_assignment_2.tpl +0 -1
- data/test/blackbox/context/modulo_assignment_1.exp +0 -1
- data/test/blackbox/context/modulo_assignment_1.tpl +0 -1
- data/test/blackbox/context/modulo_assignment_2.exp +0 -1
- data/test/blackbox/context/modulo_assignment_2.tpl +0 -1
- data/test/blackbox/data_1.rb +0 -1
- data/test/blackbox/postblock/hello.exp +0 -1
- data/test/blackbox/postblock/hello.pre +0 -1
- data/test/blackbox/postblock/hello.tpl +0 -1
- data/test/blackbox/postblock/hello_input_inclusion.exp +0 -1
- data/test/blackbox/postblock/hello_input_inclusion.tpl +0 -1
- data/test/blackbox/postblock/hello_to_authors.exp +0 -1
- data/test/blackbox/postblock/hello_to_authors.tpl +0 -1
- data/test/blackbox/poststring/hello.exp +0 -1
- data/test/blackbox/poststring/hello.tpl +0 -1
- data/test/blackbox/test_all.rb +0 -70
- data/test/standard_dialects/ruby/data.rb +0 -7
- data/test/standard_dialects/ruby/inclusion.exp +0 -6
- data/test/standard_dialects/ruby/inclusion.tpl +0 -6
- data/test/standard_dialects/test_all.rb +0 -29
- data/test/standard_dialects/yaml/assumptions_test.rb +0 -13
- data/test/standard_dialects/yaml/data.rb +0 -3
- data/test/standard_dialects/yaml/inclusion_1.exp +0 -7
- data/test/standard_dialects/yaml/inclusion_1.tpl +0 -2
- data/test/standard_dialects/yaml/inclusion_2.exp +0 -5
- data/test/standard_dialects/yaml/inclusion_2.tpl +0 -3
- data/test/unit/test_all.rb +0 -9
- data/test/unit/wlang/anagram_bugs_test.rb +0 -111
- data/test/unit/wlang/basic_ruleset_test.rb +0 -52
- data/test/unit/wlang/buffering_ruleset_test.rb +0 -102
- data/test/unit/wlang/buffering_template1.wtpl +0 -1
- data/test/unit/wlang/buffering_template2.wtpl +0 -1
- data/test/unit/wlang/buffering_template3.wtpl +0 -1
- data/test/unit/wlang/buffering_template4.wtpl +0 -1
- data/test/unit/wlang/buffering_template5.wtpl +0 -1
- data/test/unit/wlang/context_ruleset_test.rb +0 -32
- data/test/unit/wlang/data.rb +0 -3
- data/test/unit/wlang/encoder_set_test.rb +0 -42
- data/test/unit/wlang/imperative_ruleset_test.rb +0 -107
- data/test/unit/wlang/intelligent_buffer_test.rb +0 -194
- data/test/unit/wlang/othersymbols_test.rb +0 -16
- data/test/unit/wlang/parser_test.rb +0 -88
- data/test/unit/wlang/plain_text_dialect_test.rb +0 -21
- data/test/unit/wlang/ruby_dialect_test.rb +0 -100
- data/test/unit/wlang/ruby_expected.rb +0 -3
- data/test/unit/wlang/ruby_template.wrb +0 -3
- data/test/unit/wlang/ruleset_utils_test.rb +0 -245
- data/test/unit/wlang/specification_examples_test.rb +0 -54
- data/test/unit/wlang/test_utils.rb +0 -25
- data/test/unit/wlang/wlang_test.rb +0 -80
@@ -1,194 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'wlang'
|
3
|
-
module WLang
|
4
|
-
|
5
|
-
# Tests the IntelligentBuffer class
|
6
|
-
class IntelligentBufferTest < Test::Unit::TestCase
|
7
|
-
include IntelligentBuffer::Methods
|
8
|
-
|
9
|
-
# Creates a buffer instance
|
10
|
-
def buffer(str)
|
11
|
-
IntelligentBuffer.new(str)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_last_column
|
15
|
-
assert_equal(4, last_column('abc'))
|
16
|
-
assert_equal(4, last_column("\nabc"))
|
17
|
-
assert_equal(6, last_column("\nabc\nab cd"))
|
18
|
-
assert_equal(1, last_column("\n\n\n\n\n\n"))
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_ismultiline?
|
22
|
-
assert is_multiline?("\n")
|
23
|
-
assert is_multiline?("\nabc")
|
24
|
-
assert is_multiline?("\nabc\n")
|
25
|
-
assert_equal false, is_multiline?("abc")
|
26
|
-
assert_equal false, is_multiline?("abc\t")
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_tabto
|
30
|
-
template = <<-EOF
|
31
|
-
def +{d}
|
32
|
-
contents of the method here
|
33
|
-
and also here
|
34
|
-
end
|
35
|
-
EOF
|
36
|
-
template = tabto(template, 0).strip
|
37
|
-
assert_equal("def +{d}\n contents of the method here\n and also here\nend", template)
|
38
|
-
# check on normal multiline
|
39
|
-
template = %Q{
|
40
|
-
def +{d}
|
41
|
-
contents of the method here
|
42
|
-
and also here
|
43
|
-
end
|
44
|
-
}
|
45
|
-
stripped = strip_block(template)
|
46
|
-
expected = " def +{d}\n contents of the method here\n and also here\n end\n"
|
47
|
-
assert_equal(expected, tabto(stripped, 4))
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_strip_block
|
51
|
-
# check on non multiline
|
52
|
-
assert_equal 'abc', strip_block('abc')
|
53
|
-
|
54
|
-
# check on normal multiline
|
55
|
-
template = %Q{
|
56
|
-
def +{d}
|
57
|
-
contents of the method here
|
58
|
-
and also here
|
59
|
-
end
|
60
|
-
}
|
61
|
-
expected = " def +{d}\n contents of the method here\n and also here\n end\n"
|
62
|
-
assert_equal(expected, strip_block(template))
|
63
|
-
|
64
|
-
# check that explicit carriage return are recognized
|
65
|
-
template = %Q{
|
66
|
-
|
67
|
-
def +{d}
|
68
|
-
contents of the method here
|
69
|
-
and also here
|
70
|
-
end
|
71
|
-
}
|
72
|
-
expected = "\n def +{d}\n contents of the method here\n and also here\n end\n"
|
73
|
-
assert_equal(expected, strip_block(template))
|
74
|
-
|
75
|
-
# check that no first carriage return is recognized as well
|
76
|
-
template = %Q{def +{d}
|
77
|
-
contents of the method here
|
78
|
-
and also here
|
79
|
-
end
|
80
|
-
}
|
81
|
-
expected = "def +{d}\n contents of the method here\n and also here\nend\n"
|
82
|
-
assert_equal(expected, strip_block(template))
|
83
|
-
|
84
|
-
# Check on push failure
|
85
|
-
template = %Q{
|
86
|
-
|
87
|
-
def hello()
|
88
|
-
end
|
89
|
-
}
|
90
|
-
assert_equal("\n def hello()\n end\n", strip_block(template))
|
91
|
-
|
92
|
-
# Tests on a missing end bug
|
93
|
-
mod = "module MyModule\n 10\n 20\n 30\n\nend"
|
94
|
-
assert_equal(mod, strip_block(mod))
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_missing_end_bug_reason
|
98
|
-
buf = IntelligentBuffer.new
|
99
|
-
mod = "module MyModule\n 10\n 20\n 30\n\nend"
|
100
|
-
assert_equal(mod, strip_block(mod))
|
101
|
-
buf.<<(mod, true)
|
102
|
-
assert_equal(mod, buf.to_s)
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_push
|
106
|
-
template = <<-EOF
|
107
|
-
module +{name}
|
108
|
-
|
109
|
-
*{defs as d}{
|
110
|
-
|
111
|
-
def +{d}
|
112
|
-
end
|
113
|
-
}
|
114
|
-
|
115
|
-
end
|
116
|
-
EOF
|
117
|
-
#puts template.gsub(/ {8}/, '').strip
|
118
|
-
buf = buffer('')
|
119
|
-
buf.<<("module ", false)
|
120
|
-
buf.<<("MyModule", true)
|
121
|
-
buf.<<("\n\n ", false)
|
122
|
-
bufit = buffer('')
|
123
|
-
buf2 = buffer('')
|
124
|
-
buf2.<<("\n\n def ", false)
|
125
|
-
buf3 = buffer('')
|
126
|
-
buf3.<<('hello', true)
|
127
|
-
buf2.<<(buf3.to_s, true)
|
128
|
-
buf2.<<("()\n end\n ", false)
|
129
|
-
#puts "\nAppending on bufit, first iteration"
|
130
|
-
#puts "|#{buf2.to_s}|"
|
131
|
-
bufit.<<(buf2.to_s, true)
|
132
|
-
#puts "\nAfter append"
|
133
|
-
#puts "|#{bufit.to_s}|"
|
134
|
-
#puts "Last column is now #{last_column(bufit)}"
|
135
|
-
buf2 = buffer('')
|
136
|
-
buf2.<<("\n\n def ", false)
|
137
|
-
buf3 = buffer('')
|
138
|
-
buf3.<<('strip', true)
|
139
|
-
buf2.<<(buf3.to_s, true)
|
140
|
-
buf2.<<("()\n end\n ", false)
|
141
|
-
#puts "\nAppending on bufit, second iteration"
|
142
|
-
#puts "|#{buf2.to_s}|"
|
143
|
-
bufit.<<(buf2.to_s, true)
|
144
|
-
#puts "\nAfter append"
|
145
|
-
#puts "|#{bufit.to_s}|"
|
146
|
-
#puts "\nAppending bufit on buf"
|
147
|
-
#puts "|#{buf.to_s}|"
|
148
|
-
buf.<<(bufit.to_s, true)
|
149
|
-
#puts "\nAfter append"
|
150
|
-
#puts "|#{buf.to_s}|"
|
151
|
-
buf.<<("\n\nend", false)
|
152
|
-
#puts "\nNow, we've done"
|
153
|
-
#puts buf
|
154
|
-
expected = "module MyModule\n\n def hello()\n end\n \n def strip()\n end\n\n\nend"
|
155
|
-
assert_equal(expected, buf.to_s)
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_wlang_on_intelligent_buffer
|
159
|
-
template = <<-EOF
|
160
|
-
module +{name}
|
161
|
-
|
162
|
-
*{defs as d}{
|
163
|
-
|
164
|
-
def +{d}
|
165
|
-
end
|
166
|
-
}
|
167
|
-
|
168
|
-
end
|
169
|
-
EOF
|
170
|
-
template = template.gsub(/ {8}/, '').strip
|
171
|
-
#puts template
|
172
|
-
context = {"name" => "MyModule", "defs" => ["hello", "strip", "toeol"]}
|
173
|
-
#puts template.wlang_instantiate(context, "wlang/ruby")
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_wlang_on_web_example
|
177
|
-
template = %q{
|
178
|
-
<table>
|
179
|
-
*{rows as r}{
|
180
|
-
<tr>
|
181
|
-
*{r as d}{
|
182
|
-
<td>+{d}</td>
|
183
|
-
}
|
184
|
-
</tr>
|
185
|
-
}
|
186
|
-
</table>
|
187
|
-
}.gsub(/^ {8}/, '').strip
|
188
|
-
#puts template
|
189
|
-
context = {"rows" => [[10, 11, 12], [20, 21, 22], [30, 31, 32]]}
|
190
|
-
#puts template.wlang_instantiate(context, "wlang/xhtml")
|
191
|
-
end
|
192
|
-
|
193
|
-
end # class IntelligentBufferTest
|
194
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'wlang'
|
2
|
-
require 'test/unit'
|
3
|
-
module WLang
|
4
|
-
class OtherSymbolsTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_on_parentheses
|
7
|
-
template = "+{who}"
|
8
|
-
assert_equal 'blambeau', WLang.instantiate(template, {'who' => 'blambeau'}, 'wlang/active-string', :braces).to_s
|
9
|
-
template = "+(who)"
|
10
|
-
assert_equal 'blambeau', WLang.instantiate(template, {'who' => 'blambeau'}, 'wlang/active-string', :parentheses).to_s
|
11
|
-
template = "+[who]"
|
12
|
-
assert_equal 'blambeau', WLang.instantiate(template, {'who' => 'blambeau'}, 'wlang/active-string', :brackets).to_s
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'wlang'
|
3
|
-
module WLang
|
4
|
-
|
5
|
-
class ParserTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
# Installs some dialects on wlang
|
8
|
-
def setup
|
9
|
-
# wlang dialect, empty by default
|
10
|
-
WLang::dialect "example" do
|
11
|
-
rule '+' do |parser,offset|
|
12
|
-
parsed, reached = parser.parse(offset)
|
13
|
-
[parsed.upcase, reached]
|
14
|
-
end
|
15
|
-
rule '-' do |parser,offset|
|
16
|
-
parsed, reached = parser.parse(offset)
|
17
|
-
[parsed.downcase, reached]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Instantiate the given string as template
|
23
|
-
def instantiate_str(str)
|
24
|
-
WLang::template(str, "example").instantiate
|
25
|
-
end
|
26
|
-
|
27
|
-
# Asserts the result of an instanciation
|
28
|
-
def assert_instantiation_equal(expected, template, msg=nil)
|
29
|
-
template = WLang::template(template, "example")
|
30
|
-
assert_equal(expected, template.instantiate)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_parser_accepts_whole_tag
|
34
|
-
template, expected = "+{hello}", "HELLO"
|
35
|
-
assert_instantiation_equal(expected, template)
|
36
|
-
template, expected = " +{hello} ", " HELLO "
|
37
|
-
assert_instantiation_equal(expected, template)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_parser_accepts_whole_block
|
41
|
-
template, expected = "{hello}", "{hello}"
|
42
|
-
assert_instantiation_equal(expected, template)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_parser_ignores_backslashed_tags
|
46
|
-
template, expected = "\\+{hello\\}", "+{hello}"
|
47
|
-
assert_instantiation_equal(expected, template)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_parser_ignores_backslashed_blocks
|
51
|
-
template, expected = "\\{hello\\} world", "{hello} world"
|
52
|
-
assert_instantiation_equal(expected, template)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_parser_on_a_complex_case
|
56
|
-
template = "Hello \\\\} world! -{ITEMS AS I}{do +{something} \\{with \\} i} here is my name:+{name} and { that's not -{COMMON} text } !\\{"
|
57
|
-
expected = "Hello \\} world! items as i{do SOMETHING {with } i} here is my name:NAME and { that's not common text } !\{"
|
58
|
-
assert_instantiation_equal(expected, template)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_parser_raises_error
|
62
|
-
# Unclosed tag
|
63
|
-
assert_raise(ParseError){instantiate_str("-{unclosedtag")}
|
64
|
-
end
|
65
|
-
|
66
|
-
def assert_error_at_line_column(template, line, column)
|
67
|
-
begin
|
68
|
-
instantiate_str(template)
|
69
|
-
assert(false)
|
70
|
-
rescue ParseError => ex
|
71
|
-
assert_equal ex.line, line, "Line matches"
|
72
|
-
assert_equal ex.column, column, "Column matches"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_parser_error_find_line_and_column
|
77
|
-
assert_error_at_line_column("-{tag", 1, 5)
|
78
|
-
assert_error_at_line_column("-{tag with spaces ", 1, 20)
|
79
|
-
assert_error_at_line_column("-{tag as i}{\n", 2, 0)
|
80
|
-
assert_error_at_line_column("-{tag as i}{\n\n", 3, 0)
|
81
|
-
assert_error_at_line_column("-{tag as i}{\ntext\n", 3, 0)
|
82
|
-
assert_error_at_line_column("-{tag as i}{\n\ntext\n", 4, 0)
|
83
|
-
assert_error_at_line_column("-{tag as i}{\n\n\ntext\n", 5, 0)
|
84
|
-
end
|
85
|
-
|
86
|
-
end # ParserTest
|
87
|
-
|
88
|
-
end # WLang
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'test/unit/testcase'
|
2
|
-
require 'wlang'
|
3
|
-
require 'wlang/dialects/plain_text_dialect'
|
4
|
-
|
5
|
-
class WLang::PlainTestDialectTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
# Tests the camel case function
|
8
|
-
def test_camel_case
|
9
|
-
tests = [
|
10
|
-
["blambeau", "Blambeau"],
|
11
|
-
["the world and the cat", "TheWorldAndTheCat"],
|
12
|
-
["\nthe\t world and-the_cat", "TheWorldAndTheCat"],
|
13
|
-
#["l'éléphant", "LElephant"],
|
14
|
-
]
|
15
|
-
tests.each do |t|
|
16
|
-
src, expected = t
|
17
|
-
assert_equal(expected, WLang::EncoderSet::PlainText.camel_case(src, nil))
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'test/unit/testcase'
|
2
|
-
require 'wlang'
|
3
|
-
require 'wlang/dialects/standard_dialects'
|
4
|
-
module WLang
|
5
|
-
|
6
|
-
# Tests the ruby dialect
|
7
|
-
class RubyDialectTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
def get_file_contents(file)
|
10
|
-
file = File.join(File.dirname(__FILE__), file)
|
11
|
-
File.read(file)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Tests on template in HERE documents above
|
15
|
-
def test_on_template
|
16
|
-
$context = {"name" => "O'Neil"}
|
17
|
-
$template = get_file_contents('ruby_template.wrb')
|
18
|
-
$expected = get_file_contents('ruby_expected.rb')
|
19
|
-
result = $template.wlang($context, "wlang/ruby")
|
20
|
-
# puts "\n--template--"
|
21
|
-
# puts $template
|
22
|
-
# puts "\n--expected--"
|
23
|
-
# puts $expected
|
24
|
-
# puts "\n--result--"
|
25
|
-
# puts result
|
26
|
-
assert_equal($expected,result)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Tests single quoting
|
30
|
-
def test_single_quoting
|
31
|
-
context = {}
|
32
|
-
tests = [
|
33
|
-
["Hello world!", "Hello world!"],
|
34
|
-
["Hello &'{world}!", "Hello world!"],
|
35
|
-
["Hello &'{men's world}!", "Hello men\\'s world!"],
|
36
|
-
["puts 'Hello &'{men's world}!'", "puts 'Hello men\\'s world!'"],
|
37
|
-
["Hello O\'Neil", "Hello O\'Neil"],
|
38
|
-
["Hello O\\'Neil", "Hello O\\'Neil"],
|
39
|
-
["Hello O\\\\'Neil", "Hello O\\\\'Neil"],
|
40
|
-
]
|
41
|
-
tests.each do |test|
|
42
|
-
expected = test[1]
|
43
|
-
result = test[0].wlang(context, "wlang/ruby")
|
44
|
-
assert_equal(expected, result)
|
45
|
-
end
|
46
|
-
|
47
|
-
context = {"name" => %q{O\'Neil}}
|
48
|
-
template = %q{puts '{name}'}
|
49
|
-
expected = %q{puts 'O\'Neil'}
|
50
|
-
result = template.wlang(context, "wlang/ruby")
|
51
|
-
assert_equal(expected, result)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Tests double quoting
|
55
|
-
def test_double_quoting
|
56
|
-
context = {}
|
57
|
-
tests = [
|
58
|
-
['Hello world!', 'Hello world!'],
|
59
|
-
['Hello &"{world}!', 'Hello world!'],
|
60
|
-
['Hello &"{men"s world}!', 'Hello men\\"s world!'],
|
61
|
-
['puts "Hello &"{men"s world}!"', 'puts "Hello men\\"s world!"']
|
62
|
-
]
|
63
|
-
tests.each do |test|
|
64
|
-
expected = test[1]
|
65
|
-
result = test[0].wlang(context, "wlang/ruby")
|
66
|
-
assert_equal(expected, result)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# Tests single quoted
|
71
|
-
def test_single_quoted
|
72
|
-
context = {"name" => "blambeau", "mensworld" => "men's world"}
|
73
|
-
tests = [
|
74
|
-
["puts '{name}'", "puts 'blambeau'"],
|
75
|
-
["puts '{mensworld}'", "puts 'men\\'s world'"],
|
76
|
-
]
|
77
|
-
tests.each do |test|
|
78
|
-
expected = test[1]
|
79
|
-
result = test[0].wlang(context, "wlang/ruby")
|
80
|
-
assert_equal(expected, result)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# Tests double quoted
|
85
|
-
def test_double_quoted
|
86
|
-
context = {"name" => "blambeau", "mensworld" => 'men"s world'}
|
87
|
-
tests = [
|
88
|
-
['puts "{name}"', 'puts "blambeau"'],
|
89
|
-
['puts "{mensworld}"', 'puts "men\\"s world"'],
|
90
|
-
]
|
91
|
-
tests.each do |test|
|
92
|
-
expected = test[1]
|
93
|
-
result = test[0].wlang(context, "wlang/ruby")
|
94
|
-
assert_equal(expected, result)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
end # class RubyDialectTest
|
99
|
-
|
100
|
-
end # module WLang
|
@@ -1,245 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'wlang'
|
3
|
-
require 'wlang/rulesets/ruleset_utils'
|
4
|
-
|
5
|
-
# Tests the ruleset utilities.
|
6
|
-
class WLang::RuleSetUtilsTest < Test::Unit::TestCase
|
7
|
-
include WLang::RuleSet::Utils
|
8
|
-
|
9
|
-
# Tests decoding qdialects
|
10
|
-
def test_decode_qdialect()
|
11
|
-
tests = ["wlang", "xhtml", "\nxhtml ", "plain-text", "wlang/plain-text", " wlang/sql"]
|
12
|
-
tests.each do |t|
|
13
|
-
expected = {:qdialect => t.strip}
|
14
|
-
result = WLang::RuleSet::Utils.expr(:qdialect).decode(t)
|
15
|
-
assert_equal(expected, result)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Tests decoding qdialects
|
20
|
-
def test_decode_qdialect_as()
|
21
|
-
tests = ["wlang as var", "xhtml as var", "\nxhtml as var ",
|
22
|
-
"plain-text as var", "wlang/plain-text\tas\tvar", " wlang/sql as var"]
|
23
|
-
tests.each do |t|
|
24
|
-
/^\s*([^\s]+)\s+as\s+([^\s]+)\s*$/ =~ t
|
25
|
-
expected = {:qdialect => $1, :as => $2}
|
26
|
-
result = WLang::RuleSet::Utils.expr(:qdialect, ["as", :var]).decode(t)
|
27
|
-
assert_equal(expected, result)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Tests decoding qdialects
|
32
|
-
def test_decode_qdialect_as_with_optional()
|
33
|
-
tests = ["wlang", "xhtml", "\nxhtml ", "plain-text", "wlang/plain-text", " wlang/sql"]
|
34
|
-
tests.each do |t|
|
35
|
-
expected = {:qdialect => t.strip, :as => nil}
|
36
|
-
result = WLang::RuleSet::Utils.expr(:qdialect, ["as", :var, false]).decode(t)
|
37
|
-
assert_equal(expected, result)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_decode_with_a_with
|
42
|
-
source = "/hello with who: 'blambeau'"
|
43
|
-
result = WLang::RuleSet::Utils.expr(:expr, ["using", :using, false], ["with", :with, false]).decode(source)
|
44
|
-
assert_equal({:expr => '/hello', :with => {'who' => "'blambeau'"}, :using => nil}, result)
|
45
|
-
|
46
|
-
source = "/hello using self with who: 'blambeau'"
|
47
|
-
result = WLang::RuleSet::Utils.expr(:expr, ["using", :using, false], ["with", :with, false]).decode(source)
|
48
|
-
assert_equal({:expr => '/hello', :with => {'who' => "'blambeau'"}, :using => ['self']}, result)
|
49
|
-
|
50
|
-
source = "buffering_template5.wtpl using self with who2: who"
|
51
|
-
result = WLang::RuleSet::Utils.expr(:uri, ["using", :using, false], ["with", :with, false]).decode(source)
|
52
|
-
assert_equal({:uri => 'buffering_template5.wtpl', :with => {'who2' => "who"}, :using => ['self']}, result)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_DIALECT_regexp
|
56
|
-
assert_not_nil(RG_DIALECT =~ "wlang")
|
57
|
-
assert_not_nil(RG_DIALECT =~ "xhtml")
|
58
|
-
assert_not_nil(RG_DIALECT =~ "\nxhtml ")
|
59
|
-
assert_not_nil(RG_DIALECT =~ "plain-text")
|
60
|
-
assert_nil(RG_DIALECT =~ "wlang/plain-text")
|
61
|
-
assert_nil(RG_DIALECT =~ " wlang/sql ")
|
62
|
-
assert_nil(RG_DIALECT =~ "WLang")
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_ENCODER_regexp
|
66
|
-
assert_not_nil(RG_ENCODER =~ "entities-encoding")
|
67
|
-
assert_not_nil(RG_ENCODER =~ "quoting")
|
68
|
-
assert_not_nil(RG_ENCODER =~ "\nquoting ")
|
69
|
-
assert_nil(RG_ENCODER =~ "xhtml/entities-encoding")
|
70
|
-
assert_nil(RG_ENCODER =~ " wlang/quoting ")
|
71
|
-
assert_nil(RG_ENCODER =~ "ENCODING")
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_QDIALECT_regexp
|
75
|
-
assert_not_nil(RG_QDIALECT =~ "wlang")
|
76
|
-
assert_not_nil(RG_QDIALECT =~ "wlang/plain-text")
|
77
|
-
assert_not_nil(RG_QDIALECT =~ "wlang/xhtml")
|
78
|
-
assert_not_nil(RG_QDIALECT =~ "wlang/sql")
|
79
|
-
assert_not_nil(RG_QDIALECT =~ " wlang/sql ")
|
80
|
-
assert_not_nil(RG_QDIALECT =~ "wlang/sql/sybase")
|
81
|
-
assert_nil(RG_QDIALECT =~ "WLang")
|
82
|
-
assert_nil(RG_QDIALECT =~ "wlang/ sql")
|
83
|
-
assert_nil(RG_QDIALECT =~ "WLang/sql")
|
84
|
-
assert_nil(RG_QDIALECT =~ "wlang/sql/ sybase")
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_QENCODER_regexp
|
88
|
-
assert_not_nil(RG_QENCODER =~ "entities-encoding")
|
89
|
-
assert_not_nil(RG_QENCODER =~ "html/entities-encoding")
|
90
|
-
assert_not_nil(RG_QENCODER =~ "sql/back-quoting")
|
91
|
-
assert_not_nil(RG_QENCODER =~ "sql/back-quoting ")
|
92
|
-
assert_not_nil(RG_QENCODER =~ "sql/sybase/back-quoting")
|
93
|
-
assert_nil(RG_QENCODER =~ "sql/ sybase/back-quoting")
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_VAR_regexp
|
97
|
-
assert_not_nil(RG_VAR =~ "name")
|
98
|
-
assert_not_nil(RG_VAR =~ "name_with_underscore")
|
99
|
-
assert_not_nil(RG_VAR =~ "\nname_with_underscore \t")
|
100
|
-
assert_nil(RG_VAR =~ "\nname _with_underscore \t")
|
101
|
-
tests = [
|
102
|
-
[{:variable =>"name"}, "name"],
|
103
|
-
[{:variable =>"name_with_underscore"}, "\nname_with_underscore \t"],
|
104
|
-
[nil, "\nname _with_underscore \t"],
|
105
|
-
]
|
106
|
-
tests.each do |t|
|
107
|
-
expected, src = t
|
108
|
-
assert_equal(expected, WLang::RuleSet::Utils.decode_var(src))
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_EXPR_regexp
|
113
|
-
assert_not_nil(RG_EXPR =~ "name")
|
114
|
-
assert_not_nil(RG_EXPR =~ "[12, 13]")
|
115
|
-
assert_not_nil(RG_EXPR =~ "Kernel.eval('some expression')")
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_QDIALECT_AS_regexp
|
119
|
-
assert_not_nil(RG_QDIALECT_AS =~ "wlang as x")
|
120
|
-
assert_not_nil(RG_QDIALECT_AS =~ "wlang/xhtml as var")
|
121
|
-
assert_not_nil(RG_QDIALECT_AS =~ " wlang/xhtml as var ")
|
122
|
-
assert_nil(RG_QDIALECT_AS =~ "wlang/xhtml")
|
123
|
-
assert_nil(RG_QDIALECT_AS =~ "wlang/xhtml as ")
|
124
|
-
tests = [
|
125
|
-
[{:dialect =>"wlang", :variable => "x"}, "wlang as x"],
|
126
|
-
[{:dialect =>"wlang", :variable => "var"}, " wlang as var"],
|
127
|
-
[{:dialect =>"wlang/xhtml", :variable => "var"}, " wlang/xhtml as var"],
|
128
|
-
[nil, " wlang as "],
|
129
|
-
]
|
130
|
-
tests.each do |t|
|
131
|
-
expected, src = t
|
132
|
-
assert_equal(expected, WLang::RuleSet::Utils.decode_qdialect_as(src))
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_QENCODER_AS_regexp
|
137
|
-
assert_not_nil(RG_QENCODER_AS =~ "entities as x")
|
138
|
-
assert_not_nil(RG_QENCODER_AS =~ "html/entities-encoding as var")
|
139
|
-
assert_not_nil(RG_QENCODER_AS =~ " wlang/xhtml/entities-encoding as var ")
|
140
|
-
assert_nil(RG_QENCODER_AS =~ "wlang/entities")
|
141
|
-
assert_nil(RG_QENCODER_AS =~ "wlang/quoting as ")
|
142
|
-
tests = [
|
143
|
-
[{:encoder =>"entities", :variable => "x"}, "entities as x"],
|
144
|
-
[{:encoder =>"entities", :variable => "var"}, " entities as var"],
|
145
|
-
[{:encoder =>"xhtml/entities-encoding", :variable => "var"}, " xhtml/entities-encoding as var"],
|
146
|
-
[nil, " wlang as "],
|
147
|
-
]
|
148
|
-
tests.each do |t|
|
149
|
-
expected, src = t
|
150
|
-
assert_equal(expected, WLang::RuleSet::Utils.decode_qencoder_as(src))
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_EXPR_AS_regexp
|
155
|
-
assert_not_nil(RG_EXPR_AS =~ "name as n")
|
156
|
-
assert_not_nil(RG_EXPR_AS =~ "name.upcase as n")
|
157
|
-
assert_not_nil(RG_EXPR_AS =~ "[12,13,15] as n")
|
158
|
-
assert_not_nil(RG_EXPR_AS =~ "[12,13, 15] as n")
|
159
|
-
assert_nil(RG_EXPR_AS =~ "name.upcase")
|
160
|
-
tests = [
|
161
|
-
[{:expr =>"name", :variable => "n"}, "name as n"],
|
162
|
-
[{:expr =>"name.upcase", :variable => "n"}, "name.upcase as n"],
|
163
|
-
[{:expr =>"name.upcase", :variable => "n"}, " name.upcase as n "],
|
164
|
-
[{:expr =>"name/upcase", :variable => "n"}, " name/upcase as n "],
|
165
|
-
[{:expr =>"[12, 15, 276, 'blamebau']", :variable => "n"}, " [12, 15, 276, 'blamebau'] as n "],
|
166
|
-
[{:expr =>"'what if a as here'", :variable => "n"}, " 'what if a as here' as n "],
|
167
|
-
]
|
168
|
-
tests.each do |t|
|
169
|
-
expected, src = t
|
170
|
-
assert_equal(expected, WLang::RuleSet::Utils.decode_expr_as(src))
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_URI_AS_regexp
|
175
|
-
assert_not_nil(RG_URI_AS =~ "file as f")
|
176
|
-
assert_not_nil(RG_URI_AS =~ "file.yaml as f")
|
177
|
-
assert_not_nil(RG_URI_AS =~ "folder/folder/file.ext as data")
|
178
|
-
assert_not_nil(RG_URI_AS =~ "http://folder/folder/file.ext as data")
|
179
|
-
assert_not_nil(RG_URI_AS =~ "http://folder/folder/as/file.ext as data")
|
180
|
-
assert_nil(RG_URI_AS =~ "name.upcase")
|
181
|
-
tests = [
|
182
|
-
[{:uri =>"file", :variable => "f"}, "file as f"],
|
183
|
-
[{:uri =>"file.yaml", :variable => "f"}, "file.yaml as f"],
|
184
|
-
[{:uri =>"folder/folder/file.ext", :variable => "data"}, "folder/folder/file.ext as data"],
|
185
|
-
[{:uri =>"http://folder/folder/file.ext", :variable => "data"}, "http://folder/folder/file.ext as data"],
|
186
|
-
[{:uri =>"http://folder/folder/as/file.ext", :variable => "data"}, "http://folder/folder/as/file.ext as data"],
|
187
|
-
]
|
188
|
-
tests.each do |t|
|
189
|
-
expected, src = t
|
190
|
-
assert_equal(expected, WLang::RuleSet::Utils.decode_uri_as(src))
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_URI_WITH_regexp
|
195
|
-
tests = [
|
196
|
-
[{:uri =>"folder/file.yaml", :with => {"spec" => "spec"}}, "folder/file.yaml with spec: spec"],
|
197
|
-
[{:uri =>"folder/file.yaml", :with => {"a" => "a", "b" => "b"}},
|
198
|
-
"folder/file.yaml with a :a , b : b"],
|
199
|
-
[{:uri =>"folder/file.yaml", :with => {"spec" => "spec.reverse"}}, "folder/file.yaml with spec: spec.reverse"],
|
200
|
-
[{:uri =>"folder/file.yaml", :with => {"s" => "spec", "t" => "spec/rulesets", "xs" => "spec/uses"}},
|
201
|
-
"folder/file.yaml with s:spec, t:spec/rulesets, xs:spec/uses"],
|
202
|
-
]
|
203
|
-
tests.each do |t|
|
204
|
-
expected, src = t
|
205
|
-
assert_equal(expected, WLang::RuleSet::Utils.decode_uri_with(src,nil))
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_URI_WITH_regexp_with_optional
|
210
|
-
tests = [
|
211
|
-
[{:uri =>"file.yaml", :with => nil}, "file.yaml"],
|
212
|
-
[{:uri =>"folder/file.yaml", :with => nil}, "folder/file.yaml"],
|
213
|
-
[{:uri =>"folder/folder/file.ext", :with => nil}, "folder/folder/file.ext"],
|
214
|
-
[{:uri =>"http://folder/folder/with/file.ext", :with => nil}, "http://folder/folder/with/file.ext"],
|
215
|
-
]
|
216
|
-
tests.each do |t|
|
217
|
-
expected, src = t
|
218
|
-
assert_equal(expected, WLang::RuleSet::Utils.decode_uri_with(src,nil,true))
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_MULTI_AS
|
223
|
-
rx = Regexp.new(WLang::RuleSet::Utils::MULTI_AS)
|
224
|
-
assert_not_nil rx =~ "a"
|
225
|
-
assert_not_nil rx =~ "a, b"
|
226
|
-
assert_not_nil rx =~ "a , b"
|
227
|
-
assert_not_nil rx =~ "a,b"
|
228
|
-
assert_not_nil rx =~ "a,b,c"
|
229
|
-
assert_not_nil rx =~ "a, b, c"
|
230
|
-
assert_not_nil rx =~ "a , b , c"
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_decode_multi_as
|
234
|
-
tests = [
|
235
|
-
[["a"], "a"],
|
236
|
-
[["a", "b"], "a, b"],
|
237
|
-
[["a", "b"], "a,b"],
|
238
|
-
[["a", "b"], "a , b"],
|
239
|
-
]
|
240
|
-
tests.each do |test|
|
241
|
-
assert_equal(test[0], WLang::RuleSet::Utils.decode_multi_as(test[1], nil))
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
end
|