spec/scanner_spec.rb in curly-templates-2.0.1 vs spec/scanner_spec.rb in curly-templates-2.1.0.beta1

- old
+ new

@@ -2,27 +2,21 @@ describe Curly::Scanner, ".scan" do it "returns the tokens in the source" do scan("foo {{bar}} baz").should == [ [:text, "foo "], - [:component, "bar"], + [:component, "bar", nil, {}], [:text, " baz"] ] end it "scans components with identifiers" do scan("{{foo.bar}}").should == [ - [:component, "foo.bar"] + [:component, "foo", "bar", {}] ] end - it "allows components with whitespace" do - scan("{{ foo bar}}").should == [ - [:component, " foo bar"] - ] - end - it "scans comments in the source" do scan("foo {{!bar}} baz").should == [ [:text, "foo "], [:comment, "bar"], [:text, " baz"] @@ -57,33 +51,49 @@ [:text, "{{"], [:text, " lala! }} bar"] ] end + it "scans context block tags" do + scan('{{@search_form}}{{query_field}}{{/search_form}}').should == [ + [:context_block_start, "search_form", nil, {}], + [:component, "query_field", nil, {}], + [:block_end, "search_form", nil] + ] + end + it "scans conditional block tags" do scan('foo {{#bar?}} hello {{/bar?}}').should == [ [:text, "foo "], - [:conditional_block_start, "bar?"], + [:conditional_block_start, "bar?", nil, {}], [:text, " hello "], - [:conditional_block_end, "bar?"] + [:block_end, "bar?", nil] ] end + it "scans conditional block tags with parameters and attributes" do + scan('{{#active.test? name="test"}}yo{{/active.test?}}').should == [ + [:conditional_block_start, "active?", "test", { "name" => "test" }], + [:text, "yo"], + [:block_end, "active?", "test"] + ] + end + it "scans inverse block tags" do scan('foo {{^bar?}} hello {{/bar?}}').should == [ [:text, "foo "], - [:inverse_conditional_block_start, "bar?"], + [:inverse_conditional_block_start, "bar?", nil, {}], [:text, " hello "], - [:conditional_block_end, "bar?"] + [:block_end, "bar?", nil] ] end it "scans collection block tags" do scan('foo {{*bar}} hello {{/bar}}').should == [ [:text, "foo "], - [:collection_block_start, "bar"], + [:collection_block_start, "bar", nil, {}], [:text, " hello "], - [:collection_block_end, "bar"] + [:block_end, "bar", nil] ] end it "treats quotes as text" do scan('"').should == [