Sha256: dc4912814cb2d29579a45d397fd61dcabc454328c3ab7ce244e900c0558f8cd4

Contents?: true

Size: 1.87 KB

Versions: 23

Compression:

Stored size: 1.87 KB

Contents

require "spec_helper"

describe Liquidscript::Scanner::Liquidscript, :lexer_helper do

  describe "#perform" do
    it "scans a number" do
      expect(scan("43")).to eq [
        [:number, "43"]
      ]
    end

    it "scans a string" do
      scan('"hello world" ').should eq [
        [:istring, 'hello world']
      ]

      scan(" 'foobar").should eq [
        [:sstring, "'foobar"]
      ]

      scan('"hello #{world}"').should eq [
        [:istring_begin, "hello "],
        [:identifier, "world"],
        [:istring, ""]
      ]
    end

    it "scans an identifier" do
      scan('test = 4').should eq [
        [:identifier, "test"],
        [:equal, nil],
        [:number, "4"]
      ]
    end

    it "scans brackets" do
      scan("{ test = 3 }").should eq [
        [:lbrace, nil],
        [:identifier, "test"],
        [:equal, nil],
        [:number, "3"],
        [:rbrace, nil]
      ]
    end

    it "scans keywords" do
      scan("return test = new foo").should eq [
        [:preunop, "return"],
        [:identifier, "test"],
        [:equal, nil],
        [:preunop, "new"],
        [:identifier, "foo"]
      ]
    end

    it "scans heredocs" do
      scan("<<TEST\nhello\nTEST\n").should eq [
        [:heredoc_ref, "TEST"],
        [:heredoc, "hello"]
      ]

      scan("<<-TEST\nhello \#{world}\nTEST\n").should eq [
        [:iheredoc_ref, "TEST"],
        [:iheredoc_begin, "hello "],
        [:identifier, "world"],
        [:iheredoc, ""]
      ]

      scan("hello <<TEST world\nin heredoc\nTEST\n").should eq [
        [:identifier, "hello"],
        [:heredoc_ref, "TEST"],
        [:identifier, "world"],
        [:heredoc, "in heredoc"]
      ]
    end

    describe "scanning directives" do
      subject { c = described_class.new("#! test thing\n"); c.scan; c }
      its(:metadata) { should eq :directives => [{:command => "test", :args => "thing"}] }
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
liquidscript-0.10.4 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.10.3 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.10.2 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.10.1 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.10.0 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.9.2 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.9.1 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.9.0 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.8.2 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.8.1 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.8.0 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.7.12 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.7.11 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.7.10 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.7.9 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.7.8 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.7.7 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.7.6 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.7.5 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.7.4 spec/liquidscript/scanner/lexer_spec.rb