Repository navigation
Conversation
aaronzi
left a comment
There was a problem hiding this comment.
I generated the Go SDK with the AAS v3.2 model from #840. All five XML round-trip cases I tried passed, including the scientific notation example and a Property with valueType set to xs:double that kept its original 42.0 spelling. The positive infinity writer test passed too.
I'd like to see the tuple regression fixed before merging. It makes a generated test fail even when the SDK writes back exactly the XML it read. I also left a smaller comment about numbers split by XML markup.
| {III}contexts = append(contexts, xmlTextContext(contexts[len(contexts)-1], start.Name)) | ||
| {II}if element, ok := token.(xml.StartElement); ok {{ | ||
| {III}context := xmlTextContext(contexts[len(contexts)-1], element.Name) | ||
| {III}if context == "double" || context == "json:double" {{ |
There was a problem hiding this comment.
I hit this with pair: Tuple[V2, float], where V2 is a class with a text field. The SDK reads and writes <pair><v2><text>x</text></v2><v2>42</v2></pair> just fine. Both items are named v2, though, so this lookup treats the first one as a double and fails on <text> with expected numeric text, got xml.StartElement. The same round-trip passes on main.
Could we use the tuple position here, like the reader does, and cover this example with a regression test?
| {III}endTag := source[start:decoder.InputOffset()] | ||
| {III}// In a valid number, '<' can only come from intervening markup. | ||
| {III}// Keep its position relative to the digits by retaining their spelling. | ||
| {III}if strings.Contains(original[numberStart:numberEnd], "<") {{ |
There was a problem hiding this comment.
4<!--c-->2.0 and 4<!--c-->2 both parse as 42, and the comment is in exactly the same place. This early return makes them compare unequal. The same thing happens with a processing instruction between the digits. Could we compare the parsed number and the markup position separately? It would be good to cover this pair alongside the existing moved-comment case.
|
@chris-koo please give me a chance to review this PR tomorrow before merging. The experience teaches us that we should not rely on anything AAS specific -- you should not assume that there is a coupling between the fields, for example. (I haven't had chance to look at the code, so I might be just talking rubbish.) |
This is a genuine issue with XML serializations: the XSD standard knows several serializations for the same value. This strikes with doubles, but also for xs:boolean, for example "1" / "true" are the same. I've hit the same issue with the current testdata today for Java. A serialization in one language therefore does not need to be equivalent to a serialization in another language, thus making string comparison the improper tool for these test vases. Ideally, the test cases should probably use explicit serialization/deserialization functions across all languages/primitives instead of string comparisons. For simplicity sake, however, and considering that the serialization code doesn't change as frequently and we know the languages with quirks, I'd argue in favor of adding individual exceptions. |
The generated Go XML round-trip tests currently fail when a fixture and the SDK use different spellings of the same double. For example, a fixture may contain
21668651.6while the SDK writes2.16686516e+07. Both represent the samexs:doublevalue.We update the tests to compare double-precision values at XML positions that the model identifies as numeric. Different numbers still compare differently, and string fields keep their original text. For example,
42and42.0compare equally in a double field and differently in a string field.We also check the Go writer’s output directly for positive infinity. It must emit
INF, the spelling accepted by both XSD 1.0 and XSD 1.1.These changes affect only the generated tests and their golden files. SDK serialization and public APIs remain unchanged.
This addresses the numeric-comparison item in #840.