spec/token_spec.rb in luobo-0.0.2 vs spec/token_spec.rb in luobo-0.0.5

- old
+ new

@@ -1,32 +1,123 @@ require "spec_helper" -describe Luobo::Token do - subject (:token) do - Luobo::Token.new(1, "line", 4, "Echo", "same: hash", "['block', 'in', 'array']") - end +class LuaToken < Luobo + def regex_line_comment; "\s*\-\-+\s" end + def dump contents; contents end # directly return +end - its :ln do - should eq(1) +class RubyToken < Luobo + def regex_line_comment; "\s*#+\s" end + def dump contents; contents end +end + +describe Luobo do + context "without line comment marker" do + subject (:lb) do + Luobo.new('-', STDOUT) + end + + it "return a token without indent" do + token = lb.tokenize(1, "PROCNAME: proc line code") + token.is_a?(Token).should be_true + token.processor_name.should eq("PROCNAME") + token.indent_level.should eq(0) + token.ln.should eq(1) + token.line.should eq("PROCNAME: proc line code") + token.line_code.should eq("proc line code") + token.has_block?.should be_false + token.block_code.should eq("") + token.block_open?.should be_false + end + + it "return a token with indent" do + token = lb.tokenize(1, " PROCNAME: proc line code") + token.processor_name.should eq("PROCNAME") + token.indent_level.should eq(2) + token.line_code.should eq("proc line code") + token.has_block?.should be_false + token.block_code.should eq("") + token.block_open?.should be_false + end + + it "return a token with block open" do + token = lb.tokenize(1, "PROCNAME2: proc line code ->") + token.processor_name.should eq("PROCNAME2") + token.line.should eq("PROCNAME2: proc line code ->") + token.line_code.should eq("proc line code") + token.block_code.should eq("") + token.block_open?.should be_true + token.has_block?.should be_false # no block added yet + token.add_block_code("Should\nBe True\n") + token.has_block?.should be_true + token.blocks.size.should eq(2) + end end - its :line do - should eq("line") + context "lua comment with no indent" do + subject do + LuaToken.new('-', STDOUT).tokenize(2, " -- SPEC: what ever ->") + end + + its :processor_name do + should eq("SPEC") + end + + its :line_code do + should eq("what ever") + end + + its :block_open? do + should be_true + end + + its :indent_level do + should eq(0) + end end - its :indent_level do - should eq(4) + + context "lua comment with indent" do + subject do + LuaToken.new('-', STDOUT).tokenize(2, " -- SPEC: what ever ->") + end + + its :indent_level do + should eq(2) + end end - its :processor_name do - should eq("Echo") + context "ruby comment with indent" do + subject do + RubyToken.new('-', STDOUT).tokenize(2, " # INSIDE: what ever ->") + end + + its :processor_name do + should eq("INSIDE") + end + + its :indent_level do + should eq(4) + end end - its :line_args do - token.line_args["same"].should eq("hash") + context "plain raw line" do + subject do + Luobo.new('-', STDOUT).tokenize(20, "What a wonderful spirit") + end + + its :processor_name do + should eq("_raw") + end end - its :block_args do - token.block_args[2].should eq("array") + context "ruby comment with raw line" do + subject do + Luobo.new('-', STDOUT).tokenize(20, "# What a wonderful spirit") + end + + its :processor_name do + should eq("_raw") + end end end