Skip to content

Commit b0f163f

Browse files
Fixed typo in mip (spurious character after name:) and fixed $copy path from mie to mip description to accomodate new schema change.
1 parent 7eb44b7 commit b0f163f

File tree

4 files changed

+12
-80
lines changed

4 files changed

+12
-80
lines changed

arch/csr/mie.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ address: 0x304
88
priv_mode: M
99
length: MXLEN
1010
definedBy: Sm
11-
description: "$copy: mip.yaml#/mip/description"
11+
description: "$copy: mip.yaml#/description"
1212
fields:
1313
SSIE:
1414
location: 1

arch/csr/mip.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
$schema: "csr_schema.json#"
44
kind: csr
5-
name: mip>
5+
name: mip
66
long_name: Machine Interrupt Pending
77
address: 0x344
88
priv_mode: M

lib/test/test_yaml_loader.rb

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -208,74 +208,6 @@ def test_that_double_inherits_doesnt_delete_keys
208208
assert_equal({ "key1" => "value1", "key2" => "value2", "key3" => "value3_new", "key4" => "value4", "key5" => "value5", "key6" => "value6_new" }, doc["child"])
209209
end
210210

211-
# Removed by @dhower-qc in https://github.com/riscv-software-src/riscv-unified-db/commit/7d10d70f122de6263ce7907dee8daeddc0a0af40
212-
# Waiting for response in https://github.com/riscv-software-src/riscv-unified-db/pull/271
213-
#
214-
# def test_refs_in_the_same_document
215-
# yaml = <<~YAML
216-
# $defs:
217-
# target1: A string
218-
# target2:
219-
# a: hash
220-
#
221-
# obj1:
222-
# $ref: "#/$defs/target2"
223-
#
224-
# obj2:
225-
# $ref: "#/$defs/target2"
226-
# target2: Should disappear
227-
#
228-
# obj3:
229-
# target2: Should disappear
230-
# $ref: "#/$defs/target2"
231-
# YAML
232-
#
233-
# f = Tempfile.new("yml")
234-
# f.write(yaml)
235-
# f.flush
236-
#
237-
# doc = YamlLoader.load(f.path)
238-
# assert_equal({ "a" => "hash" }, doc["obj1"])
239-
# assert_equal({ "a" => "hash" }, doc["obj2"])
240-
# assert_equal({ "a" => "hash" }, doc["obj3"])
241-
# end
242-
#
243-
# def test_refs_in_the_different_document
244-
# yaml1 = <<~YAML
245-
# $defs:
246-
# target1: A string
247-
# target2:
248-
# a: hash
249-
# YAML
250-
#
251-
# f1 = Tempfile.new("yml")
252-
# f1.write(yaml1)
253-
# f1.flush
254-
# f1_path = Pathname.new(f1.path)
255-
#
256-
# yaml2 = <<~YAML
257-
# obj1:
258-
# $ref: "#{f1_path.basename}#/$defs/target2"
259-
#
260-
# obj2:
261-
# $ref: "#{f1_path.basename}#/$defs/target2"
262-
# target2: Should disappear
263-
#
264-
# obj3:
265-
# target2: Should disappear
266-
# $ref: "#{f1_path.basename}#/$defs/target2"
267-
# YAML
268-
#
269-
# f2 = Tempfile.new("yml")
270-
# f2.write(yaml2)
271-
# f2.flush
272-
#
273-
# doc = YamlLoader.load(f2.path)
274-
# assert_equal({ "a" => "hash" }, doc["obj1"])
275-
# assert_equal({ "a" => "hash" }, doc["obj2"])
276-
# assert_equal({ "a" => "hash" }, doc["obj3"])
277-
# end
278-
279211
def test_inherits_in_the_same_document
280212
yaml = <<~YAML
281213
$defs:

lib/yaml_loader.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def self.expand(filename, obj, yaml_opts = {})
142142
obj[key] =
143143
if value.is_a?(String) && value.start_with?("$copy:")
144144
copy_target = value.delete_prefix("$copy:").lstrip
145-
self.get_ref_target_obj(filename, copy_target, yaml_opts)
145+
self.get_copy_target_obj(filename, copy_target, yaml_opts)
146146
else
147147
expand(filename, value, yaml_opts)
148148
end
@@ -162,35 +162,35 @@ def self.expand(filename, obj, yaml_opts = {})
162162
end
163163

164164
# @param filename [String,Pathname] path to the YAML file
165-
# @param ref_target [String]
165+
# @param copy_target [String]
166166
# @param yaml_opts [Hash] options to pass to YAML.load_file
167167
# @return [Object]
168-
def self.get_ref_target_obj(filename, ref_target, yaml_opts)
169-
relative_path = ref_target.split("#")[0]
168+
def self.get_copy_target_obj(filename, copy_target, yaml_opts)
169+
relative_path = copy_target.split("#")[0]
170170
if relative_path.empty?
171171
# this is a reference in the same document
172172
obj_doc = YAML.load_file(filename, **yaml_opts)
173-
obj_path = ref_target.split("#")[1].split("/")[1..]
173+
obj_path = copy_target.split("#")[1].split("/")[1..]
174174
target_obj = obj_doc.dig(*obj_path)
175-
raise DereferenceError, "$ref: #{obj_path} cannot be found in file #{filename}" if target_obj.nil?
175+
raise DereferenceError, "$copy: #{obj_path} referenced to same file cannot be found in file #{filename}" if target_obj.nil?
176176

177177
ref = expand(filename, target_obj, yaml_opts)
178178
if ref.nil?
179-
raise DereferenceError, "JSON Path #{obj_path} does not exist in file #{filename}"
179+
raise DereferenceError, "$copy: JSON Path #{obj_path} referenced to same file does not exist in file #{filename}"
180180
end
181181

182182
ref
183183
else
184184
target_filename = File.realpath(File.join(filename.dirname, relative_path))
185185

186186
obj_doc = YamlLoader.load(target_filename, yaml_opts)
187-
obj_path = ref_target.split("#")[1].split("/")[1..]
187+
obj_path = copy_target.split("#")[1].split("/")[1..]
188188
target_obj = obj_doc.dig(*obj_path)
189-
raise "$ref: #{obj_path} cannot be found in file #{target_filename}" if target_obj.nil?
189+
raise DereferenceError, "$copy: #{obj_path} referenced from file #{filename} cannot be found in file #{target_filename}" if target_obj.nil?
190190

191191
ref = expand(target_filename, target_obj, yaml_opts)
192192
if ref.nil?
193-
raise DereferenceError, "JSON Path #{obj_path} does not exist in file #{target_filename}"
193+
raise DereferenceError, "$copy: JSON Path #{obj_path} referenced from file #{filename} does not exist in file #{target_filename}"
194194
end
195195

196196
ref

0 commit comments

Comments
 (0)