mirror of
https://gitea.invidious.io/iv-org/protodec.git
synced 2024-08-15 00:43:18 +00:00
Add specs
This commit is contained in:
parent
174a36f4ad
commit
a7f2c4fbea
5 changed files with 520 additions and 233 deletions
29
spec/protodec_spec.cr
Normal file
29
spec/protodec_spec.cr
Normal file
|
@ -0,0 +1,29 @@
|
|||
require "./spec_helper"
|
||||
|
||||
describe Protodec do
|
||||
it "decodes Base64 data" do
|
||||
input = "4qmFsgIrEhhVQ0NqOTU2SUY2MkZiVDdHb3VzemFqOXcaD0VnbGpiMjF0ZFc1cGRIaw"
|
||||
output = input.strip
|
||||
.try { |i| URI.decode_www_form(i) }
|
||||
.try { |i| URI.decode_www_form(i) }
|
||||
.try { |i| Base64.decode(i) }
|
||||
.try { |i| IO::Memory.new(i) }
|
||||
.try { |i| Protodec::Any.parse(i) }
|
||||
|
||||
output["80226972:0:embedded"]["2:0:string"].should eq("UCCj956IF62FbT7Gouszaj9w")
|
||||
output["80226972:0:embedded"]["3:1:base64"]["2:0:string"].should eq("community")
|
||||
end
|
||||
|
||||
it "encodes JSON object" do
|
||||
object = Protodec::Any.cast_json({
|
||||
"80226972:0:embedded" => {
|
||||
"2:0:string" => "UCCj956IF62FbT7Gouszaj9w",
|
||||
"3:1:base64" => {
|
||||
"2:0:string" => "community",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Base64.urlsafe_encode(Protodec::Any.from_json(object), padding: false).should eq("4qmFsgIrEhhVQ0NqOTU2SUY2MkZiVDdHb3VzemFqOXcaD0VnbGpiMjF0ZFc1cGRIaw")
|
||||
end
|
||||
end
|
2
spec/spec_helper.cr
Normal file
2
spec/spec_helper.cr
Normal file
|
@ -0,0 +1,2 @@
|
|||
require "spec"
|
||||
require "../src/protodec/utils"
|
Loading…
Add table
Add a link
Reference in a new issue