Add OsChar conversions#158
Merged
Merged
Conversation
Add `TryFrom Char OsChar` and `From OsChar Char` instances, mirroring the existing `OsString` conversions. `TryFrom Char OsChar` is partial because a `Char` may not fit in a platform `OsChar` (one byte on POSIX, two on Windows); it is guarded by a round trip through `toChar` so it never silently truncates. `From OsChar Char` is total. Covered by unit tests and a hedgehog round-trip property. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR extends Witch’s conversion coverage for OsString.OsChar by adding TryFrom Char OsChar and From OsChar Char instances, aligning the API with existing OsString conversions while preventing silent truncation via a round-trip guard.
Changes:
- Add
TryFrom Char OsString.OsCharwith atoCharround-trip check to reject out-of-rangeCharvalues. - Add total
From OsString.OsChar CharusingOsString.toChar. - Add unit tests plus a Hedgehog round-trip property for the new conversions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| source/library/Witch/Instances.hs | Adds the new TryFrom/From instances for Char ↔ OsChar, including documentation about platform bounds. |
| source/test-suite/Main.hs | Adds unit tests covering the new conversions. |
| source/hedgehog/Main.hs | Adds a property test to validate tryFrom/from round-tripping (within the generated input domain). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+2486
to
+2490
| it "works" $ do | ||
| f 'a' `shouldBe` Just (OsString.unsafeFromChar 'a') | ||
| f '\xFF' `shouldBe` Just (OsString.unsafeFromChar '\xFF') | ||
| -- Above @0xFFFF@, so it fails on both POSIX and Windows. | ||
| f '\x10000' `shouldBe` Nothing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
TryFrom Char OsCharandFrom OsChar Charinstances, mirroring the existingOsStringconversions.TryFrom Char OsCharis partial because aCharmay not fit in a platformOsChar(one byte on POSIX, two on Windows); it is guarded by a round trip throughtoCharso it never silently truncates.From OsChar Charis total. Covered by unit tests and a hedgehog round-trip property.This follows up on #156.