normalizexml 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +59 -0
- data/bin/normalizexml +121 -0
- data/docs/README.CODE.txt +21 -0
- data/lib/normalizexml.rb +58 -0
- data/lib/normalizexml/config.rb +93 -0
- data/lib/normalizexml/controller.rb +83 -0
- data/lib/normalizexml/normalize_xml_task.rb +28 -0
- data/lib/normalizexml/parser.rb +273 -0
- data/lib/normalizexml/version.rb +19 -0
- data/normalizexml.gemspec +30 -0
- data/rakefile.rb +48 -0
- data/spec/data/test.xml +1 -0
- data/spec/data/test2.xml +1 -0
- data/spec/normalize_xml_task_spec.rb +64 -0
- data/spec/parser_spec.rb +145 -0
- data/spec/spec_helper.rb +42 -0
- metadata +183 -0
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NormalizeXml::Parser do
|
4
|
+
|
5
|
+
let(:parser) { NormalizeXml::Parser.new }
|
6
|
+
let(:outdir) { Pathname.new 'tmp/spec/normalizexml.parser' }
|
7
|
+
let(:srcxml) { 'spec/data/test.xml' }
|
8
|
+
let(:srcxml2) { 'spec/data/test2.xml' }
|
9
|
+
|
10
|
+
|
11
|
+
before :each do
|
12
|
+
out = Pathname.new outdir
|
13
|
+
out.rmtree if out.exist? && out.directory?
|
14
|
+
# Parser does NOT create the output directory.
|
15
|
+
out.mkpath
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
let(:outfile) { outdir + 'test.nml.xml' }
|
20
|
+
let(:outfile2) { outdir + 'test2.nml.xml' }
|
21
|
+
|
22
|
+
|
23
|
+
context "#normalize" do
|
24
|
+
|
25
|
+
it "generates an output file" do
|
26
|
+
parser.infile = srcxml
|
27
|
+
parser.outfile = outfile.to_s
|
28
|
+
parser.normalize()
|
29
|
+
|
30
|
+
expect(outfile.exist?).to eq true
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
let(:outputfile1) do
|
36
|
+
parser.infile = srcxml
|
37
|
+
parser.outfile = outfile.to_s
|
38
|
+
parser.normalize()
|
39
|
+
|
40
|
+
outfile
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:outputfile2) do
|
44
|
+
parser.infile = srcxml
|
45
|
+
parser.outfile = outfile2.to_s
|
46
|
+
parser.normalize()
|
47
|
+
|
48
|
+
outfile2
|
49
|
+
end
|
50
|
+
|
51
|
+
context "outputfile" do
|
52
|
+
|
53
|
+
it "starts with an XML declaration statement" do
|
54
|
+
lines = file_to_array(outputfile1)
|
55
|
+
lines[0].should include '<?xml version="1.0"?>'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "contains GuidelineRoot opening and closing tags" do
|
59
|
+
lines = file_to_array(outputfile1)
|
60
|
+
lines[1].should include "<GuidelineRoot>"
|
61
|
+
lines[lines.size - 1].should include "</GuidelineRoot>"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "all IDs are normalized to 0" do
|
65
|
+
lines = file_to_array(outputfile1)
|
66
|
+
lines.each do |line|
|
67
|
+
if line.include?(' Id="')
|
68
|
+
line.should include 'Id="0"'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "AssignTo lines are correctly pretty printed" do
|
74
|
+
lines = file_to_array(outputfile2)
|
75
|
+
lines.each do |line|
|
76
|
+
if line.include?('<AssignTo>')
|
77
|
+
line.should_not include '</AssignTo>'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
context "Order attributes" do
|
84
|
+
|
85
|
+
it "are stripped from Compute elements" do
|
86
|
+
lines = file_to_array(outputfile2)
|
87
|
+
lines.each do |line|
|
88
|
+
if line.include?('<Compute')
|
89
|
+
line.should_not include 'Order='
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "are stripped from AssignTo elements" do
|
95
|
+
lines = file_to_array(outputfile2)
|
96
|
+
lines.each do |line|
|
97
|
+
if line.include?('<AssignTo')
|
98
|
+
line.should_not include 'Order='
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it "are stripped from Message elements" do
|
104
|
+
lines = file_to_array(outputfile2)
|
105
|
+
lines.each do |line|
|
106
|
+
if line.include?('<Message')
|
107
|
+
line.should_not include 'Order='
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end # context "Order attributes"
|
112
|
+
|
113
|
+
|
114
|
+
context "Id attributes" do
|
115
|
+
|
116
|
+
it "are stripped from DPM elements" do
|
117
|
+
lines = file_to_array(outputfile2)
|
118
|
+
lines.each do |line|
|
119
|
+
if line.include?('<DPM')
|
120
|
+
line.should_not include 'Id='
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "are stripped from Ruleset elements" do
|
126
|
+
lines = file_to_array(outputfile2)
|
127
|
+
lines.each do |line|
|
128
|
+
if line.include?('<Ruleset')
|
129
|
+
line.should_not include 'Id='
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it "are stripped from Rule elements" do
|
135
|
+
lines = file_to_array(outputfile2)
|
136
|
+
lines.each do |line|
|
137
|
+
if line.include?('<Rule')
|
138
|
+
line.should_not include 'Id='
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end # context "Order attributes"
|
143
|
+
end # context "outputfile"
|
144
|
+
end # context "#normalize"
|
145
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
config.filter_run :focus
|
10
|
+
|
11
|
+
# Run specs in random order to surface order dependencies. If you find an
|
12
|
+
# order dependency and want to debug it, you can fix the order by providing
|
13
|
+
# the seed, which is printed after each run.
|
14
|
+
# --seed 1234
|
15
|
+
config.order = 'random'
|
16
|
+
|
17
|
+
# Enable both 'should' and 'expect' syntax
|
18
|
+
config.expect_with :rspec do |c|
|
19
|
+
# Disable the `expect` sytax...
|
20
|
+
#c.syntax = :should
|
21
|
+
|
22
|
+
# ...or disable the `should` syntax...
|
23
|
+
#c.syntax = :expect
|
24
|
+
|
25
|
+
# ...or explicitly enable both
|
26
|
+
c.syntax = [:should, :expect]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
require_relative '../lib/normalizexml'
|
33
|
+
require 'pathname'
|
34
|
+
|
35
|
+
def file_to_array(filepath)
|
36
|
+
dump = []
|
37
|
+
File.open(filepath) do |f|
|
38
|
+
f.each_line {|line| dump << line}
|
39
|
+
end
|
40
|
+
dump
|
41
|
+
end
|
42
|
+
|
metadata
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: normalizexml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff McAffee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-mocks
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: nokogiri
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: ktcommon
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: user-choices
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: NormalizeXml is a utility to normalize XML files for easy comparison.
|
126
|
+
email:
|
127
|
+
- jeff@ktechsystems.com
|
128
|
+
executables:
|
129
|
+
- normalizexml
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE
|
137
|
+
- README.md
|
138
|
+
- bin/normalizexml
|
139
|
+
- docs/README.CODE.txt
|
140
|
+
- lib/normalizexml.rb
|
141
|
+
- lib/normalizexml/config.rb
|
142
|
+
- lib/normalizexml/controller.rb
|
143
|
+
- lib/normalizexml/normalize_xml_task.rb
|
144
|
+
- lib/normalizexml/parser.rb
|
145
|
+
- lib/normalizexml/version.rb
|
146
|
+
- normalizexml.gemspec
|
147
|
+
- rakefile.rb
|
148
|
+
- spec/data/test.xml
|
149
|
+
- spec/data/test2.xml
|
150
|
+
- spec/normalize_xml_task_spec.rb
|
151
|
+
- spec/parser_spec.rb
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
homepage: https://github.com/jmcaffee/normalizexml
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.3.0
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: Normalize XML files for easy comparison
|
177
|
+
test_files:
|
178
|
+
- spec/data/test.xml
|
179
|
+
- spec/data/test2.xml
|
180
|
+
- spec/normalize_xml_task_spec.rb
|
181
|
+
- spec/parser_spec.rb
|
182
|
+
- spec/spec_helper.rb
|
183
|
+
has_rdoc:
|