Finish tests for Pigeon::Lexer 💯 ✔️
This commit is contained in:
parent
3982406014
commit
8d9deb90af
|
@ -30,6 +30,8 @@ module Pigeon
|
|||
|
||||
LEXER_STATES = [HEADER = :header, BODY = :body, FOOTER = :footer]
|
||||
|
||||
class LexError < StandardError; end
|
||||
|
||||
def self.tokenize(bundle_string)
|
||||
# TODO: Maybe move #tokeinze into constructor.
|
||||
new(bundle_string).tokenize
|
||||
|
@ -57,7 +59,7 @@ module Pigeon
|
|||
end
|
||||
|
||||
def flunk!
|
||||
raise "Syntax error at #{scanner.pos}"
|
||||
raise LexError, "Syntax error at #{scanner.pos}"
|
||||
end
|
||||
|
||||
# This might be a mistake or uneccessary. NN 20 MAR 2020
|
||||
|
@ -133,7 +135,7 @@ module Pigeon
|
|||
return
|
||||
end
|
||||
|
||||
raise "Parse error at #{scanner.pos}. Double carriage return not found."
|
||||
raise LexError, "Parse error at #{scanner.pos}. Double carriage return not found."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
module Pigeon
|
||||
class Parser
|
||||
def self.parse(tokens)
|
||||
raise "WIP"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -27,11 +27,20 @@ RSpec.describe Pigeon::Lexer do
|
|||
[:MESSAGE_END],
|
||||
]
|
||||
|
||||
MESSAGE_LINES = [
|
||||
"author @WEf06RUKouNcEVURslzHvepOiK4WbQAgRc_9aiUy7rE=.ed25519",
|
||||
"kind unit_test",
|
||||
"prev NONE",
|
||||
"depth 0",
|
||||
"",
|
||||
"foo:\"bar\"",
|
||||
"",
|
||||
"signature hHvhdvUcrabhFPz52GSGa9_iuudOsGEEE7S0o0WJLqjQyhLfgUy72yppHXsG6T4E21p6EEI6B3yRcjfurxegCA==.sig.ed25519",
|
||||
].freeze
|
||||
|
||||
let(:message) do
|
||||
draft = Pigeon::Draft.create(kind: "unit_test")
|
||||
hash = Pigeon::Storage.current.set_blob(File.read("./logo.png"))
|
||||
draft["a"] = "bar"
|
||||
draft["b"] = hash
|
||||
draft["foo"] = "bar"
|
||||
Pigeon::Message.publish(draft)
|
||||
end
|
||||
|
||||
|
@ -70,4 +79,15 @@ RSpec.describe Pigeon::Lexer do
|
|||
expect(hash[:PREV]).to eq Pigeon::EMPTY_MESSAGE
|
||||
expect(hash[:SIGNATURE]).to eq(message.signature)
|
||||
end
|
||||
|
||||
it "catches syntax errors" do
|
||||
e = Pigeon::Lexer::LexError
|
||||
[
|
||||
MESSAGE_LINES.dup.insert(3, "@@@").join("\n"),
|
||||
MESSAGE_LINES.dup.insert(5, "@@@").join("\n"),
|
||||
MESSAGE_LINES.dup.insert(7, "@@@").join("\n"),
|
||||
].map do |bundle|
|
||||
expect { Pigeon::Lexer.tokenize(bundle) }.to raise_error(e)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue