-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from localshred/bj/backport_string_field_issues
Backport string field encode fixes from 2.8.x
- Loading branch information
Showing
3 changed files
with
62 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe ::Protobuf::Field::StringField do | ||
|
||
describe '#encode' do | ||
context 'when a repeated string field contains frozen strings' do | ||
it 'does not raise an encoding error' do | ||
expect { | ||
frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] | ||
::Test::ResourceFindRequest.new(:name => 'resource', :widgets => frozen_strings).serialize_to_string | ||
}.not_to raise_error | ||
end | ||
end | ||
|
||
context 'when a repeated bytes field contains frozen strings' do | ||
it 'does not raise an encoding error' do | ||
expect { | ||
frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] | ||
::Test::ResourceFindRequest.new(:name => 'resource', :widget_bytes => frozen_strings).serialize_to_string | ||
}.not_to raise_error | ||
end | ||
end | ||
|
||
it 'does not alter string values after encoding multiple times' do | ||
source_string = "foo" | ||
proto = ::Test::Resource.new(:name => source_string) | ||
proto.serialize_to_string | ||
proto.name.should eq source_string | ||
proto.serialize_to_string | ||
proto.name.should eq source_string | ||
end | ||
|
||
it 'does not alter unicode string values after encoding multiple times' do | ||
source_string = "¢" | ||
proto = ::Test::Resource.new(:name => source_string) | ||
proto.serialize_to_string | ||
proto.name.should eq source_string | ||
proto.serialize_to_string | ||
proto.name.should eq source_string | ||
end | ||
end | ||
|
||
|
||
end |