From 526bfa056c7436d432ca3e1c1b47efe40ec00393 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Thu, 21 May 2020 07:50:02 -0500 Subject: [PATCH] 33 examples, 1 failures --- spec/fixtures/x/messages.pgn | 8 ++++---- spec/pigeon/bundle_spec.rb | 6 +++--- spec/pigeon/draft_spec.rb | 4 ++-- spec/pigeon/lexer_spec.rb | 13 ------------- spec/pigeon/message_spec.rb | 4 ++-- spec/pigeon/parser_spec.rb | 4 ++-- spec/pigeon/template_spec.rb | 14 ++++++++------ spec/spec_helper.rb | 30 ++++++++++++++++++++++++++++++ 8 files changed, 51 insertions(+), 32 deletions(-) diff --git a/spec/fixtures/x/messages.pgn b/spec/fixtures/x/messages.pgn index 9082f63..266e207 100644 --- a/spec/fixtures/x/messages.pgn +++ b/spec/fixtures/x/messages.pgn @@ -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 diff --git a/spec/pigeon/bundle_spec.rb b/spec/pigeon/bundle_spec.rb index 45e684e..91ece1c 100644 --- a/spec/pigeon/bundle_spec.rb +++ b/spec/pigeon/bundle_spec.rb @@ -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 diff --git a/spec/pigeon/draft_spec.rb b/spec/pigeon/draft_spec.rb index 3b813b8..0baa6e6 100644 --- a/spec/pigeon/draft_spec.rb +++ b/spec/pigeon/draft_spec.rb @@ -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", diff --git a/spec/pigeon/lexer_spec.rb b/spec/pigeon/lexer_spec.rb index e3061d1..d178a61 100644 --- a/spec/pigeon/lexer_spec.rb +++ b/spec/pigeon/lexer_spec.rb @@ -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) diff --git a/spec/pigeon/message_spec.rb b/spec/pigeon/message_spec.rb index b69e7aa..52a0dd0 100644 --- a/spec/pigeon/message_spec.rb +++ b/spec/pigeon/message_spec.rb @@ -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", diff --git a/spec/pigeon/parser_spec.rb b/spec/pigeon/parser_spec.rb index 065b7f5..060ad6e 100644 --- a/spec/pigeon/parser_spec.rb +++ b/spec/pigeon/parser_spec.rb @@ -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) diff --git a/spec/pigeon/template_spec.rb b/spec/pigeon/template_spec.rb index c661539..ddc892e 100644 --- a/spec/pigeon/template_spec.rb +++ b/spec/pigeon/template_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bdaeaa9..2a73abc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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")