From 45de11cb3b6281497354b024ad2e2ec19f22327d Mon Sep 17 00:00:00 2001 From: Guillaume DOTT Date: Fri, 6 Sep 2013 11:15:27 +0200 Subject: [PATCH] Add tests for GSM7Bit --- spec/biju/pdu/gsm7bit_spec.rb | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 spec/biju/pdu/gsm7bit_spec.rb diff --git a/spec/biju/pdu/gsm7bit_spec.rb b/spec/biju/pdu/gsm7bit_spec.rb new file mode 100644 index 0000000..d10eaa5 --- /dev/null +++ b/spec/biju/pdu/gsm7bit_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' +require 'biju/pdu/gsm7bit' + +describe Biju::PDU::GSM7Bit do + describe '::decode' do + it "decodes string" do + expect(Biju::PDU::GSM7Bit.decode('D4F29C0E', length: 4)).to eq('Test') + end + + it "decodes character from extension set" do + expect(Biju::PDU::GSM7Bit.decode('9B32', length: 1)).to eq('€') + end + + it "decodes character with a length of 7" do + expect(Biju::PDU::GSM7Bit.decode('E170381C0E8701', length: 7)).to eq('a' * 7) + end + end + + describe '::encode' do + it "encodes string" do + expect(Biju::PDU::GSM7Bit.encode('Test').upcase).to eq('D4F29C0E') + end + + it "encodes character from extension set" do + expect(Biju::PDU::GSM7Bit.encode('€').upcase).to eq('9B32') + end + + it "encodes character with a length of 7" do + expect(Biju::PDU::GSM7Bit.encode('a' * 7).upcase).to eq('E170381C0E8701') + end + end + + it "gives same text after encoding and decoding" do + strings = [ + 'My first TEST', + '{More complicated]', + 'And on€ More~', + 'a' * 7, + ] + + strings.each do |string| + expect(Biju::PDU::GSM7Bit.decode( + Biju::PDU::GSM7Bit.encode(string), length: string.length)).to eq(string) + end + end +end