Skip to content

fix #1602: преобразование ЭлементСпискаЗначений в строку - #1606

Merged
EvilBeaver merged 2 commits into
EvilBeaver:developfrom
Mr-Rm:v2/fix-1602
Nov 7, 2025
Merged

fix #1602: преобразование ЭлементСпискаЗначений в строку#1606
EvilBeaver merged 2 commits into
EvilBeaver:developfrom
Mr-Rm:v2/fix-1602

Conversation

@Mr-Rm

@Mr-RmMr-Rm commented Nov 7, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Improvements

    • List elements now convert to strings using presentation format when available, with automatic fallback to default conversion when not.
  • Tests

    • Added test coverage for list element string conversion functionality.

@coderabbitai

coderabbitaiBot commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This PR adds a ToString() method override to the ValueListItem class that prefers Presentation over Value.ToString(), refactors property accessors with null-coalescing behavior, and introduces corresponding test coverage for list element string conversion.

Changes

Cohort / File(s)Summary
ValueListItem.cs refactoring
src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs
Streamlined property accessors (Presentation, Check) with expression-bodied get/set and null-coalescing; added ToString() override that prioritizes Presentation over Value.ToString() fallback
String conversion test addition
tests/value-list.os
Added new exported test procedure ТестДолжен_ПроверитьПреобразованиеЭлементаСпискаВСтроку() and registered it in the test collection builder ПолучитьСписокТестов()

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Straightforward method override with clear null-coalescing logic
  • Property accessor refactoring follows common C# patterns
  • New test is isolated and additive with no modifications to existing test logic

Poem

🐰 A string representation takes shape,
Presentation blooms, or Value won't escape,
The ToString hops with elegance true,
And tests dance along to verify too! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring 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 nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title clearly identifies the main change: adding string conversion functionality (ToString override) to the ValueListItem class, directly addressing issue #1602.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5188ef and e3fcb95.

📒 Files selected for processing (2)
  • src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs (1 hunks)
  • tests/value-list.os (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-10-01T08:10:34.187Z
Learnt from: Mr-Rm
Repo: EvilBeaver/OneScript PR: 1456
File: src/ScriptEngine/Compiler/StackMachineCodeGenerator.cs:308-308
Timestamp: 2024-10-01T08:10:34.187Z
Learning: Если метод `ToString()` обеспечивает достаточное представление константы, возможно, хранение поля `presentation` не требуется.

Applied to files:

  • src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs
🧬 Code graph analysis (1)
src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs (1)
src/ScriptEngine/Machine/ValueFactory.cs (1)
  • ValueFactory (17-175)
🔇 Additional comments (6)
src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs (4)

31-31: LGTM!

The simplification to an auto-property is appropriate and maintains the same functionality.


36-37: LGTM!

The expression-bodied syntax with null-coalescing operator correctly normalizes null values to empty strings while maintaining the same behavior.


41-41: LGTM!

The simplification to an auto-property is appropriate.


46-47: LGTM!

The expression-bodied syntax with null-coalescing operator correctly normalizes null values to undefined values via ValueFactory.Create().

tests/value-list.os (2)

22-22: LGTM!

The new test is correctly added to the test collection with consistent naming.


397-413: Excellent test coverage!

The test comprehensively covers the string conversion behavior including edge cases:

  • No presentation specified (falls back to value)
  • Empty presentation (falls back to value)
  • Undefined presentation (normalized and falls back to value)
  • Space presentation (preserved as presentation)

Comment on lines +50 to +51
public override string ToString()
=> !String.IsNullOrEmpty(_presentationHolder) ? _presentationHolder : Value.ToString();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Add null check for Value to prevent NullReferenceException.

If Value is null, calling Value.ToString() will throw a NullReferenceException. Since Value is not initialized in the constructor and is a settable property, it can be null.

Apply this diff to add a null check:

 public override string ToString()
- => !String.IsNullOrEmpty(_presentationHolder) ? _presentationHolder : Value.ToString();+ => !String.IsNullOrEmpty(_presentationHolder) ? _presentationHolder : Value?.ToString() ?? String.Empty;
📝 Committable suggestion

‼️IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
publicoverridestringToString()
=>!String.IsNullOrEmpty(_presentationHolder)?_presentationHolder:Value.ToString();
publicoverridestringToString()
=>!String.IsNullOrEmpty(_presentationHolder)?_presentationHolder:Value?.ToString()??String.Empty;
🤖 Prompt for AI Agents
In src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs around
lines 50-51, the ToString() implementation calls Value.ToString() which can
throw a NullReferenceException if Value is null; change the logic so it returns
_presentationHolder if present, otherwise if Value is non-null return
Value.ToString(), and if Value is null return an empty string (or another safe
default) to avoid the exception.

@EvilBeaver
EvilBeaver merged commit 4b3beaa into EvilBeaver:developNov 7, 2025
1 of 2 checks passed
Sign up for freeto 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.

2 participants

@Mr-Rm@EvilBeaver