Sha256: c37a515abad6888573a48dcc8cca68613d4b5758dc7078a685302415e010cd80

Contents?: true

Size: 1.23 KB

Versions: 10

Compression:

Stored size: 1.23 KB

Contents

require "spec_helper"

describe Liquidscript::Scanner::Lexer, :lexer_helper do
  subject { described_class.new }
  describe "#emit" do
    it "pushes a token" do
      subject.instance_exec { @data = "hello"; @ts = 0; @te = 6 }
      subject.emit(:test)
      expect(subject.tokens.first).to be_token(:test, "hello")
    end
  end

  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 [
        [:dstring, '"hello world"']
      ]

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

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

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

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
liquidscript-0.3.1 spec/lib/liquidscript/scanner/lexer_spec.rb
liquidscript-0.3.0 spec/lib/liquidscript/scanner/lexer_spec.rb
liquidscript-0.2.1 spec/lib/liquidscript/scanner/lexer_spec.rb
liquidscript-0.2.0 spec/lib/liquidscript/scanner/lexer_spec.rb
liquidscript-0.1.5 spec/lib/liquidscript/scanner/lexer_spec.rb
liquidscript-0.1.4 spec/lib/liquidscript/scanner/lexer_spec.rb
liquidscript-0.1.3 spec/lib/liquidscript/scanner/lexer_spec.rb
liquidscript-0.1.2 spec/lib/liquidscript/scanner/lexer_spec.rb
liquidscript-0.1.1 spec/lib/liquidscript/scanner/lexer_spec.rb
liquidscript-0.1.0 spec/lib/liquidscript/scanner/lexer_spec.rb