forked from connamara/quickfixn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_dd_for_dupe_enums.rb
49 lines (38 loc) · 1000 Bytes
/
check_dd_for_dupe_enums.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'rubygems'
require 'nokogiri'
# Script to check issue #114 (duplicate enum values in DDs)
# Shows all enums for which there are dupe values.
# Takes one param: the path to a DD.
# If no params, runs on all DDs in <gitroot>/spec
def hash_has_dupes h
h.each {|k,v| return true if v>1 }
false
end
dds = []
if ARGV.length == 0
dds = Dir.glob("../spec/fix/*xml")
else
dds = Array.new(ARGV)
end
dds.each {|ddfile|
puts "== Processing #{ddfile}"
doc = Nokogiri::XML(open(ddfile))
doc.xpath("//fields//field").each {|f|
field_name = "#{f.attribute("name")}/#{f.attribute("number")}"
enums = f.element_children
if enums.count > 0
h = {}
enums.each {|e|
enumval = e.attribute("enum").value
h[enumval] = 0 unless h.has_key?(enumval)
h[enumval] += 1
}
if hash_has_dupes(h)
puts " * field #{field_name}"
h.each {|k,v|
puts " - #{k}: #{v} times" if v > 1
}
end
end
}
}