Sha256: 26b8fee7831a130077e0b276a888953fe8f0d235982aa9e44c8e9fb8cb7b895f

Contents?: true

Size: 827 Bytes

Versions: 1

Compression:

Stored size: 827 Bytes

Contents

RSpec.describe Salt::Language::Scanner do
  let(:input) { %{function main(): int { return 0; } } }
  let(:source) { 'test.sa' }
  subject { described_class.scan(input, source) }

  it 'generates tokens' do
    expect(subject.any?).to be true
    expect(subject.map(&:class).
      all? { |_| _ == Salt::Language::Scanner::Token }).to be true
  end

  it 'properly tokenizes' do
    expect(subject.map(&:to_a)).to eq [
      [:FUNCTION], [:IDENTIFIER, 'main'], [:LPAREN], [:RPAREN],
      [:COLON], [:IDENTIFIER, 'int'],
      [:LBRACE], [:RETURN], [:NUMBER, '0'], [:SEMICOLON], [:RBRACE]
    ]
  end

  it 'adds line and column information' do
    expect(subject.map { |_| [_.line, _.column] }).to eq [
      [1, 0], [1, 9], [1, 13], [1, 14], [1, 15], [1, 17], [1, 21],
      [1, 23], [1, 30], [1, 31], [1, 33]
    ]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
salt-0.0.2 spec/salt/language/scanner_spec.rb