Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
thallgren committed Jun 14, 2017
2 parents 1d7275f + 9fb6464 commit a28822e
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/pops/loader/static_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def create_resource_type_references()
end

def add_type(name, type)
set_entry(TypedName.new(:type, name.downcase), type)
set_entry(TypedName.new(:type, name), type)
type
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/pops/loader/type_definition_instantiator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def self.create(loader, typed_name, source_ref, pp_code_string)
end

def self.create_from_model(type_definition, loader)
typed_name = TypedName.new(:type, type_definition.name.downcase)
typed_name = TypedName.new(:type, type_definition.name)
type = create_runtime_type(type_definition)
loader.set_entry(
typed_name,
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/pops/loader/typed_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TypedName
attr_reader :compound_name

def initialize(type, name, name_authority = Pcore::RUNTIME_NAME_AUTHORITY)
name = name.downcase
@type = type
@name_authority = name_authority
# relativize the name (get rid of leading ::), and make the split string available
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/pops/loaders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def self.register_static_implementations(obj_classes)
def self.register_implementations_with_loader(obj_classes, name_authority, loader)
types = obj_classes.map do |obj_class|
type = obj_class._pcore_type
typed_name = Loader::TypedName.new(:type, type.name.downcase, name_authority)
typed_name = Loader::TypedName.new(:type, type.name, name_authority)
entry = loader.loaded_entry(typed_name)
loader.set_entry(typed_name, type) if entry.nil? || entry.value.nil?
type
Expand All @@ -129,7 +129,7 @@ def self.register_runtime3_type(name, origin)

name = name.to_s
caps_name = Types::TypeFormatter.singleton.capitalize_segments(name)
typed_name = Loader::TypedName.new(:type, name.downcase)
typed_name = Loader::TypedName.new(:type, name)
rt3_loader.set_entry(typed_name, Types::PResourceType.new(caps_name), origin)
nil
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/pops/pcore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def self.add_alias(name, type, loader, name_authority = RUNTIME_NAME_AUTHORITY)
end

def self.add_type(type, loader, name_authority = RUNTIME_NAME_AUTHORITY)
loader.set_entry(Loader::TypedName.new(:type, type.name.downcase, name_authority), type)
loader.set_entry(Loader::TypedName.new(:type, type.name, name_authority), type)
type
end

Expand All @@ -97,7 +97,7 @@ def self.register_aliases(aliases, name_authority = RUNTIME_NAME_AUTHORITY, load
add_type(Types::PTypeAliasType.new(name, Types::TypeFactory.type_reference(type_string), nil), loader, name_authority)
end
parser = Types::TypeParser.singleton
aliases.each_key.map { |name| loader.load(:type, name.downcase).resolve(parser, loader) }
aliases.each_key.map { |name| loader.load(:type, name).resolve(parser, loader) }
end
end
end
11 changes: 7 additions & 4 deletions lib/puppet/pops/serialization/deserializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ def read
result = type.read(val.attribute_count, self)
if result.is_a?(Types::PObjectType)
existing_type = loader.load(:type, result.name)

# Add result to the loader unless it is the exact same instance as the existing_type. The add
# will succeed when the existing_type is nil.
loader.add_entry(:type, result.name, result, nil) unless result.equal?(existing_type)
if result.eql?(existing_type)
result = existing_type
else
# Add result to the loader unless it is equal to the existing_type. The add
# will only succeed when the existing_type is nil.
loader.add_entry(:type, result.name, result, nil)
end
end
result
when Extension::ObjectStart
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/pops/types/p_type_set_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def resolve_literal_hash(type_parser, loader, init_hash_expression)
if types.is_a?(Hash)
types.each do |type_name, value|
full_name = "#{@name}::#{type_name}".freeze
typed_name = Loader::TypedName.new(:type, full_name.downcase, name_auth)
typed_name = Loader::TypedName.new(:type, full_name, name_auth)
type = Loader::TypeDefinitionInstantiator.create_type(full_name, value, name_auth)
loader.set_entry(typed_name, type, value.locator.to_uri(value))
types[type_name] = type
Expand All @@ -308,7 +308,7 @@ def resolve_hash(type_parser, loader, init_hash)
if types.is_a?(Hash)
types.each do |type_name, value|
full_name = "#{@name}::#{type_name}".freeze
typed_name = Loader::TypedName.new(:type, full_name.downcase, name_auth)
typed_name = Loader::TypedName.new(:type, full_name, name_auth)
meta_name = value.is_a?(Hash) ? 'Object' : 'TypeAlias'
type = Loader::TypeDefinitionInstantiator.create_named_type(full_name, meta_name, value, name_auth)
loader.set_entry(typed_name, type)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/pops/types/type_set_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _pcore_init_hash
end

def resolve(type_parser, loader)
typed_name = Loader::TypedName.new(:type, @name.downcase, @name_authority)
typed_name = Loader::TypedName.new(:type, @name, @name_authority)
loaded_entry = loader.load_typed(typed_name)
type_set = loaded_entry.nil? ? nil : loaded_entry.value

Expand Down
9 changes: 4 additions & 5 deletions lib/puppet/util/character_encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ def override_encoding_to_utf_8(string)
}

# Given a string, return a copy of that string with any invalid byte
# sequences in its current encoding replaced with "?". We use "?" to make
# sure our output is consistent across ruby versions and encodings, and
# because calling scrub on a non-UTF8 string with the unicode replacement
# character "\uFFFD" results in an Encoding::CompatibilityError.
# sequences in its current encoding replaced with the replacement character
# "\uFFFD" (UTF-8) if the string is UTF-8 or UTF-16LE, or "?" otherwise.
# @param string a string to remove invalid byte sequences from
# @return a copy of string invalid byte sequences replaced by "?" character
# @return a copy of string invalid byte sequences replaced by the unicode
# replacement character or "?" character
# @note does not modify encoding, but new string will have different bytes
# from original. Only needed for ruby 1.9.3 support.
def scrub(string)
Expand Down
10 changes: 10 additions & 0 deletions spec/unit/pops/loaders/loaders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
expect(tn.name).to eq('foo::bar')
expect(tn.qualified?).to be_truthy
end

it 'TypedName converts name to lower case' do
tn = Puppet::Pops::Loader::TypedName.new(:type, '::Foo::Bar')
expect(tn.name_parts).to eq(['foo', 'bar'])
expect(tn.name).to eq('foo::bar')
end

it 'TypedName is case insensitive' do
expect(Puppet::Pops::Loader::TypedName.new(:type, '::Foo::Bar')).to eq(Puppet::Pops::Loader::TypedName.new(:type, '::foo::bar'))
end
end

describe 'loaders' do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/pops/types/p_object_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Types

def type_object_t(name, body_string)
object = PObjectType.new(name, pp_parser.parse_string("{#{body_string}}").body)
loader.set_entry(Loader::TypedName.new(:type, name.downcase), object)
loader.set_entry(Loader::TypedName.new(:type, name), object)
object
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/pops/types/p_type_set_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Types
def type_set_t(name, body_string, name_authority)
i12n_literal_hash = pp_parser.parse_string("{#{body_string}}").body
typeset = PTypeSetType.new(name, i12n_literal_hash, name_authority)
loader.set_entry(Loader::TypedName.new(:type, name.downcase, name_authority), typeset)
loader.set_entry(Loader::TypedName.new(:type, name, name_authority), typeset)
typeset
end

Expand Down

0 comments on commit a28822e

Please sign in to comment.