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
data/test/unit/test_all.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.expand_path('../../../', __FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
|
3
|
-
require 'wlang'
|
4
|
-
require 'test/unit'
|
5
|
-
test_files = Dir[File.join(File.dirname(__FILE__), '**/*_test.rb')]
|
6
|
-
test_files.each { |file|
|
7
|
-
require(file)
|
8
|
-
}
|
9
|
-
|
@@ -1,111 +0,0 @@
|
|
1
|
-
# require 'test/unit'
|
2
|
-
# require 'wlang'
|
3
|
-
# module WLang
|
4
|
-
#
|
5
|
-
# # Tests the IntelligentBuffer class
|
6
|
-
# class AnagramBugsTest < Test::Unit::TestCase
|
7
|
-
# include IntelligentBuffer::Methods
|
8
|
-
#
|
9
|
-
# def test_on_anagram_spacing_policy
|
10
|
-
# WLang::dialect("anagram") do
|
11
|
-
# rule '=~' do |parser,offset|
|
12
|
-
# match, reached = parser.parse(offset, "wlang/dummy")
|
13
|
-
# block, reached = parser.parse_block(reached, "wlang/dummy")
|
14
|
-
#
|
15
|
-
# # puts "Here is the block ==="
|
16
|
-
# # puts "#{block.gsub(/ /, '.').gsub(/\n/, "\\n\n")}"
|
17
|
-
# # puts "=== Here is the block"
|
18
|
-
#
|
19
|
-
# [block, reached]
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
# template = %q{
|
23
|
-
# =~{String}{
|
24
|
-
# this is an anagram template
|
25
|
-
# }
|
26
|
-
# }.gsub(/^ {8}/, '').strip
|
27
|
-
# result = template.wlang_instantiate({}, "anagram")
|
28
|
-
# #assert IntelligentBuffer===result
|
29
|
-
# # assert_equal("this is an anagram template", result)
|
30
|
-
#
|
31
|
-
# template = %q{
|
32
|
-
# =~{String}{
|
33
|
-
# module MyModule
|
34
|
-
# end
|
35
|
-
# }
|
36
|
-
# }.gsub(/^ {8}/, '').strip
|
37
|
-
# result = template.wlang_instantiate({}, "anagram")
|
38
|
-
# #assert IntelligentBuffer===result
|
39
|
-
# assert_equal("module MyModule\nend\n", result)
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# def test_missing_end_bug
|
43
|
-
# WLang::dialect("anagram") do
|
44
|
-
# rules WLang::RuleSet::Basic
|
45
|
-
# rules WLang::RuleSet::Imperative
|
46
|
-
# rule '=~' do |parser,offset|
|
47
|
-
# match, reached = parser.parse(offset, "wlang/dummy")
|
48
|
-
# match = parser.evaluate(match)
|
49
|
-
# block, reached = parser.parse_block(reached, "wlang/dummy")
|
50
|
-
# block = block.strip_block(block)
|
51
|
-
# block = block.tabto(block,0)
|
52
|
-
# parser.evaluate("matching_rules") << [match, block]
|
53
|
-
#
|
54
|
-
# # puts "Here is the block ==="
|
55
|
-
# # puts "#{block.gsub(/ /, '.').gsub(/\n/, "\\n\n")}"
|
56
|
-
# # puts "=== Here is the block"
|
57
|
-
#
|
58
|
-
# ["", reached]
|
59
|
-
# end
|
60
|
-
# rule '+~' do |parser,offset|
|
61
|
-
# what, reached = parser.parse(offset, "wlang/dummy")
|
62
|
-
# evaluated = parser.evaluate(what)
|
63
|
-
# raise "Unexpected case, #{what} leads to nil" unless evaluated
|
64
|
-
#
|
65
|
-
# rules = parser.evaluate("matching_rules")
|
66
|
-
# found = rules.find {|r| r[0]===evaluated}
|
67
|
-
# raise "Unexpected case: no match for #{what.class}" unless found
|
68
|
-
#
|
69
|
-
# context = {"n" => evaluated, "matching_rules" => rules}
|
70
|
-
# inst = found[1].wlang_instantiate(context, "anagram")
|
71
|
-
#
|
72
|
-
# inst2 = inst.gsub(/ /, '.').gsub(/\n/, "\\n\n")
|
73
|
-
# # puts "Here is the inst ==="
|
74
|
-
# # puts "#{inst2}"
|
75
|
-
# # puts "=== Here is the inst"
|
76
|
-
#
|
77
|
-
# found = [inst, reached]
|
78
|
-
# end
|
79
|
-
# end
|
80
|
-
# template = %Q{
|
81
|
-
# =~{Array}{
|
82
|
-
# module MyModule
|
83
|
-
# *{n as c}{
|
84
|
-
# +~{c}
|
85
|
-
# }
|
86
|
-
# end
|
87
|
-
# }
|
88
|
-
# =~{Integer}{
|
89
|
-
# +{n}
|
90
|
-
# }
|
91
|
-
# +~{n}
|
92
|
-
# }.gsub(/ {8}/,'').strip
|
93
|
-
# context = {'n' => [10, 20, 30], 'matching_rules' => []}
|
94
|
-
# result = template.wlang_instantiate(context, "anagram")
|
95
|
-
#
|
96
|
-
# # template = template.gsub(/ /, '.').gsub(/\n/, "\\n\n")
|
97
|
-
# # puts "Here is the template ==="
|
98
|
-
# # puts "#{template}"
|
99
|
-
# # puts "=== Here is the template"
|
100
|
-
#
|
101
|
-
# # result = result.gsub(/ /, '.').gsub(/\n/, "\\n\n")
|
102
|
-
# # puts "Here is the result ==="
|
103
|
-
# # puts "#{result}"
|
104
|
-
# # puts "=== Here is the result"
|
105
|
-
# result = result.strip
|
106
|
-
# expected = "module MyModule\n 10\n \n 20\n \n 30\n\nend"
|
107
|
-
# assert_equal expected, result
|
108
|
-
# end
|
109
|
-
#
|
110
|
-
# end
|
111
|
-
# end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'wlang'
|
3
|
-
require File.join(File.dirname(__FILE__), 'test_utils.rb')
|
4
|
-
require 'wlang/rulesets/basic_ruleset'
|
5
|
-
require 'wlang/rulesets/context_ruleset'
|
6
|
-
require 'wlang/rulesets/buffering_ruleset'
|
7
|
-
|
8
|
-
# Tests the Basic ruleset
|
9
|
-
class WLang::BasicRuleSetTest < Test::Unit::TestCase
|
10
|
-
include WLang::TestUtils
|
11
|
-
|
12
|
-
# Installs a dialect on wlang
|
13
|
-
def setup
|
14
|
-
WLang::dialect "basic-test" do
|
15
|
-
rules WLang::RuleSet::Basic
|
16
|
-
rules WLang::RuleSet::Context
|
17
|
-
rules WLang::RuleSet::Buffering
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# tests !{wlang/hosted} operator
|
22
|
-
def test_execution
|
23
|
-
tests = [
|
24
|
-
["!{name}", "blambeau", {"name" => "blambeau"}],
|
25
|
-
["!{!{var}}", "blambeau", {"var" => "name", "name" => "blambeau"}],
|
26
|
-
["!{'hello'.upcase}", "HELLO", {}]
|
27
|
-
]
|
28
|
-
tests.each do |t|
|
29
|
-
template, expected, context = t
|
30
|
-
result = template.wlang(context, "basic-test")
|
31
|
-
assert_equal(expected, result)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Tests recursive_application rule
|
36
|
-
def test_recursive_application
|
37
|
-
tests = [
|
38
|
-
["#={code}{%{wlang/dummy}{+{variable}}}"\
|
39
|
-
"%!{basic-test with variable: 'hello'}{+{code}}", "hello"],
|
40
|
-
["<<={data.rb as context}"\
|
41
|
-
"#={code}{%{wlang/dummy}{+{author}}}"\
|
42
|
-
"%!{basic-test using context}{+{code}}", "blambeau"]
|
43
|
-
]
|
44
|
-
tests.each do |test|
|
45
|
-
template, expected = test
|
46
|
-
template = relative_template(template, "basic-test", __FILE__)
|
47
|
-
result = template.instantiate()
|
48
|
-
assert_equal(expected, result)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end # class WLang::BasicRuleSetTest
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'wlang'
|
3
|
-
require File.join(File.dirname(__FILE__), 'test_utils.rb')
|
4
|
-
require 'wlang/rulesets/buffering_ruleset'
|
5
|
-
|
6
|
-
# Tests the Scoping ruleset
|
7
|
-
class WLang::BufferingRuleSetTest < Test::Unit::TestCase
|
8
|
-
include WLang::TestUtils
|
9
|
-
|
10
|
-
# Installs a dialect on wlang
|
11
|
-
def setup
|
12
|
-
WLang::dialect "buffering-test" do
|
13
|
-
rules WLang::RuleSet::Basic
|
14
|
-
rules WLang::RuleSet::Buffering
|
15
|
-
rule ';' do |parser, offset|
|
16
|
-
text, reached = parser.parse(offset)
|
17
|
-
[text.upcase, reached]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Tests input rule
|
23
|
-
def test_input
|
24
|
-
expected = read_relative_file("ruby_template.wrb", __FILE__)
|
25
|
-
template = relative_template("<<{ruby_template.wrb}", "buffering-test", __FILE__)
|
26
|
-
result = template.instantiate()
|
27
|
-
assert_equal(expected, result)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Tests that input rule allows creating file name in wlang
|
31
|
-
def test_input_accepts_injection
|
32
|
-
expected = read_relative_file("ruby_template.wrb", __FILE__)
|
33
|
-
template = relative_template("<<{ruby_template.wrb}", "buffering-test", __FILE__)
|
34
|
-
result = template.instantiate("ext" => "wrb")
|
35
|
-
assert_equal(expected, result)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Tests output rule
|
39
|
-
def test_output
|
40
|
-
output = relative_file("buffering_ruleset_test_output.txt", __FILE__)
|
41
|
-
File.delete(output) if File.exists?(output)
|
42
|
-
template = relative_template(">>{buffering_ruleset_test_output.txt}{an output}", "buffering-test", __FILE__)
|
43
|
-
assert_equal("", template.instantiate)
|
44
|
-
assert_equal("an output", File.read(output))
|
45
|
-
File.delete(output) if File.exists?(output)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Tests output rule allows creating file name in wlang
|
49
|
-
def test_output_accepts_injection
|
50
|
-
output = relative_file("buffering_ruleset_test_output.txt", __FILE__)
|
51
|
-
File.delete(output) if File.exists?(output)
|
52
|
-
template = relative_template(">>{buffering_ruleset_test_output.${ext}}{an output}", "buffering-test", __FILE__)
|
53
|
-
assert_equal("", template.instantiate("ext" => "txt"))
|
54
|
-
assert_equal("an output", File.read(output))
|
55
|
-
File.delete(output) if File.exists?(output)
|
56
|
-
end
|
57
|
-
|
58
|
-
# Tests output rule parses the second block in same dialect
|
59
|
-
def test_output_stays_in_same_dialect
|
60
|
-
output = relative_file("buffering_ruleset_test_output.txt", __FILE__)
|
61
|
-
File.delete(output) if File.exists?(output)
|
62
|
-
template = relative_template(">>{buffering_ruleset_test_output.txt}{;{an output}}", "buffering-test", __FILE__)
|
63
|
-
assert_equal("", template.instantiate())
|
64
|
-
assert_equal("AN OUTPUT", File.read(output))
|
65
|
-
File.delete(output) if File.exists?(output)
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_output_created_dirs
|
69
|
-
output = relative_file("buffering_ruleset_output/buffering_ruleset_test_output.txt", __FILE__)
|
70
|
-
File.delete(output) if File.exists?(output)
|
71
|
-
template = relative_template(">>{buffering_ruleset_output/buffering_ruleset_test_output.txt}{an output}", "buffering-test", __FILE__)
|
72
|
-
assert_equal("", template.instantiate())
|
73
|
-
assert_equal("an output", File.read(output))
|
74
|
-
File.delete(output) if File.exists?(output)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_output_multiple_created_dirs
|
78
|
-
output = relative_file("buffering_ruleset_output/subdir/subdir/buffering_ruleset_test_output.txt", __FILE__)
|
79
|
-
File.delete(output) if File.exists?(output)
|
80
|
-
template = relative_template(">>{buffering_ruleset_output/subdir/subdir/buffering_ruleset_test_output.txt}{an output}", "buffering-test", __FILE__)
|
81
|
-
assert_equal("", template.instantiate())
|
82
|
-
assert_equal("an output", File.read(output))
|
83
|
-
File.delete(output) if File.exists?(output)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Tests that an included template can include other thinks
|
87
|
-
def test_inclusion_in_include_template_works
|
88
|
-
expected = "template3"
|
89
|
-
file = relative_file("buffering_template1.wtpl", __FILE__)
|
90
|
-
result = WLang::file_instantiate(file)
|
91
|
-
assert_equal(expected, result)
|
92
|
-
end
|
93
|
-
|
94
|
-
# Tests that an included template can include other thinks
|
95
|
-
def test_with_works_in_inclusion
|
96
|
-
expected = "blambeau world"
|
97
|
-
file = relative_file("buffering_template4.wtpl", __FILE__)
|
98
|
-
result = WLang::file_instantiate(file, {"who" => "blambeau"})
|
99
|
-
assert_equal(expected, result)
|
100
|
-
end
|
101
|
-
|
102
|
-
end # class WLang::ScopingRuleSetTest
|
@@ -1 +0,0 @@
|
|
1
|
-
<<+{buffering_template2.wtpl}
|
@@ -1 +0,0 @@
|
|
1
|
-
<<+{buffering_template3.wtpl}
|
@@ -1 +0,0 @@
|
|
1
|
-
template3
|
@@ -1 +0,0 @@
|
|
1
|
-
<<+{buffering_template5.wtpl share all with who2: who, hello: 'world'}
|
@@ -1 +0,0 @@
|
|
1
|
-
+{who2} +{hello}
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'test/unit/testcase'
|
2
|
-
require 'wlang'
|
3
|
-
require 'wlang/rulesets/basic_ruleset'
|
4
|
-
require 'wlang/rulesets/context_ruleset'
|
5
|
-
|
6
|
-
# Tests the Scoping ruleset
|
7
|
-
class WLang::ContextRuleSetTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
# Installs a dialect on wlang
|
10
|
-
def setup
|
11
|
-
WLang::dialect "context-test" do
|
12
|
-
rules WLang::RuleSet::Basic
|
13
|
-
rules WLang::RuleSet::Context
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Tests the define decoder
|
18
|
-
def test_block_assignment
|
19
|
-
tests = [
|
20
|
-
["#={code}{hello}+{code}", "hello"],
|
21
|
-
["#={code}{hello}{+{code}}", "hello"],
|
22
|
-
["#={code}{%{wlang/dummy}{hello}}{+{code}}", "hello"],
|
23
|
-
["#={code}{%{wlang/dummy}{+{hello}}}{+{code}}", "+{hello}"]
|
24
|
-
]
|
25
|
-
tests.each do |test|
|
26
|
-
template, expected = test
|
27
|
-
result = template.wlang(nil, "context-test")
|
28
|
-
assert_equal(expected, result)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end # class WLang::ScopingRuleSetTest
|
data/test/unit/wlang/data.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'test/unit/testcase'
|
2
|
-
require 'wlang'
|
3
|
-
module WLang
|
4
|
-
|
5
|
-
# Tests Dialect class
|
6
|
-
class EncoderSetTest < Test::Unit::TestCase
|
7
|
-
|
8
|
-
# Installs a simple upcase/lowcase plain-text dialect
|
9
|
-
def setup
|
10
|
-
@plain = WLang::EncoderSet.new
|
11
|
-
@plain.add_encoder(:upcase)
|
12
|
-
@plain.add_encoder("downcase") {|src,options| src.downcase}
|
13
|
-
identity = Proc.new {|src, options| src}
|
14
|
-
@plain.add_encoder("identity", identity)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Tests has_encoder? method
|
18
|
-
def test_has_encoder
|
19
|
-
assert_equal(true, @plain.has_encoder?("upcase"))
|
20
|
-
assert_equal(true, @plain.has_encoder?("downcase"))
|
21
|
-
assert_equal(true, @plain.has_encoder?("identity"))
|
22
|
-
assert_equal(false, @plain.has_encoder?("encoding"))
|
23
|
-
end
|
24
|
-
|
25
|
-
# Tests get_encoder method
|
26
|
-
def test_get_encoder
|
27
|
-
assert_equal(true, @plain.get_encoder("upcase").is_a?(Encoder))
|
28
|
-
assert_equal(true, @plain.get_encoder("downcase").is_a?(Encoder))
|
29
|
-
assert_equal(true, @plain.get_encoder("identity").is_a?(Encoder))
|
30
|
-
assert_nil(@plain.get_encoder("encoding"))
|
31
|
-
end
|
32
|
-
|
33
|
-
# Tests the encode method
|
34
|
-
def test_encode
|
35
|
-
assert_equal("IN UPPER CASE", @plain.encode("upcase","in Upper Case"))
|
36
|
-
assert_equal("in lower case", @plain.encode("downcase","IN Lower CASE"))
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
end # class TargetLanguageTest
|
41
|
-
|
42
|
-
end # module WLang
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require "wlang"
|
3
|
-
require 'wlang/rulesets/imperative_ruleset'
|
4
|
-
module WLang
|
5
|
-
|
6
|
-
# Tests the Imperative rule set
|
7
|
-
class ImperativeRuleSetTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
# Installs some dialects on wlang
|
10
|
-
def setup
|
11
|
-
# wlang dialect, empty by default
|
12
|
-
WLang::dialect "imperative-test" do
|
13
|
-
rules WLang::RuleSet::Basic
|
14
|
-
rules WLang::RuleSet::Imperative
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Tests the each regexp
|
19
|
-
def test_decode_each
|
20
|
-
expr = WLang::RuleSet::Utils.expr(:expr,
|
21
|
-
["using", :var, false],
|
22
|
-
["as", :multi_as, false])
|
23
|
-
hash = expr.decode("items")
|
24
|
-
assert_equal({:expr => "items", :using => nil, :as => nil}, hash)
|
25
|
-
hash = expr.decode("the_items")
|
26
|
-
assert_equal({:expr => "the_items", :using => nil, :as => nil}, hash)
|
27
|
-
hash = expr.decode("items using each_with_index")
|
28
|
-
assert_equal({:expr => "items", :using => "each_with_index", :as => nil}, hash)
|
29
|
-
hash = expr.decode("items as x")
|
30
|
-
assert_equal({:expr => "items", :using => nil, :as => ["x"]}, hash)
|
31
|
-
hash = expr.decode("items using each_with_index as x, i")
|
32
|
-
assert_equal({:expr => "items", :using => "each_with_index", :as => ["x", "i"]}, hash)
|
33
|
-
hash = expr.decode("names using each_with_index as name, i")
|
34
|
-
assert_equal({:expr => "names", :using => "each_with_index", :as => ["name", "i"]}, hash)
|
35
|
-
text = "p.items.children using each_with_index as child, i"
|
36
|
-
assert_not_nil(expr.decode(text))
|
37
|
-
end
|
38
|
-
|
39
|
-
# Tests merging args
|
40
|
-
def test_merge_each_args
|
41
|
-
hash = WLang::RuleSet::Imperative.merge_each_args(["item", "index"], [1, 2])
|
42
|
-
assert_equal({"item" => 1, "index" => 2}, hash)
|
43
|
-
hash = WLang::RuleSet::Imperative.merge_each_args(["item", "index"], [1])
|
44
|
-
assert_equal({"item" => 1}, hash)
|
45
|
-
hash = WLang::RuleSet::Imperative.merge_each_args(["item"], [1, 2])
|
46
|
-
assert_equal({"item" => 1}, hash)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Tests conditional
|
50
|
-
def test_conditional
|
51
|
-
context = {"name" => "blambeau", "no" => false, "yes" => true}
|
52
|
-
tests = [
|
53
|
-
["?{true}{then} after", "then after"],
|
54
|
-
["?{true}{then}{else} after", "then after"],
|
55
|
-
["?{false}{text} after", " after"],
|
56
|
-
["?{false}{text}{else} after", "else after"],
|
57
|
-
["before ?{true}{then} after", "before then after"],
|
58
|
-
["before ?{true}{then}{else} after", "before then after"],
|
59
|
-
["before ?{false}{text} after", "before after"],
|
60
|
-
["before ?{false}{text}{else} after", "before else after"],
|
61
|
-
["?{name}{${name}}", "blambeau"],
|
62
|
-
["?{nil}{${name}}{else}", "else"],
|
63
|
-
["?{no}{${name}}", ""],
|
64
|
-
["?{yes}{${name}}", "blambeau"],
|
65
|
-
]
|
66
|
-
tests.each do |test|
|
67
|
-
result = test[0].wlang_instantiate(context, "imperative-test")
|
68
|
-
assert_equal(test[1], result)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Tests the enumration
|
73
|
-
def test_enumeration
|
74
|
-
context = {"names" => ["blambeau", "llambeau", "chl"],
|
75
|
-
"empty" => [],
|
76
|
-
"one" => ["blambeau"],
|
77
|
-
"two" => ["blambeau", "llambeau"]}
|
78
|
-
tests = [
|
79
|
-
['*{["blambeau","llambeau","chl"] as x}{${x}}{, }', "blambeau, llambeau, chl"],
|
80
|
-
["*{names as name}{${name}}", "blambeaullambeauchl"],
|
81
|
-
["*{names as name}{${name}}{, }", "blambeau, llambeau, chl"],
|
82
|
-
["*{names using each_with_index as name, i}{${i}:${name}}{, }", "0:blambeau, 1:llambeau, 2:chl"],
|
83
|
-
["*{empty as e}{+{e}}", ""],
|
84
|
-
["*{empty as e}{+{e}}{}", ""],
|
85
|
-
["*{empty as e}{+{e}}{ }", ""],
|
86
|
-
["*{one as e}{+{e}}", "blambeau"],
|
87
|
-
["*{one as e}{+{e}}{}", "blambeau"],
|
88
|
-
["*{one as e}{+{e}}{ }", "blambeau"],
|
89
|
-
["*{two as t}{+{t}}", "blambeaullambeau"],
|
90
|
-
["*{two as t}{+{t}}{ }", "blambeau llambeau"]
|
91
|
-
]
|
92
|
-
tests.each do |test|
|
93
|
-
result = test[0].wlang_instantiate(context, "imperative-test")
|
94
|
-
assert_equal(test[1], result)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_enumeration_bug
|
99
|
-
context = {"hello" => "world", "names" => ["blambeau", "llambeau", "chl"]}
|
100
|
-
expected = "worldworldworld"
|
101
|
-
template = "*{names as n}{+{hello}}"
|
102
|
-
assert_equal expected, template.wlang_instantiate(context, "imperative-test")
|
103
|
-
end
|
104
|
-
|
105
|
-
end # class ImperativeRuleSetTest
|
106
|
-
|
107
|
-
end # module WLang
|