Skip to content

refactor(strings): improve tests for case conversion functions to improve coverage and performance benchmarks#122

Merged
ReneWerner87 merged 2 commits intomasterfrom
test-strings-better
Jul 4, 2025
Merged

refactor(strings): improve tests for case conversion functions to improve coverage and performance benchmarks#122
ReneWerner87 merged 2 commits intomasterfrom
test-strings-better

Conversation

@sixcolors
Copy link
Member

@sixcolors sixcolors commented Jul 3, 2025

Enhance test cases for case conversion functions to boost coverage and performance benchmarks.

Remove IfToUpper and IfToLower since ToUpper and ToLower now have the same functionality.

Summary by CodeRabbit

  • Tests
    • Expanded and refactored tests for ASCII string case conversion, adding comprehensive coverage for various scenarios and edge cases.
    • Introduced structured, table-driven tests to ensure correctness for both ToUpper and ToLower functions.
    • Added benchmarks to compare performance and allocations of custom and standard library case conversion functions.
  • Bug Fixes
    • Removed conditional case conversion functions to streamline and simplify string case handling.

@sixcolors sixcolors requested a review from a team as a code owner July 3, 2025 18:10
@sixcolors sixcolors requested review from ReneWerner87, efectn and gaby and removed request for a team July 3, 2025 18:10
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Walkthrough

This change introduces comprehensive, table-driven tests and benchmarks for ASCII string case conversion utilities (ToUpper, ToLower, ToUpperBytes, ToLowerBytes). It adds new test constants, a TestCase struct, and a large suite of test cases covering edge cases, boundary lengths, and typical usage patterns, replacing previous ad hoc tests. Additionally, it removes two conditional conversion functions, IfToLower and IfToUpper, from the codebase.

Changes

Files Change Summary
bytes_test.go Added string constants for test input and expected output; updated benchmarks to use these constants.
utils/strings_test.go Refactored and expanded tests for ASCII case conversion: introduced TestCase struct, comprehensive test cases, table-driven tests, and benchmarks for both custom and standard library functions.
utils/strings.go Removed IfToLower and IfToUpper functions that conditionally converted string cases based on pre-check scans.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant ToUpper
    participant ToLower

    TestRunner->>ToUpper: Call ToUpper(input)
    ToUpper-->>TestRunner: Return uppercased string

    TestRunner->>ToLower: Call ToLower(input)
    ToLower-->>TestRunner: Return lowercased string

    Note over TestRunner: Validate outputs against expected results for each test case
Loading

Possibly related PRs

Suggested labels

codex

Suggested reviewers

  • gaby
  • efectn

Poem

In the meadow of code, a bunny hops,
Refactoring tests with leaps and stops.
Upper and lower, each case is explored,
Benchmarks abound, coverage restored.
With table-driven joy and ASCII delight,
The rabbit ensures conversions are right!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 436a248 and ccf5c67.

📒 Files selected for processing (2)
  • strings.go (0 hunks)
  • strings_test.go (1 hunks)
💤 Files with no reviewable changes (1)
  • strings.go
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ReneWerner87
PR: gofiber/contrib#0
File: :0-0
Timestamp: 2024-10-16T10:04:06.328Z
Learning: The i18n functionality in the gofiber/contrib repository is being refactored from middleware to a global container to improve robustness and performance. The global container will be initialized once before setting up routes and will manage the i18n bundle and localizer map.
Learnt from: ReneWerner87
PR: gofiber/contrib#0
File: :0-0
Timestamp: 2024-07-03T11:59:00.303Z
Learning: The i18n functionality in the gofiber/contrib repository is being refactored from middleware to a global container to improve robustness and performance. The global container will be initialized once before setting up routes and will manage the i18n bundle and localizer map.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
strings_test.go (9)
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: efectn
PR: gofiber/fiber#3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the `require` methods from the `testify` package for assertions instead of manual comparisons and calls to `t.Fatal` or `t.Fatalf`.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-07-26T21:00:12.902Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: juls0730
PR: gofiber/recipes#2710
File: tableflip/main.go:61-62
Timestamp: 2024-12-01T01:15:48.126Z
Learning: In the GoFiber `tableflip` recipe (`tableflip/main.go`), the implementation matches the upstream reference implementation. Future code suggestions should consider maintaining this alignment to ensure consistency.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build (1.24.x, macos-13)
  • GitHub Check: Build (1.23.x, windows-latest)
  • GitHub Check: Build (1.24.x, windows-latest)
  • GitHub Check: Build (1.23.x, macos-13)
  • GitHub Check: Compare
🔇 Additional comments (10)
strings_test.go (10)

1-10: Excellent documentation and test suite overview.

The comprehensive header comment clearly explains the purpose and scope of the test suite, including the optimization thresholds and coverage areas. This documentation will be valuable for future maintainers.


21-29: Well-designed TestCase structure for comprehensive testing.

The TestCase struct effectively captures all necessary test parameters including allocation expectations, making the test suite both thorough and efficient for verifying optimization behaviors.


31-155: Comprehensive test case coverage with excellent edge case handling.

The test cases cover an impressive range of scenarios:

  • Edge cases (empty strings, single characters, non-alphabetic)
  • HTTP methods and headers (real-world use cases)
  • URL patterns
  • SWAR optimization thresholds (15-25 bytes)
  • Large string handling
  • Position-specific character variations

The allocation flags (upperNoConv, lowerNoConv) are correctly set to verify the optimization behavior where functions should return the input without allocation when no conversion is needed.


157-173: Excellent allocation checking implementation in ToUpper tests.

The test correctly verifies both functional correctness and performance optimization by checking for zero allocations when no conversion is needed. The parallel execution is properly implemented with proper variable capture.


175-191: Consistent and thorough ToLower test implementation.

The ToLower test mirrors the ToUpper test structure perfectly, maintaining consistency in the test suite while providing comprehensive coverage for the lowercase conversion function.


193-206: Thorough ASCII character validation.

This test ensures complete ASCII character coverage by testing all 128 ASCII characters against the standard library implementation, providing confidence in the correctness of the custom functions.


208-216: Important non-ASCII character preservation test.

This test verifies that the ASCII-optimized functions correctly preserve non-ASCII characters unchanged, which is crucial for maintaining data integrity in international applications.


218-233: Comprehensive benchmark with allocation verification.

The benchmark not only measures performance but also verifies correctness and allocation behavior, providing valuable insights for optimization validation. The allocation checking in benchmarks is particularly well-implemented.


235-250: Consistent ToLower benchmark implementation.

The ToLower benchmark maintains the same thorough approach as the ToUpper benchmark, ensuring comprehensive performance testing across all test cases.


252-276: Valuable standard library performance comparison.

The inclusion of standard library benchmarks provides important baseline comparisons for evaluating the performance benefits of the custom implementations. This is excellent for performance regression detection and optimization validation.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in a Comment
  • Commit Unit Tests in branch test-strings-better

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @sixcolors, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on improving the robustness and performance validation of the string case conversion utilities. It introduces a highly structured and comprehensive set of test cases to ensure the correctness of ToUpper and ToLower functions across a wide array of inputs, while also enhancing the benchmarking suite to provide more detailed performance and allocation insights.

Highlights

  • Enhanced Test Coverage: The test suite for ToUpper and ToLower functions has been significantly expanded using a data-driven approach. A new TestCase struct and a comprehensive testCases slice now cover a wide range of scenarios, including edge cases (empty, numbers, symbols), HTTP methods, HTTP headers, URLs, and various string lengths and character patterns (lowercase, uppercase, mixed, camelCase, kebab-case, snake_case).
  • New Test Cases: Added specific tests to verify the behavior of ToUpper and ToLower for all 128 ASCII characters, ensuring correctness across the entire ASCII range. A new test also confirms that non-ASCII characters remain unchanged by these functions.
  • Improved Performance Benchmarking: The benchmarks for ToUpper and ToLower have been refactored to utilize the new testCases data, providing more thorough performance analysis across diverse inputs. Benchmarks now report memory allocations (b.ReportAllocs()) and include comparisons against the standard library's strings.ToUpper and strings.ToLower functions, allowing for direct performance comparisons.
  • Test Code Refactoring: Older, less comprehensive test functions (e.g., Test_IfToUpper, Test_IfToLower, Test_ToLower_DirectByteIteration) have been removed and replaced by the new data-driven test structure. String constants used for testing (largeStr, upperStr, lowerStr) have been centralized in bytes_test.go for better organization.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Jul 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.87%. Comparing base (3c2770a) to head (436a248).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #122      +/-   ##
==========================================
- Coverage   96.51%   91.87%   -4.65%     
==========================================
  Files           9        9              
  Lines         517      517              
==========================================
- Hits          499      475      -24     
- Misses         12       36      +24     
  Partials        6        6              
Flag Coverage Δ
unittests 91.87% <ø> (-4.65%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the tests for string case conversion functions, using a table-driven approach. The benchmarks have been improved to use the same test cases and compare against the standard library. The tests for the exported functions IfToUpper and IfToLower have been removed, but the functions themselves remain. This reduces test coverage and should be addressed.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
strings_test.go (1)

21-29: Consider testing the no-allocation behavior indicated by upperNoConv/lowerNoConv fields.

The TestCase struct includes upperNoConv and lowerNoConv fields that indicate when functions should return input without allocation, but these aren't tested. Consider adding assertions to verify this behavior.

Example implementation to test no-allocation cases:

func Test_ToUpper_NoAllocation(t *testing.T) {
	t.Parallel()
	for _, tc := range testCases {
		if tc.upperNoConv {
			t.Run(tc.name+"-no-alloc", func(t *testing.T) {
				t.Parallel()
				result := ToUpper(tc.input)
				// Verify pointer equality when no conversion needed
				require.True(t, &result == &tc.input, "ToUpper should return same string without allocation")
			})
		}
	}
}

Also applies to: 157-177

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c2770a and 436a248.

📒 Files selected for processing (2)
  • bytes_test.go (1 hunks)
  • strings_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ReneWerner87
PR: gofiber/contrib#0
File: :0-0
Timestamp: 2024-10-16T10:04:06.328Z
Learning: The i18n functionality in the gofiber/contrib repository is being refactored from middleware to a global container to improve robustness and performance. The global container will be initialized once before setting up routes and will manage the i18n bundle and localizer map.
Learnt from: ReneWerner87
PR: gofiber/contrib#0
File: :0-0
Timestamp: 2024-07-03T11:59:00.303Z
Learning: The i18n functionality in the gofiber/contrib repository is being refactored from middleware to a global container to improve robustness and performance. The global container will be initialized once before setting up routes and will manage the i18n bundle and localizer map.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-07-01T03:44:03.672Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:20-23
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in both `EncryptCookie` and `DecryptCookie` functions have been added to ensure robust validation and prevent potential runtime errors.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
bytes_test.go (6)
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: efectn
PR: gofiber/fiber#3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the `require` methods from the `testify` package for assertions instead of manual comparisons and calls to `t.Fatal` or `t.Fatalf`.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-07-26T21:00:12.902Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The project uses the testify/assert package for assertions in unit tests.
strings_test.go (7)
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: efectn
PR: gofiber/fiber#3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the `require` methods from the `testify` package for assertions instead of manual comparisons and calls to `t.Fatal` or `t.Fatalf`.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-07-26T21:00:12.902Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: juls0730
PR: gofiber/recipes#2710
File: tableflip/main.go:61-62
Timestamp: 2024-12-01T01:15:48.126Z
Learning: In the GoFiber `tableflip` recipe (`tableflip/main.go`), the implementation matches the upstream reference implementation. Future code suggestions should consider maintaining this alignment to ensure consistency.
🧬 Code Graph Analysis (1)
strings_test.go (1)
strings.go (2)
  • ToUpper (30-50)
  • ToLower (8-27)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Build (1.24.x, windows-latest)
  • GitHub Check: Build (1.24.x, macos-13)
  • GitHub Check: Build (1.23.x, windows-latest)
  • GitHub Check: Build (1.23.x, macos-13)
  • GitHub Check: Compare
  • GitHub Check: Analyse
🔇 Additional comments (5)
bytes_test.go (1)

14-18: Good addition of benchmark constants!

The string constants provide consistent test data for benchmarking ToLowerBytes and ToUpperBytes. The chosen path string is realistic and representative of typical web application URLs.

strings_test.go (4)

1-9: Excellent documentation update!

The expanded header comment clearly describes the test suite's purpose and coverage, including the specific optimization thresholds being tested (15-24 bytes for SWAR). This helps future maintainers understand the test design.


31-155: Comprehensive test coverage!

The test cases are exceptionally well-designed, covering:

  • Edge cases and single characters
  • Real-world HTTP methods and headers
  • SWAR optimization thresholds (15-24 bytes)
  • Position-specific variations
  • Large strings up to 256 bytes

This provides excellent coverage for the ASCII case conversion functions.


179-202: Excellent edge case coverage!

Testing all 128 ASCII values ensures complete coverage, and verifying that non-ASCII characters remain unchanged (µßäöü) confirms the functions are ASCII-only as intended.


204-254: Well-structured benchmarks with standard library comparison!

The benchmarks properly:

  • Call b.ReportAllocs() to track allocations
  • Store results to prevent compiler optimizations
  • Include standard library benchmarks for direct performance comparison

This enables accurate performance analysis of the ASCII-optimized implementations.

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@ReneWerner87
Copy link
Member

ok understand because of #119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants