Sha256: c2b6f62443b86f494352cb54444bd724445e1ef7dbe25bf9250d9921c77f0860

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 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 [
        [:unop, "return"],
        [:identifier, "test"],
        [:equal, nil],
        [:unop, "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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
liquidscript-0.6.1 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.6.0 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.5.1 spec/liquidscript/scanner/lexer_spec.rb
liquidscript-0.5.0 spec/liquidscript/scanner/lexer_spec.rb