Skip to content

Conversation

@Shane32
Copy link
Owner

@Shane32 Shane32 commented Oct 6, 2025

Removes the optional creation date from the created postscript instructions. Should have no effect on output. Makes it easier for developers that want to write tests for their code that uses QRCoder to create postscript output. Also converted constants to raw string literals.

Summary by CodeRabbit

  • Bug Fixes

    • Removed timestamp from PostScript/EPS headers for stable, reproducible output across runs and platforms.
  • Refactor

    • Streamlined PostScript generation internals without altering behavior or public APIs.
  • Tests

    • Updated approval tests to align with deterministic PostScript/EPS output.

@Shane32 Shane32 self-assigned this Oct 6, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 6, 2025

📝 Walkthrough

Walkthrough

Refactors PostScript generation in QRCoder/PostscriptQRCode.cs to remove date/time from headers, reformat header/functions via multiline strings with reordered placeholders, and adjust call sites accordingly. Updates tests to remove date-stripping helper and assert directly against approved outputs. Public API remains unchanged.

Changes

Cohort / File(s) Summary
PostScript generation refactor
QRCoder/PostscriptQRCode.cs
Reworked PS header/functions/footer using multiline string literals; removed DateTime from header; adjusted placeholder ordering and string.Format arguments (width, points/module, EPS token, drawable module count); added cross-platform line-ending comments; no public API changes.
Tests: approval alignment
QRCoderTests/PostscriptQRCodeRendererTests.cs
Replaced RemoveCreationDate helper usage with direct ShouldMatchApproved assertions; removed the private Regex-based helper; no public API changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • gfoidl

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% 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 succinctly captures the core change of making the PostScript output deterministic by removing the creation date and aligns directly with the modifications and PR objectives. It uses clear, concise language without unnecessary detail and accurately reflects the main change.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch postscript-determinstic

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.

private const string PS_HEADER = @"%!PS-Adobe-3.0 {3}
%%Creator: QRCoder.NET
%%Title: QRCode
%%CreationDate: {0}
Copy link
Owner Author

@Shane32 Shane32 Oct 6, 2025

Choose a reason for hiding this comment

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

This "CreationDate" line is the only removed line; the constant is otherwise identical. (although {1} becomes {0} etc)

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: 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 3deb235 and 5dfb6c3.

📒 Files selected for processing (2)
  • QRCoder/PostscriptQRCode.cs (2 hunks)
  • QRCoderTests/PostscriptQRCodeRendererTests.cs (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Test .NET Core 3.1
  • GitHub Check: Test .NET Framework 4.6.2
  • GitHub Check: Test .NET 5.0
  • GitHub Check: additional-tests
  • GitHub Check: Test .NET 6.0 Windows
  • GitHub Check: Test .NET 5.0 Windows
  • GitHub Check: Test .NET 6.0
  • GitHub Check: Test .NET Core 2.1
🔇 Additional comments (9)
QRCoder/PostscriptQRCode.cs (4)

103-106: LGTM! Date parameter correctly removed.

The format call has been updated to remove the DateTime.Now parameter, achieving the goal of deterministic output. The placeholder indices {0}, {1}, {2} correctly map to width, pointsPerModule, and EPSF string respectively.


135-155: LGTM! PS_HEADER format string is correct.

The raw string literal format is clean and the placeholder indices are correctly positioned:

  • {2} for EPSF version token (line 136)
  • {0} for width/size values (lines 141, 142, 148)
  • {1} for scale/pointsPerModule (line 149)

157-193: LGTM! PS_FUNCTIONS format string is correct.

The raw string literal format is clean and all placeholders {0}-{6} are correctly positioned for RGB colors and module count.


195-201: LGTM! PS_FOOTER format string is correct.

The raw string literal format is clean and requires no placeholders.

QRCoderTests/PostscriptQRCodeRendererTests.cs (5)

12-12: LGTM! Test simplified correctly.

The test now directly asserts against approved output since the production code no longer includes a creation date, eliminating the need for the RemoveCreationDate helper.


22-22: LGTM! Test simplified correctly.

Consistent with the removal of date-dependent output from the PostScript generator.


32-32: LGTM! Test simplified correctly.

Consistent with the removal of date-dependent output from the PostScript generator.


42-42: LGTM! Test simplified correctly.

Consistent with the removal of date-dependent output from the PostScript generator.


52-52: LGTM! Test simplified correctly.

Consistent with the removal of date-dependent output from the PostScript generator.

Comment on lines +133 to +134
// Note: line terminations here will encode differently based on which platform QRCoder was compiled on (CRLF vs LF);
// however, PostScript interpreters should handle both equally well.
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Verify cross-platform test determinism.

The comment correctly notes that line terminations will differ based on compilation platform (CRLF on Windows, LF on Unix). While PostScript interpreters handle both, this could cause approval test failures when developers compile on different platforms and the tests perform exact string comparisons.

Consider one of these approaches:

  1. Normalize line endings in the generated PostScript to always use LF (more deterministic)
  2. Update approval tests to ignore line ending differences
  3. Document that developers should use consistent line endings in their development environment

Run this script to check how the approval tests handle line ending differences:


🏁 Script executed:

#!/bin/bash
# Check if approval tests normalize line endings

# Search for the ShouldMatchApproved implementation and configuration
rg -n "ShouldMatchApproved|NoDiff" --type cs -A 5 -B 5

# Look for any line ending normalization in test utilities
rg -n "LineEnding|CRLF|\\\\r\\\\n|normalize" --type cs

Length of output: 66105


Ensure deterministic LF line endings in PostScript output
Approval tests use exact NoDiff comparisons, so CRLF vs LF variations break on different platforms.

  • Normalize GetGraphic to emit LF-only line endings
  • Update PostscriptQRCodeRendererTests to ignore CRLF/LF differences
🤖 Prompt for AI Agents
In QRCoder/PostscriptQRCode.cs around lines 133-134, the PostScript output
currently may contain platform-dependent CRLF line endings; modify GetGraphic so
it deterministically returns LF-only line endings by normalizing the final
string (replace "\r\n" and any lone "\r" with "\n") before returning; also
update PostscriptQRCodeRendererTests to either compare normalized strings
(replace CRLF with LF on both expected and actual) or use a test helper that
normalizes line endings so comparisons ignore CRLF vs LF differences.

var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L);
var ps = new PostscriptQRCode(data).GetGraphic(5);
RemoveCreationDate(ps).ShouldMatchApproved(x => x.NoDiff());
ps.ShouldMatchApproved(x => x.NoDiff());
Copy link
Owner Author

Choose a reason for hiding this comment

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

Tests previously removed the creation date from the verified files. So all tests continue to match with no change to test result data.

@Shane32 Shane32 requested a review from gfoidl October 6, 2025 04:39
@Shane32 Shane32 added this to the 1.7.0 milestone Oct 6, 2025
@Shane32 Shane32 mentioned this pull request Oct 6, 2025
@Shane32 Shane32 merged commit 8d2217c into master Oct 6, 2025
10 checks passed
@Shane32 Shane32 deleted the postscript-determinstic branch October 6, 2025 11:56
@Shane32 Shane32 added the enhancement A new feature or feature request label Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A new feature or feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants