feat: add XML encoding and decoding exercise template - #100
Conversation
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
|
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 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. 📒 Files selected for processing (1)
WalkthroughAdds 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
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
📒 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.Marshalwhich 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.
|
Should i review and fix these issues as well |
Hacktoberfest 2025
Summary
Add comprehensive XML exercise (37_xml) covering encoding/xml package usage.
Changes:
Exercise Features:
Test Results:
Checklist
make verifyorgolearn verify <slug>Screenshots / Output (if CLI UX)
Paste before/after where helpful.
Related issues
Fixes #82
Summary by CodeRabbit
New Features
Tests
Documentation