shard-ameba/spec/ameba/tokenizer_spec.cr

45 lines
1.3 KiB
Crystal
Raw Normal View History

2017-11-04 14:43:40 +00:00
require "../spec_helper"
2017-11-04 15:38:04 +00:00
module Ameba
private def it_tokenizes(str, expected)
it "tokenizes #{str}" do
([] of Symbol).tap do |token_types|
Tokenizer.new(Source.new str)
.run { |token| token_types << token.type }
.should be_true
end.should eq expected
end
2017-11-04 14:43:40 +00:00
end
describe Tokenizer do
describe "#run" do
2017-11-04 15:38:04 +00:00
it_tokenizes %("string"), %i(DELIMITER_START STRING DELIMITER_END EOF)
it_tokenizes %(100), %i(NUMBER EOF)
it_tokenizes %('a'), %i(CHAR EOF)
it_tokenizes %([]), %i([] EOF)
it_tokenizes %([] of String), %i([] SPACE IDENT SPACE CONST EOF)
it_tokenizes %q("str #{3}"), %i(
DELIMITER_START STRING INTERPOLATION_START NUMBER } DELIMITER_END EOF
)
2017-11-04 14:43:40 +00:00
it_tokenizes %(%w(1 2)),
2017-11-04 15:38:04 +00:00
%i(STRING_ARRAY_START STRING STRING STRING_ARRAY_END EOF)
2017-11-04 14:43:40 +00:00
it_tokenizes %(%i(one two)),
2017-11-04 15:38:04 +00:00
%i(SYMBOL_ARRAY_START STRING STRING STRING_ARRAY_END EOF)
2017-11-04 14:43:40 +00:00
it_tokenizes %(
2017-11-04 15:38:04 +00:00
class A
def method
puts "hello"
end
2017-11-04 14:43:40 +00:00
end
2017-11-04 15:38:04 +00:00
), %i(
NEWLINE SPACE IDENT SPACE CONST NEWLINE SPACE IDENT SPACE IDENT
NEWLINE SPACE IDENT SPACE DELIMITER_START STRING DELIMITER_END
NEWLINE SPACE IDENT NEWLINE SPACE IDENT NEWLINE SPACE EOF
)
2017-11-04 14:43:40 +00:00
end
end
end