Skip to content

Conversation

@AngeloTadeucci
Copy link
Collaborator

@AngeloTadeucci AngeloTadeucci commented Sep 30, 2025

Introduces BanWordParser for parsing ban words and UGC ban words from XML files. Adds BanWordParserTest to verify correct parsing and updates project version to 2.3.4.

Summary by CodeRabbit

  • New Features
    • Added support for parsing ban words, including separate handling for standard and UGC lists. Produces sequential IDs with non-empty names and aggregates results across all relevant data sources.
  • Tests
    • Added unit tests validating parsing correctness and expected totals for both standard and UGC ban word lists.
  • Chores
    • Bumped package version to 2.3.4.

Introduces BanWordParser for parsing ban words and UGC ban words from XML files. Adds BanWordParserTest to verify correct parsing and updates project version to 2.3.4.
@coderabbitai
Copy link

coderabbitai bot commented Sep 30, 2025

Walkthrough

Introduces BanWordParser to extract ban words from XML via M2dReader, adds two parsing methods (banword and ugcbanword), includes corresponding unit tests validating counts and non-empty names, and bumps Maple2.File.Parser package version from 2.3.3 to 2.3.4.

Changes

Cohort / File(s) Summary
Parser: New BanWordParser
Maple2.File.Parser/BanWordParser.cs
Adds public BanWordParser with constructor BanWordParser(M2dReader). Implements ParseBanWords() and ParseUgcBanWords() to deserialize XML (StringMapping) from entries whose names match banword patterns, yielding (int Id, string Name) for non-empty values.
Tests: BanWordParser coverage
Maple2.File.Tests/BanWordParserTest.cs
Adds unit tests asserting non-negative IDs, non-empty names, and total counts (6179 for ban words, 1208 for UGC). Uses TestUtils.XmlReader to load test data.
Project: Version bump
Maple2.File.Parser/Maple2.File.Parser.csproj
Increments PackageVersion from 2.3.3 to 2.3.4.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Test as Test
  participant Parser as BanWordParser
  participant Reader as M2dReader
  participant Xml as XmlSerializer

  Test->>Parser: new BanWordParser(M2dReader)
  Test->>Parser: ParseBanWords()
  loop For each entry name containing "banword" and not "ugc"
    Parser->>Reader: Open(entry)
    Reader-->>Parser: XML stream
    Parser->>Xml: Deserialize<StringMapping>(stream)
    Xml-->>Parser: StringMapping
    alt Non-empty values
      Parser-->>Test: yield (Id, Name)
    end
  end

  Test->>Parser: ParseUgcBanWords()
  loop For each entry name containing "ugcbanword"
    Parser->>Reader: Open(entry)
    Reader-->>Parser: XML stream
    Parser->>Xml: Deserialize<StringMapping>(stream)
    Xml-->>Parser: StringMapping
    alt Non-empty values
      Parser-->>Test: yield (Id, Name)
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • Zintixx

Poem

I hop through XML, nibbling tags with care,
Pluck banned words like carrots from the air.
Two baskets filled—UGC and plain—
Counted clean, no empty grain.
Version hops a dot—2.3.4, hooray!
Parsers dance; tests lead the way. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 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 summarizes the primary change by noting the addition of the BanWordParser along with its corresponding unit tests, which matches the pull request’s main objectives without unnecessary detail.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
Maple2.File.Tests/BanWordParserTest.cs (1)

11-23: Consider extracting common setup to a test initialization method.

Both test methods duplicate the Filter.Load call with identical parameters. Consider extracting this to a [TestInitialize] method to improve maintainability.

Apply this diff to refactor the common setup:

+    [TestInitialize]
+    public void Setup() {
+        var locale = Locale.NA;
+        Filter.Load(TestUtils.XmlReader, locale.ToString(), "Live");
+    }
+
     [TestMethod]
     public void TestBanWordParser() {
-        var locale = Locale.NA;
-        Filter.Load(TestUtils.XmlReader, locale.ToString(), "Live");
         var parser = new BanWordParser(TestUtils.XmlReader);
Maple2.File.Parser/BanWordParser.cs (1)

19-53: Extract common parsing logic to reduce duplication.

ParseBanWords() and ParseUgcBanWords() contain nearly identical logic. The only difference is the file filter predicate. Consider extracting the common parsing logic to a private helper method.

Apply this refactor to eliminate duplication:

+    private IEnumerable<(int Id, string Name)> ParseBanWordsInternal(Func<PackFileEntry, bool> fileFilter) {
+        int i = 0;
+        foreach (PackFileEntry entry in xmlReader.Files.Where(fileFilter)) {
+            XmlReader reader = xmlReader.GetXmlReader(entry);
+            var mapping = nameSerializer.Deserialize(reader) as StringMapping;
+
+            if (mapping == null) {
+                throw new InvalidOperationException($"Failed to deserialize ban word mapping from entry: {entry.Name}");
+            }
+
+            Dictionary<int, string> banWords = mapping.key.ToDictionary(_ => i++, key => key.name);
+            foreach (var banWord in banWords) {
+                if (string.IsNullOrEmpty(banWord.Value)) {
+                    continue;
+                }
+                yield return (banWord.Key, banWord.Value);
+            }
+        }
+    }
+
     public IEnumerable<(int Id, string Name)> ParseBanWords() {
-        int i = 0;
-        foreach (PackFileEntry entry in xmlReader.Files.Where(entry => entry.Name.Contains("banword") && !entry.Name.Contains("ugc"))) {
-            XmlReader reader = xmlReader.GetXmlReader(entry);
-            var mapping = nameSerializer.Deserialize(reader) as StringMapping;
-
-            Debug.Assert(mapping != null);
-
-            Dictionary<int, string> banWords = mapping.key.ToDictionary(_ => i++, key => key.name);
-            foreach (var banWord in banWords) {
-                if (string.IsNullOrEmpty(banWord.Value)) {
-                    continue;
-                }
-                yield return (banWord.Key, banWord.Value);
-            }
-        }
+        return ParseBanWordsInternal(entry => entry.Name.Contains("banword") && !entry.Name.Contains("ugc"));
     }

     public IEnumerable<(int Id, string Name)> ParseUgcBanWords() {
-        int i = 0;
-        foreach (PackFileEntry entry in xmlReader.Files.Where(entry => entry.Name.Contains("ugcbanword"))) {
-            XmlReader reader = xmlReader.GetXmlReader(entry);
-            var mapping = nameSerializer.Deserialize(reader) as StringMapping;
-
-            Debug.Assert(mapping != null);
-
-            Dictionary<int, string> banWords = mapping.key.ToDictionary(_ => i++, key => key.name);
-            foreach (var banWord in banWords) {
-                if (string.IsNullOrEmpty(banWord.Value)) {
-                    continue;
-                }
-                yield return (banWord.Key, banWord.Value);
-            }
-        }
+        return ParseBanWordsInternal(entry => entry.Name.Contains("ugcbanword"));
     }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 328356c and 36eb002.

📒 Files selected for processing (3)
  • Maple2.File.Parser/BanWordParser.cs (1 hunks)
  • Maple2.File.Parser/Maple2.File.Parser.csproj (1 hunks)
  • Maple2.File.Tests/BanWordParserTest.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
Maple2.File.Tests/BanWordParserTest.cs (3)
Maple2.File.Parser/Tools/Filter.cs (1)
  • Filter (9-47)
Maple2.File.IO/M2dReader.cs (1)
  • XmlReader (43-45)
Maple2.File.Parser/BanWordParser.cs (2)
  • BanWordParser (10-54)
  • BanWordParser (14-17)
Maple2.File.Parser/BanWordParser.cs (1)
Maple2.File.IO/M2dReader.cs (1)
  • XmlReader (43-45)
🔇 Additional comments (3)
Maple2.File.Parser/Maple2.File.Parser.csproj (1)

16-16: LGTM!

The version bump from 2.3.3 to 2.3.4 is appropriate for the addition of the new BanWordParser functionality.

Maple2.File.Parser/BanWordParser.cs (2)

14-17: LGTM!

The constructor properly initializes the required dependencies for XML deserialization.


27-27: Verify the ID assignment behavior with empty ban words.

The current implementation assigns IDs sequentially during dictionary creation (line 27), but only yields non-empty ban words (lines 29-31). This results in non-contiguous IDs when empty entries exist.

For example, if entries 2 and 5 are empty in a set of 10, the yielded IDs will be: 0, 1, 3, 4, 6, 7, 8, 9.

Is this non-contiguous ID assignment intentional? If contiguous IDs are desired, move the increment to the yield statement.

If contiguous IDs are required, apply this diff:

 public IEnumerable<(int Id, string Name)> ParseBanWords() {
     int i = 0;
     foreach (PackFileEntry entry in xmlReader.Files.Where(entry => entry.Name.Contains("banword") && !entry.Name.Contains("ugc"))) {
         XmlReader reader = xmlReader.GetXmlReader(entry);
         var mapping = nameSerializer.Deserialize(reader) as StringMapping;

         Debug.Assert(mapping != null);

-        Dictionary<int, string> banWords = mapping.key.ToDictionary(_ => i++, key => key.name);
-        foreach (var banWord in banWords) {
-            if (string.IsNullOrEmpty(banWord.Value)) {
+        foreach (var key in mapping.key) {
+            if (string.IsNullOrEmpty(key.name)) {
                 continue;
             }
-            yield return (banWord.Key, banWord.Value);
+            yield return (i++, key.name);
         }
     }
 }

@AngeloTadeucci AngeloTadeucci merged commit 41477e7 into master Sep 30, 2025
3 checks passed
@AngeloTadeucci AngeloTadeucci deleted the dev branch September 30, 2025 02:25
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.

3 participants