mbt-gen 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mbt-gen.rb +153 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 20bf8b787d83e3b2b6944c56c94054da7f42bd5c587bd4dd78486a2aec1acf12
|
|
4
|
+
data.tar.gz: 055a0a05ac4556b952c6746f2bf987b440b80f111f0714883958193be4254966
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c58c06320fda5aa5944b17ac9e1507f1d65ffe93810bb7c0fcb158e6e1ddb273b98ab3a47afbdbf41b9230fdf0bc2deb8a2b6b04e78bdd413e9a9876e82b40fc
|
|
7
|
+
data.tar.gz: 884f6ef5c8f134cfe401a5a46e28b92599ee86ae46adfc7ad8d30bdc1c5e1d47299ffc177774b03b230c29a63ae605196a0e551c0ad4bcebc9aae4ecee5990dd
|
data/lib/mbt-gen.rb
CHANGED
|
@@ -1029,6 +1029,10 @@ def xpath_to_filename(xpath)
|
|
|
1029
1029
|
xpath.gsub("/", "-").gsub(/\[\d*\]/) {|s| if s =~ /\[(\d*)\]/ then "-#{$1}-" else s end }
|
|
1030
1030
|
end
|
|
1031
1031
|
|
|
1032
|
+
def xpath_to_methodname(xpath)
|
|
1033
|
+
xpath.gsub("/", "_").gsub(/\[\d*\]/) {|s| if s =~ /\[(\d*)\]/ then "_#{$1}_" else s end }
|
|
1034
|
+
end
|
|
1035
|
+
|
|
1032
1036
|
def generate_equality_test_data(progress, message, output_dir, config, options)
|
|
1033
1037
|
unless Dir.exist?(output_dir)
|
|
1034
1038
|
FileUtils.mkdir_p(output_dir)
|
|
@@ -1116,7 +1120,155 @@ def generate_equality_test_data(progress, message, output_dir, config, options)
|
|
|
1116
1120
|
else
|
|
1117
1121
|
raise RuntimeError.new("encountered unknown :type #{desc[:type].inspect}")
|
|
1118
1122
|
end
|
|
1119
|
-
end
|
|
1123
|
+
end
|
|
1124
|
+
|
|
1125
|
+
generate_equality_test(message, "#{output_dir}/test-equality.rb")
|
|
1126
|
+
end
|
|
1127
|
+
|
|
1128
|
+
def generate_equality_test(message, output_filename)
|
|
1129
|
+
|
|
1130
|
+
base_filename = BASE_FILENAME
|
|
1131
|
+
positive_tests = []
|
|
1132
|
+
positive_tests << <<EOF
|
|
1133
|
+
def test_equality_positive_base()
|
|
1134
|
+
assert(equality('#{base_filename}', '#{base_filename}'), 'Equality implementation is not reflexive on file #{base_filename}')
|
|
1135
|
+
end
|
|
1136
|
+
EOF
|
|
1137
|
+
each_structure_and_field_in(message) do |desc, xpath|
|
|
1138
|
+
if desc[:type] == :field then
|
|
1139
|
+
positive_tests << <<EOF
|
|
1140
|
+
def test_equality_positive_mutated_#{xpath_to_methodname(xpath)}()
|
|
1141
|
+
assert(equality('doc-mutated-#{xpath_to_filename(xpath)}.xml', 'doc-mutated-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation is not reflexive on file doc-mutated-#{xpath_to_filename(xpath)}.xml')
|
|
1142
|
+
end
|
|
1143
|
+
EOF
|
|
1144
|
+
|
|
1145
|
+
if desc[:optional] == true then
|
|
1146
|
+
positive_tests << <<EOF
|
|
1147
|
+
def test_equality_positive_removed_#{xpath_to_methodname(xpath)}()
|
|
1148
|
+
assert(equality('doc-removed-#{xpath_to_filename(xpath)}.xml', 'doc-removed-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation is not reflexive on file doc-removed-#{xpath_to_filename(xpath)}.xml')
|
|
1149
|
+
end
|
|
1150
|
+
EOF
|
|
1151
|
+
end
|
|
1152
|
+
elsif desc[:type] == :list then
|
|
1153
|
+
if desc[:element] then
|
|
1154
|
+
positive_tests << <<EOF
|
|
1155
|
+
def test_equality_positive_mutated_#{xpath_to_methodname(xpath)}()
|
|
1156
|
+
assert(equality('doc-mutated-#{xpath_to_filename(xpath)}.xml', 'doc-mutated-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation is not reflexive on file doc-mutated-#{xpath_to_filename(xpath)}.xml')
|
|
1157
|
+
end
|
|
1158
|
+
EOF
|
|
1159
|
+
|
|
1160
|
+
else
|
|
1161
|
+
positive_tests << <<EOF
|
|
1162
|
+
def test_equality_positive_removed_#{xpath_to_methodname(xpath)}()
|
|
1163
|
+
assert(equality('doc-removed-#{xpath_to_filename(xpath)}.xml', 'doc-removed-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation is not reflexive on file doc-removed-#{xpath_to_filename(xpath)}.xml')
|
|
1164
|
+
end
|
|
1165
|
+
EOF
|
|
1166
|
+
end
|
|
1167
|
+
elsif desc[:type] == :objlist then
|
|
1168
|
+
if desc[:element] then
|
|
1169
|
+
# list elements
|
|
1170
|
+
# no additional test data neccessary as the element objects will contain fields that are modified already
|
|
1171
|
+
else
|
|
1172
|
+
# the list itself
|
|
1173
|
+
positive_tests << <<EOF
|
|
1174
|
+
def test_equality_positive_removed_#{xpath_to_methodname(xpath)}()
|
|
1175
|
+
assert(equality('doc-removed-#{xpath_to_filename(xpath)}.xml', 'doc-removed-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation is not reflexive on file doc-removed-#{xpath_to_filename(xpath)}.xml')
|
|
1176
|
+
end
|
|
1177
|
+
EOF
|
|
1178
|
+
end
|
|
1179
|
+
elsif desc[:type] == :structure then
|
|
1180
|
+
if desc[:optional] == true then
|
|
1181
|
+
positive_tests << <<EOF
|
|
1182
|
+
def test_equality_positive_removed_#{xpath_to_methodname(xpath)}()
|
|
1183
|
+
assert(equality('doc-removed-#{xpath_to_filename(xpath)}.xml', 'doc-removed-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation is not reflexive on file doc-removed-#{xpath_to_filename(xpath)}.xml')
|
|
1184
|
+
end
|
|
1185
|
+
EOF
|
|
1186
|
+
end
|
|
1187
|
+
else
|
|
1188
|
+
raise RuntimeError.new("encountered unknown :type #{desc[:type].inspect}")
|
|
1189
|
+
end
|
|
1190
|
+
end
|
|
1191
|
+
|
|
1192
|
+
negative_tests = []
|
|
1193
|
+
each_structure_and_field_in(message) do |desc, xpath|
|
|
1194
|
+
if desc[:type] == :field then
|
|
1195
|
+
negative_tests << <<EOF
|
|
1196
|
+
def test_equality_negative_mutated_#{xpath_to_methodname(xpath)}()
|
|
1197
|
+
assert(!equality('#{base_filename}', 'doc-mutated-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation seems not to take the field #{xpath} into account. It regards the files #{base_filename} and doc-mutated-#{xpath_to_filename(xpath)}.xml as equal.')
|
|
1198
|
+
end
|
|
1199
|
+
EOF
|
|
1200
|
+
|
|
1201
|
+
if desc[:optional] == true then
|
|
1202
|
+
negative_tests << <<EOF
|
|
1203
|
+
def test_equality_negative_removed_#{xpath_to_methodname(xpath)}()
|
|
1204
|
+
assert(!equality('#{base_filename}', 'doc-removed-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation seems not to take the existence of field #{xpath} into account. It regards the files #{base_filename} and doc-removed-#{xpath_to_filename(xpath)}.xml as equal.')
|
|
1205
|
+
end
|
|
1206
|
+
EOF
|
|
1207
|
+
end
|
|
1208
|
+
elsif desc[:type] == :list then
|
|
1209
|
+
if desc[:element] then
|
|
1210
|
+
negative_tests << <<EOF
|
|
1211
|
+
def test_equality_negative_mutated_#{xpath_to_methodname(xpath)}()
|
|
1212
|
+
assert(!equality('#{base_filename}', 'doc-mutated-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation seems not to take the list #{xpath} into account. It regards the files #{base_filename} and doc-mutated-#{xpath_to_filename(xpath)}.xml as equal.')
|
|
1213
|
+
end
|
|
1214
|
+
EOF
|
|
1215
|
+
|
|
1216
|
+
else
|
|
1217
|
+
negative_tests << <<EOF
|
|
1218
|
+
def test_equality_negative_removed_#{xpath_to_methodname(xpath)}()
|
|
1219
|
+
assert(!equality('#{base_filename}', 'doc-removed-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation seems not to take the existence of the list #{xpath} into account. It regards the files #{base_filename} and doc-removed-#{xpath_to_filename(xpath)}.xml as equal.')
|
|
1220
|
+
end
|
|
1221
|
+
EOF
|
|
1222
|
+
end
|
|
1223
|
+
elsif desc[:type] == :objlist then
|
|
1224
|
+
if desc[:element] then
|
|
1225
|
+
# list elements
|
|
1226
|
+
# no additional test data neccessary as the element objects will contain fields that are modified already
|
|
1227
|
+
else
|
|
1228
|
+
# the list itself
|
|
1229
|
+
negative_tests << <<EOF
|
|
1230
|
+
def test_equality_negative_removed_#{xpath_to_methodname(xpath)}()
|
|
1231
|
+
assert(!equality('#{base_filename}', 'doc-removed-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation seems not to take the existence of objlist #{xpath} into account. It regards the files #{base_filename} and doc-removed-#{xpath_to_filename(xpath)}.xml as equal.')
|
|
1232
|
+
end
|
|
1233
|
+
EOF
|
|
1234
|
+
end
|
|
1235
|
+
elsif desc[:type] == :structure then
|
|
1236
|
+
if desc[:optional] == true then
|
|
1237
|
+
negative_tests << <<EOF
|
|
1238
|
+
def test_equality_negative_removed_#{xpath_to_methodname(xpath)}()
|
|
1239
|
+
assert(!equality('#{base_filename}', 'doc-removed-#{xpath_to_filename(xpath)}.xml'), 'Equality implementation seems not to take the existence of structure #{xpath} into account. It regards the files #{base_filename} and doc-removed-#{xpath_to_filename(xpath)}.xml as equal.')
|
|
1240
|
+
end
|
|
1241
|
+
EOF
|
|
1242
|
+
end
|
|
1243
|
+
else
|
|
1244
|
+
raise RuntimeError.new("encountered unknown :type #{desc[:type].inspect}")
|
|
1245
|
+
end
|
|
1246
|
+
end
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
content = <<EOF
|
|
1250
|
+
#!/bin/ruby
|
|
1251
|
+
|
|
1252
|
+
require 'test/unit'
|
|
1253
|
+
|
|
1254
|
+
class EqualityTest < Test::Unit::TestCase
|
|
1255
|
+
|
|
1256
|
+
def equality(filename1, filename2)
|
|
1257
|
+
# TODO: call your equality implementation here.
|
|
1258
|
+
# This is just an example showing how to call an externally-provided implementation.
|
|
1259
|
+
system("diff", filename1, filename2)
|
|
1260
|
+
end
|
|
1261
|
+
|
|
1262
|
+
#{positive_tests.join("\n\n")}
|
|
1263
|
+
|
|
1264
|
+
#{negative_tests.join("\n\n")}
|
|
1265
|
+
end
|
|
1266
|
+
EOF
|
|
1267
|
+
|
|
1268
|
+
File.open(output_filename, "w") do |f|
|
|
1269
|
+
f.puts(content)
|
|
1270
|
+
end
|
|
1271
|
+
|
|
1120
1272
|
end
|
|
1121
1273
|
|
|
1122
1274
|
def generate_max_doc(progress, message, output_filename, config, options)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mbt-gen
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.12
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- FM-enthusiast
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-09-
|
|
11
|
+
date: 2026-09-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: nokogiri
|