Skip to content

Fix hashkey's inspect: "rocket" style to "colon" style #240

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

Merged
merged 2 commits into from
Jul 15, 2025

Conversation

hasumikin
Copy link
Member

This pull request introduces several changes to improve the handling of symbols, hash key formatting, and test coverage, as well as minor adjustments to the Dockerfile and test file paths. The most significant updates include enhancements to how symbols and hash keys are represented in inspect methods compatible with mruby, particularly in how it formats symbol keys.

ref mruby/mruby@baeeb5e

Enhancements to symbol and hash key handling:

  • src/c_hash.c: Updated c_hash_inspect to format hash keys differently based on their type (symbol or other types). Symbols are now displayed in a more concise format.
  • src/console.c: Added a helper function mrbc_p_sub_hashkey to format hash keys consistently when printing hashes. Updated mrbc_print_sub to use this helper function [1] [2].
  • src/symbol.c: Modified c_symbol_inspect to include quotes around symbols with colons, improving their readability.

Updates to test cases:

  • test/array_test.rb: Adjusted expected outputs in test_inspect to reflect the updated formatting of hash keys and symbols.
  • test/symbol_test.rb: Added a new test case for the inspect method to verify the formatting of symbols with colons.
  • test/div_mod_test.rb: Renamed the test class from SymbolTest to DivModTest for clarity.

Dockerfile improvements:

  • Dockerfile: Changed the git clone command to use --depth 1 for a shallow clone, reducing download size. Updated default MRUBY_CONFIG to picoruby-test for consistency.

Test file path adjustment:

  • test/0_runner.rb: Fixed the file path to picotest to ensure compatibility with the directory structure.

- Use `git clone --depth 1` in Dockerfile to speed up the build process by fetching only the latest commit.
- Adjust the `require` path in `test/0_runner.rb` to correctly locate the `picotest` library, resolving a path issue in the test environment.
This commit updates the `Hash#inspect` method to produce output that is compatible with mruby, particularly in how it formats symbol keys.

Key changes:
- Modified `c_hash.c` to use the `key: value` syntax for symbol keys in `Hash#inspect`, aligning with modern Ruby conventions and mruby's output.
- Updated `console.c` to handle the new symbol key formatting when printing hash objects.
- Adjusted `symbol.c` to correctly inspect symbols that contain colons.
- Updated related test cases in `array_test.rb` and `symbol_test.rb` to reflect the new `inspect` output.
- Fixed a minor class name typo in `div_mod_test.rb`.

Reference: mruby/mruby@baeeb5e
hasumikin added a commit to picoruby/mruby-compiler2 that referenced this pull request Jul 14, 2025
@HirohitoHigashi HirohitoHigashi merged commit ec0125a into mrubyc:master Jul 15, 2025
8 checks passed
@hasumikin hasumikin deleted the fix_hash_inspect branch July 15, 2025 04:11
hasumikin added a commit to picoruby/picoruby that referenced this pull request Jul 15, 2025
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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy