33 examples, 1 failures

This commit is contained in:
Netscape Navigator 2020-05-21 07:50:02 -05:00
parent 3f83404e40
commit 526bfa056c
8 changed files with 51 additions and 32 deletions

View File

@ -1,9 +1,9 @@
author @PZ1R38E146JX8H6ZMQ6F2EFA2FSCGX7BEF2W79S665Z9NT2VYNKG.ed25519
kind nonsense
prev NONE
author @YDVX7JWTVNRFEVYC8E8DS9MVWW9KB66F1XQYMNB2FQ6QBPXKAQX0.ed25519
depth 0
kind nonsense
lipmaa NONE
prev NONE
example:"Just block me"
signature HG1PCKWXN5FCSC6B3VK732YAAPGPMBVZXJ2HVE7HGA0W4TBNCS8JZVQ54MXM4GHFACNYBC6PC0FQ13YQTTK36SH0ZZ1BBEX3VNYHW00.sig.ed25519
signature CJ431HNC4D745WQ5X5JME9G88SKGZSQ6KHVHERBTC56V1VBSTGWHV5GYP1T8Y14V4HVA98S61KDC7X7ZBAYD47RK7KBFV44VQ8N8E2G.sig.ed25519

View File

@ -40,9 +40,9 @@ RSpec.describe Pigeon::Message do
it "does not ingest messages from blocked peers" do
db.reset_database
antagonist = "@PZ1R38E146JX8H6ZMQ6F2EFA2FSCGX7BEF2W79S665Z9NT2VYNKG.ed25519"
antagonist = "@YDVX7JWTVNRFEVYC8E8DS9MVWW9KB66F1XQYMNB2FQ6QBPXKAQX0.ed25519"
db.block_peer(antagonist)
db.import_bundle("./spec/fixtures/x")
db.import_bundle(BLOCKED_PEER_FIXTURE_PATH)
expect(db.all_messages.count).to eq(0)
end
@ -53,7 +53,7 @@ RSpec.describe Pigeon::Message do
"&FV0FJ0YZADY7C5JTTFYPKDBHTZJ5JVVP5TCKP0605WWXYJG4VMRG.sha256",
"&YPF11E5N9JFVB6KB1N1WDVVT9DXMCHE0XJWBZHT2CQ29S5SEPCSG.sha256",
]
db.import_bundle("./spec/fixtures/has_blobs")
db.import_bundle(HAS_BLOB_PATH)
expect(db.all_messages.count).to eq(3)
blobs.map do |h|
expect(db.have_blob?(h)).to be true

View File

@ -18,10 +18,10 @@ RSpec.describe Pigeon::Draft do
MSG = [
"author DRAFT",
"kind unit_test",
"prev DRAFT",
"depth DRAFT",
"kind unit_test",
"lipmaa DRAFT",
"prev DRAFT",
"\na:\"bar\"",
"b:&CHHABX8Q9D9Q0BY2BBZ6FA7SMAFNE9GGMSDTZVZZC9TK2N9F15QG.sha256",
"\n",

View File

@ -1,7 +1,6 @@
require "spec_helper"
RSpec.describe Pigeon::Lexer do
NORMAL_PATH = "./spec/fixtures/normal/"
EXPECTED_TOKENS1 = [
[:AUTHOR, "@3DWXGXHXCB02WV1TEA47J43HHTTBNMM496ANME7FZ2SYPGA9KTZG.ed25519", 69],
[:DEPTH, 0, 77],
@ -60,18 +59,6 @@ RSpec.describe Pigeon::Lexer do
db.publish_draft
end
def regenerate_examples
db.add_message("unit_test1", { "foo" => "bar" })
db.add_message("unit_test2", { "bar" => "baz" })
db.add_message("unit_test3", { "cats" => "meow" })
db.export_bundle(NORMAL_PATH)
full_path = NORMAL_PATH + Pigeon::MESSAGE_FILE
bundle = File.read(full_path)
tokens = Pigeon::Lexer.tokenize(bundle)
puts "=== CHANGE THE TOP VALUE TO THIS ==="
puts "EXPECTED_TOKENS1 = #{tokens.inspect}"
end
it "tokenizes a bundle" do
bundle = File.read(NORMAL_PATH + Pigeon::MESSAGE_FILE)
tokens = Pigeon::Lexer.tokenize(bundle)

View File

@ -47,10 +47,10 @@ RSpec.describe Pigeon::Message do
actual = message.render
expected = [
"author __AUTHOR__",
"kind unit_test",
"prev NONE",
"depth 0",
"kind unit_test",
"lipmaa NONE",
"prev NONE",
"",
"a:\"bar\"",
"b:&CHHABX8Q9D9Q0BY2BBZ6FA7SMAFNE9GGMSDTZVZZC9TK2N9F15QG.sha256",

View File

@ -24,14 +24,14 @@ RSpec.describe Pigeon::Lexer do
it "parses tokens" do
results = Pigeon::Parser.parse(db, tokens)
expect(results.length).to eq(10)
expect(results.length).to eq(3)
expect(results.first).to be_kind_of(Pigeon::Message)
expect(results.last).to be_kind_of(Pigeon::Message)
end
it "ingests and reconstructs a bundle" do
messages = db.import_bundle("./spec/fixtures/normal")
expect(messages.length).to eq(10)
expect(messages.length).to eq(3)
expect(messages.map(&:class).uniq).to eq([Pigeon::Message])
re_bundled = messages.map(&:render).join("\n\n") + "\n"
expect(re_bundled).to eq(example_bundle)

View File

@ -3,12 +3,14 @@ require "spec_helper"
RSpec.describe Pigeon::MessageSerializer do
SHIM_ATTRS = %i[author body kind depth prev signature lipmaa].freeze
MessageShim = Struct.new(*SHIM_ATTRS)
TOP_HALF = ["author FAKE_AUTHOR",
"\nkind FAKE_KIND",
"\nprev NONE",
"\ndepth 23",
"\nlipmaa 22",
"\n\nfoo:\"bar\"\n\n"].join("")
TOP_HALF = [
"author FAKE_AUTHOR",
"\ndepth 23",
"\nkind FAKE_KIND",
"\nlipmaa 22",
"\nprev NONE",
"\n\nfoo:\"bar\"\n\n",
].join("")
BOTTOM_HALF = "signature XYZ.sig.sha256"
EXPECTED_DRAFT = TOP_HALF + BOTTOM_HALF

View File

@ -1,5 +1,35 @@
require "pry"
require "simplecov"
NORMAL_PATH = "./spec/fixtures/normal/"
HAS_BLOB_PATH = "./spec/fixtures/has_blobs"
BLOCKED_PEER_FIXTURE_PATH = "./spec/fixtures/x"
def regenerate_fixture_normal_path(db)
db.add_message("unit_test1", { "foo" => "bar" })
db.add_message("unit_test2", { "bar" => "baz" })
db.add_message("unit_test3", { "cats" => "meow" })
db.export_bundle(NORMAL_PATH)
full_path = NORMAL_PATH + Pigeon::MESSAGE_FILE
bundle = File.read(full_path)
tokens = Pigeon::Lexer.tokenize(bundle)
puts "=== CHANGE THE TOP VALUE TO THIS ==="
puts "EXPECTED_TOKENS1 = #{tokens.inspect}"
end
def regenerate_fixture_has_blobs(db)
db.reset_database
blobs = %w(./a.gif ./b.gif ./c.gif)
.map { |x| File.read(x) }
.map { |x| db.add_blob(x) }
.map { |x| db.add_message("example", { "file_name" => x }) }
db.export_bundle(HAS_BLOB_PATH)
end
def regenerate_fixture_x(db)
db.reset_database
db.add_message("nonsense", { "example" => "Just block me" })
db.export_bundle(BLOCKED_PEER_FIXTURE_PATH)
end
SimpleCov.start
require_relative File.join("..", "lib", "pigeon")