Skip to content

feat: add XML encoding and decoding exercise template - #100

Merged
zhravan merged 2 commits into
zhravan:mainfrom
aviralgarg05:feat/add-xml-exercise-template
Oct 1, 2025
Merged

feat: add XML encoding and decoding exercise template#100
zhravan merged 2 commits into
zhravan:mainfrom
aviralgarg05:feat/add-xml-exercise-template

Conversation

@aviralgarg05

@aviralgarg05 aviralgarg05 commented Oct 1, 2025

Copy link
Copy Markdown
Contributor

Hacktoberfest 2025

Summary

Add comprehensive XML exercise (37_xml) covering encoding/xml package usage.

Changes:

  • Add exercise template in internal/exercises/templates/37_xml/
    • xml.go: Template with TODO comments for students
    • xml_test.go: Comprehensive test suite with 5 test cases
  • Add solution in internal/exercises/solutions/37_xml/
    • xml.go: Complete implementation of XML marshaling/unmarshaling
    • xml_test.go: Test suite for validation
  • Update internal/exercises/catalog.yaml with new exercise entry

Exercise Features:

  • Teaches Go's encoding/xml package
  • Covers XML struct tags usage
  • Implements Marshal and Unmarshal operations
  • Includes two struct types (Person and Book)
  • Comprehensive test coverage including round-trip validation

Test Results:

  • Solution tests: 5/5 passed
  • Template tests: Fail as expected (incomplete implementation)
  • Project builds successfully
  • CLI integration verified

Checklist

  • Tests pass: make verify or golearn verify <slug>
  • Docs updated (README/CONTRIBUTING) if needed
  • No large new dependencies

Screenshots / Output (if CLI UX)

Paste before/after where helpful.

Related issues

Fixes #82

Summary by CodeRabbit

  • New Features

    • Added a new “XML Encoding and Decoding” exercise, covering XML marshalling/unmarshalling with example data structures and starter templates.
    • Includes built-in hints to guide learners.
  • Tests

    • Introduced comprehensive test coverage for the new exercise, including round-trip validation.
  • Documentation

    • Updated exercise catalog with descriptions, hints, and regex-based test guidance.

Add comprehensive XML exercise (37_xml) covering encoding/xml package usage.

Changes:
- Add exercise template in internal/exercises/templates/37_xml/
  - xml.go: Template with TODO comments for students
  - xml_test.go: Comprehensive test suite with 5 test cases
- Add solution in internal/exercises/solutions/37_xml/
  - xml.go: Complete implementation of XML marshaling/unmarshaling
  - xml_test.go: Test suite for validation
- Update internal/exercises/catalog.yaml with new exercise entry

Exercise Features:
- Teaches Go's encoding/xml package
- Covers XML struct tags usage
- Implements Marshal and Unmarshal operations
- Includes two struct types (Person and Book)
- Comprehensive test coverage including round-trip validation

Test Results:
- Solution tests: 5/5 passed
- Template tests: Fail as expected (incomplete implementation)
- Project builds successfully
- CLI integration verified

Closes zhravan#82
@coderabbitai

coderabbitai Bot commented Oct 1, 2025

Copy link
Copy Markdown

Warning

Rate limit exceeded

@zhravan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 0 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0e28569 and 597f55d.

📒 Files selected for processing (1)
  • internal/exercises/catalog.yaml (1 hunks)

Walkthrough

Adds a new XML exercise (slug 37_xml) to the catalog with hints. Introduces template stubs and tests under templates/37_xml. Provides a complete reference implementation and tests under solutions/37_xml using encoding/xml with Person and Book types and marshal/unmarshal helpers.

Changes

Cohort / File(s) Summary
Catalog Update
internal/exercises/catalog.yaml
Registers concept 37_xml “XML Encoding and Decoding”; adds test_regex and hints regarding encoding/xml, struct tags, xml.Marshal/xml.Unmarshal.
Solutions: XML implementation + tests
internal/exercises/solutions/37_xml/xml.go, internal/exercises/solutions/37_xml/xml_test.go
Adds Person and Book structs with XML tags; implements MarshalPerson/UnmarshalPerson and MarshalBook/UnmarshalBook; includes tests covering marshal, unmarshal, and round-trip.
Templates: Stubs + tests
internal/exercises/templates/37_xml/xml.go, internal/exercises/templates/37_xml/xml_test.go
Adds stub types and functions mirroring solutions API; provides template tests verifying expected behavior; implementation left to learners.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer Code
  participant Ex as xml package (exercise)
  participant Lib as encoding/xml

  rect rgba(200,220,255,0.3)
  note right of Ex: Marshal flow
  Dev->>Ex: MarshalPerson(p)
  Ex->>Lib: xml.Marshal(p)
  Lib-->>Ex: []byte XML, error
  Ex-->>Dev: []byte XML, error
  end

  rect rgba(220,255,200,0.3)
  note right of Ex: Unmarshal flow
  Dev->>Ex: UnmarshalPerson(data)
  Ex->>Lib: xml.Unmarshal(data, &Person)
  Lib-->>Ex: error
  Ex-->>Dev: Person, error
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble tags with whiskered cheer,
and <title> crystal-clear.
Bytes to roots, and roots to leaves,
I hop through marshals, weave retrieves.
A carrot-shaped commit I bring—
XML now does its spring! 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The pull request introduces solution code and tests under internal/exercises/solutions/37_xml, which are not part of the acceptance criteria defined in linked issue #82 that only calls for templates, tests in the templates directory, and catalog updates. Please remove or isolate the solution implementation and associated tests into a separate pull request or update the linked issue to explicitly include solution code to keep the scope aligned with the original requirements.
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely describes the primary change of adding an XML encoding and decoding exercise template, directly matching the new template files under internal/exercises/templates/37_xml and the associated tests and hints added to the catalog.
Linked Issues Check ✅ Passed The pull request fully satisfies all acceptance criteria of linked issue #82 by adding the XML exercise template under internal/exercises/templates/37_xml, including the requisite tests in xml_test.go, updating internal/exercises/catalog.yaml with the new slug and helpful hints, and linking the new exercise appropriately.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
internal/exercises/templates/37_xml/xml_test.go (1)

1-124: Comprehensive test suite for the XML exercise.

The test coverage is excellent:

  • Marshal/unmarshal for both Person and Book
  • Round-trip validation for Person
  • Proper error handling throughout

The tests will fail with the stub implementation (as expected for templates), which helps students understand the requirements.

Optional enhancement: Consider adding a round-trip test for Book similar to TestMarshalUnmarshalRoundTrip for Person, though the current coverage is adequate.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b99da22 and 0e28569.

📒 Files selected for processing (5)
  • internal/exercises/catalog.yaml (1 hunks)
  • internal/exercises/solutions/37_xml/xml.go (1 hunks)
  • internal/exercises/solutions/37_xml/xml_test.go (1 hunks)
  • internal/exercises/templates/37_xml/xml.go (1 hunks)
  • internal/exercises/templates/37_xml/xml_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
internal/exercises/templates/37_xml/xml_test.go (2)
internal/exercises/solutions/37_xml/xml.go (6)
  • Person (6-10)
  • MarshalPerson (20-22)
  • UnmarshalPerson (25-29)
  • Book (13-17)
  • MarshalBook (32-34)
  • UnmarshalBook (37-41)
internal/exercises/templates/37_xml/xml.go (6)
  • Person (4-12)
  • MarshalPerson (27-31)
  • UnmarshalPerson (35-40)
  • Book (15-23)
  • MarshalBook (44-48)
  • UnmarshalBook (52-57)
internal/exercises/solutions/37_xml/xml.go (1)
internal/exercises/templates/37_xml/xml.go (6)
  • MarshalPerson (27-31)
  • Person (4-12)
  • UnmarshalPerson (35-40)
  • MarshalBook (44-48)
  • Book (15-23)
  • UnmarshalBook (52-57)
internal/exercises/solutions/37_xml/xml_test.go (1)
internal/exercises/solutions/37_xml/xml.go (6)
  • Person (6-10)
  • MarshalPerson (20-22)
  • UnmarshalPerson (25-29)
  • Book (13-17)
  • MarshalBook (32-34)
  • UnmarshalBook (37-41)
internal/exercises/templates/37_xml/xml.go (1)
internal/exercises/solutions/37_xml/xml.go (6)
  • MarshalPerson (20-22)
  • Person (6-10)
  • UnmarshalPerson (25-29)
  • MarshalBook (32-34)
  • Book (13-17)
  • UnmarshalBook (37-41)
🔇 Additional comments (10)
internal/exercises/catalog.yaml (1)

137-144: LGTM! Well-structured exercise entry.

The catalog entry is clear and provides helpful hints covering all key aspects: the encoding/xml package, struct tags, and both marshal/unmarshal operations. The hints will effectively guide students through the exercise.

internal/exercises/solutions/37_xml/xml_test.go (1)

1-124: Test suite matches template tests (intentional).

The tests are identical to those in internal/exercises/templates/37_xml/xml_test.go. This is appropriate for an educational repository where:

  • Template tests define the acceptance criteria for students
  • Solution tests validate the reference implementation
  • Having identical tests ensures consistency
internal/exercises/templates/37_xml/xml.go (3)

3-12: Clear template structure with helpful TODO comments.

The Person struct provides a good starting point for students, with explicit instructions on which XML tags to add for each field.


14-23: Consistent template structure for Book.

The Book struct follows the same clear pattern as Person, making it easy for students to apply what they learned.


25-57: Function stubs provide clear guidance.

All four functions have:

  • Correct signatures matching the test expectations
  • Clear TODO comments indicating what to implement
  • Reminder to import the encoding/xml package

The stub implementations compile but intentionally fail tests, guiding students to complete them.

internal/exercises/solutions/37_xml/xml.go (5)

1-17: Clean implementation with proper XML tags.

Both structs are correctly defined with:

  • Appropriate XML struct tags (lowercase, matching XML element names)
  • Clear comments
  • Proper field types

19-22: MarshalPerson correctly delegates to xml.Marshal.

The implementation is appropriately simple, directly wrapping xml.Marshal which handles all the serialization logic based on the struct tags.


31-34: MarshalBook follows the same clean pattern.

Consistent with MarshalPerson, this function correctly wraps xml.Marshal.


24-29: UnmarshalPerson correctly uses xml.Unmarshal.

The implementation properly:

  • Creates a zero-value Person
  • Passes a pointer to xml.Unmarshal (required)
  • Returns both the struct and any error

36-41: UnmarshalBook mirrors UnmarshalPerson correctly.

The implementation follows the same correct pattern with proper pointer usage and error handling.

@aviralgarg05

Copy link
Copy Markdown
Contributor Author

Should i review and fix these issues as well

@zhravan zhravan added patch Bug fixes and small improvements hacktoberfest Hacktoberfest participation hacktoberfest-accepted hacktoberfest2025 labels Oct 1, 2025
@zhravan
zhravan merged commit 0d451ad into zhravan:main Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest Hacktoberfest participation hacktoberfest2025 hacktoberfest-accepted patch Bug fixes and small improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Concept] XML - add exercise templates

2 participants