Skip to content

Commit

Permalink
Adds blackbox tests on the buffering ruleset (no bug detected so far).
Browse files Browse the repository at this point in the history
  • Loading branch information
blambeau committed Jan 25, 2010
1 parent eb3522e commit a110ec3
Show file tree
Hide file tree
Showing 39 changed files with 64 additions and 8 deletions.
5 changes: 5 additions & 0 deletions lib/wlang.rb
Expand Up @@ -129,6 +129,11 @@ def self.load_data(uri, extension=nil)
loader.call(uri)
end

# Maps a file extension to a dialect qualified name
def self.file_extension_map(extension, dialect_qname)
WLang::FILE_EXTENSIONS[extension] = dialect_qname
end

# Infers a dialect from a file extension
def self.infer_dialect(uri)
WLang::FILE_EXTENSIONS[File.extname(uri)]
Expand Down
4 changes: 2 additions & 2 deletions lib/wlang/basic_object.rb
Expand Up @@ -6,8 +6,8 @@ module WLang
class BasicObject

# Methods that we keep
KEPT_METHODS = ["__send__", "__id__", "instance_eval", "initialize", "object_id", "nil?",
:__send__, :__id__, :instance_eval, :initialize, :object_id, :nil?]
KEPT_METHODS = ["__send__", "__id__", "instance_eval", "initialize", "object_id", "nil?", "singleton_method_added",
:__send__, :__id__, :instance_eval, :initialize, :object_id, :nil?, :singleton_method_added]

# Removes all methods that are not needed to the class
(instance_methods + private_instance_methods).each do |m|
Expand Down
9 changes: 8 additions & 1 deletion lib/wlang/hosted_language.rb
Expand Up @@ -19,13 +19,20 @@ def method_missing(name, *args, &block)
if @parser_state.scope.has_key?(name.to_s)
@parser_state.scope[name.to_s]
else
Kernel.raise ::WLang::UndefinedVariableError.new(nil, nil, nil, name)
variable_missing(name)
end
else
super(name, *args, &block)
end
end

# Called when a variable cannot be found. By default, it raises an
# UndefinedVariableError. This method is intended to be overriden
# for handling such a situation more friendly.
def variable_missing(name)
Kernel.raise ::WLang::UndefinedVariableError.new(nil, nil, nil, name)
end

#
# Evaluates a given expression in the context of a given
# parser state.
Expand Down
2 changes: 1 addition & 1 deletion lib/wlang/rulesets/buffering_ruleset.rb
Expand Up @@ -85,7 +85,7 @@ def self.input_inclusion(parser, offset)
parser.syntax_error(offset) if decoded.nil?

# Look for share and context
shared = decoded[:share].nil? ? :root : decoded[:share]
shared = decoded[:share].nil? ? :none : decoded[:share]
context = U.context_from_using_and_with(decoded)

# Resolve the file by delegation to the parser
Expand Down
1 change: 1 addition & 0 deletions test/blackbox/buffering/data_1.rb
@@ -0,0 +1 @@
"blambeau"
1 change: 1 addition & 0 deletions test/blackbox/buffering/data_assignment_1.exp
@@ -0,0 +1 @@
blambeau
1 change: 1 addition & 0 deletions test/blackbox/buffering/data_assignment_1.tpl
@@ -0,0 +1 @@
<<={data_1.rb as x}{+{x}}
1 change: 1 addition & 0 deletions test/blackbox/buffering/data_assignment_2.exp
@@ -0,0 +1 @@
blambeau wlang
1 change: 1 addition & 0 deletions test/blackbox/buffering/data_assignment_2.tpl
@@ -0,0 +1 @@
<<={data_1.rb as who}{+{who}} +{who}
1 change: 1 addition & 0 deletions test/blackbox/buffering/data_assignment_3.exp
@@ -0,0 +1 @@
blambeau wlang
1 change: 1 addition & 0 deletions test/blackbox/buffering/data_assignment_3.tpl
@@ -0,0 +1 @@
<<={+{data_file_1} as who}{+{who}} +{who}
1 change: 1 addition & 0 deletions test/blackbox/buffering/data_assignment_4.exp
@@ -0,0 +1 @@
blambeau wlang
1 change: 1 addition & 0 deletions test/blackbox/buffering/data_assignment_4.tpl
@@ -0,0 +1 @@
<<={../+{data_file_1} as who}{+{who}} +{who}
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_1.exp
@@ -0,0 +1 @@
text_1
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_1.tpl
@@ -0,0 +1 @@
<<{text_1.txt}
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_2.exp
@@ -0,0 +1 @@
wlang
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_2.tpl
@@ -0,0 +1 @@
<<{+{who}.txt}
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_3.exp
@@ -0,0 +1 @@
text_1
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_3.tpl
@@ -0,0 +1 @@
<<{+{input_file}}
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion.exp
@@ -0,0 +1 @@
wlang
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion.tpl
@@ -0,0 +1 @@
+{who}
Empty file.
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion_1.tpl
@@ -0,0 +1 @@
<<+{input_inclusion.tpl share none}
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion_2.exp
@@ -0,0 +1 @@
wlang
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion_2.tpl
@@ -0,0 +1 @@
<<+{input_inclusion.tpl share root}
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion_3.exp
@@ -0,0 +1 @@
wlang
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion_3.tpl
@@ -0,0 +1 @@
<<+{input_inclusion.tpl share all}
Empty file.
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion_4.tpl
@@ -0,0 +1 @@
<<+{input_inclusion_1.tpl with who: 'blambeau'}
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion_5.exp
@@ -0,0 +1 @@
blambeau
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion_5.tpl
@@ -0,0 +1 @@
<<+{input_inclusion_2.tpl with who: 'blambeau'}
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion_6.exp
@@ -0,0 +1 @@
blambeau
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion_6.tpl
@@ -0,0 +1 @@
<<+{input_inclusion_3.tpl with who: 'blambeau'}
Empty file.
1 change: 1 addition & 0 deletions test/blackbox/buffering/input_inclusion_7.tpl
@@ -0,0 +1 @@
<<+{input_inclusion.tpl}
1 change: 1 addition & 0 deletions test/blackbox/buffering/text_1.txt
@@ -0,0 +1 @@
text_1
1 change: 1 addition & 0 deletions test/blackbox/buffering/wlang.txt
@@ -0,0 +1 @@
wlang
1 change: 1 addition & 0 deletions test/blackbox/data_1.rb
@@ -0,0 +1 @@
"blambeau"
21 changes: 17 additions & 4 deletions test/blackbox/test_all.rb
Expand Up @@ -18,22 +18,35 @@ def test_on_examples
rules WLang::RuleSet::Basic
rules WLang::RuleSet::Context
}
dialect("buffering") {
ruby_require "wlang/rulesets/basic_ruleset"
ruby_require "wlang/rulesets/buffering_ruleset"
rules WLang::RuleSet::Basic
rules WLang::RuleSet::Buffering
}
end
hosted = ::WLang::HostedLanguage.new
def hosted.variable_missing(name)
""
end
WLang::file_extension_map('.tpl', 'blackbox/buffering')

# Context used here
context = {
'who' => 'wlang',
'whowho' => 'who'
'who' => 'wlang',
'whowho' => 'who',
'input_file' => 'text_1.txt',
'data_file_1' => 'data_1.rb'
}

Dir["#{File.dirname(__FILE__)}/*"].each do |folder|
dialect_name = File.basename(folder)
Dir["#{folder}/*.tpl"].each do |template_file|
begin
basename = File.basename(template_file, ".tpl")
template = File.read(File.join(folder, "#{basename}.tpl"))
expected = File.read(File.join(folder, "#{basename}.exp"))
assert_equal(expected, template.wlang(context.dup, "blackbox/#{dialect_name}"), "Blackbox test failed #{basename}")
template = WLang::file_template(template_file, "blackbox/#{dialect_name}")
assert_equal(expected, template.instantiate(context.dup, hosted), "Blackbox test failed #{basename}")
rescue Exception => ex
puts "Blackbox test failed: #{template_file}\n#{ex.message}"
puts ex.backtrace.join("\n")
Expand Down

0 comments on commit a110ec3

Please sign in to comment.