Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xml:Text and xmlSequence equality comparison #43074

Merged
merged 22 commits into from
Sep 26, 2024

Conversation

ravinperera00
Copy link
Contributor

@ravinperera00 ravinperera00 commented Jul 9, 2024

Purpose

The Ballerina specification states the following regarding xml:Text singleton and xml sequences.

# Type for zero or more text characters.
# Built-in subtype of xml.
# Adjacent xml text items are automatically concatenated,
# so an xml sequence belongs to this type if it is a singleton text sequence
# or the empty sequence.
@builtinSubtype
public type Text xml;

This means, when an xml sequence contains only children of xml:Text type, the sequence belongs to the xml:Text type and its value should be equal to an xml:Text value with the concatenation of the children of the sequence. The current implementation does not consider the above two values as equal and the changes included in this PR fixes that.

Fixes #42836

Approach

  • Modify the xmlSequence constructor to concatenate adjacent xml:Text elements into one member.
  • Change the equals methods of both XmlSequence and XmlText to accept the opposing type as equal if their text values are equal.

Samples

import ballerina/io;

public function main() {
    xml x1 = xml `<a>abc</a><b>def</b>`;
    xml r = xml:map(xml:elements(x1), y => y.getChildren());
    boolean b = (xml `abcdef` == r);
    io:println(b); // true
}

The map method will return an xml sequence containing a single xml:Text member (generated using the concatenation of the two xml:Text elements). This xml sequence will be equal to the xml:Text value of "abcdef".

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 93.10345% with 2 lines in your changes missing coverage. Please review.

Project coverage is 77.35%. Comparing base (207d34e) to head (f3b175e).
Report is 30 commits behind head on master.

Files with missing lines Patch % Lines
...ballerina/runtime/internal/values/XmlSequence.java 95.83% 0 Missing and 1 partial ⚠️
.../io/ballerina/runtime/internal/values/XmlText.java 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #43074      +/-   ##
============================================
+ Coverage     77.30%   77.35%   +0.04%     
- Complexity    58541    58599      +58     
============================================
  Files          3460     3460              
  Lines        220070   220111      +41     
  Branches      28909    28916       +7     
============================================
+ Hits         170136   170273     +137     
+ Misses        40524    40423     -101     
- Partials       9410     9415       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ravinperera00 ravinperera00 marked this pull request as ready for review July 19, 2024 08:19
Copy link

github-actions bot commented Aug 3, 2024

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Aug 3, 2024
Copy link

github-actions bot commented Aug 7, 2024

Closed PR due to inactivity for more than 18 days.

@github-actions github-actions bot closed this Aug 7, 2024
@ravinperera00 ravinperera00 reopened this Aug 8, 2024
@github-actions github-actions bot removed the Stale label Aug 10, 2024
Copy link

github-actions bot commented Sep 6, 2024

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@gimantha
Copy link
Contributor

@ravinperera00 The build is failing
image

Copy link
Contributor

@warunalakshitha warunalakshitha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@warunalakshitha warunalakshitha merged commit b950a72 into ballerina-platform:master Sep 26, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: xml:map operation when returning consecutive xml:Texts doesn't merge them together
6 participants