-
Notifications
You must be signed in to change notification settings - Fork 395
Add support for standard numeric format strings #788
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
angularsen
merged 6 commits into
angularsen:master
from
tmilnthorp:StandardFormatStrings
May 28, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
456153e
Add support for standard double numeric format strings. Also allow up…
tmilnthorp dd720fc
Getting too fancy
tmilnthorp 043795a
Add abbreviation suffix. Add tests for custom format strings
tmilnthorp 5e8aea0
Merge branch 'master' into StandardFormatStrings
tmilnthorp 35e8462
PR requests. Better variable names.
tmilnthorp c5c20ef
Add list for valid strings. Update some doc.
tmilnthorp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// Licensed under MIT No Attribution, see LICENSE file at the root. | ||
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet. | ||
|
||
using Xunit; | ||
|
||
namespace UnitsNet.Tests | ||
{ | ||
public class QuantityFormatterTests | ||
{ | ||
[Theory] | ||
[InlineData("C")] | ||
[InlineData("C0")] | ||
[InlineData("C1")] | ||
[InlineData("C2")] | ||
[InlineData("C3")] | ||
[InlineData("C4")] | ||
[InlineData("C5")] | ||
[InlineData("C6")] | ||
[InlineData("c")] | ||
[InlineData("c0")] | ||
[InlineData("c1")] | ||
[InlineData("c2")] | ||
[InlineData("c3")] | ||
[InlineData("c4")] | ||
[InlineData("c5")] | ||
[InlineData("c6")] | ||
[InlineData("E")] | ||
[InlineData("E0")] | ||
[InlineData("E1")] | ||
[InlineData("E2")] | ||
[InlineData("E3")] | ||
[InlineData("E4")] | ||
[InlineData("E5")] | ||
[InlineData("E6")] | ||
[InlineData("e")] | ||
[InlineData("e0")] | ||
[InlineData("e1")] | ||
[InlineData("e2")] | ||
[InlineData("e3")] | ||
[InlineData("e4")] | ||
[InlineData("e5")] | ||
[InlineData("e6")] | ||
[InlineData("F")] | ||
[InlineData("F0")] | ||
[InlineData("F1")] | ||
[InlineData("F2")] | ||
[InlineData("F3")] | ||
[InlineData("F4")] | ||
[InlineData("F5")] | ||
[InlineData("F6")] | ||
[InlineData("f")] | ||
[InlineData("f0")] | ||
[InlineData("f1")] | ||
[InlineData("f2")] | ||
[InlineData("f3")] | ||
[InlineData("f4")] | ||
[InlineData("f5")] | ||
[InlineData("f6")] | ||
[InlineData("N")] | ||
[InlineData("N0")] | ||
[InlineData("N1")] | ||
[InlineData("N2")] | ||
[InlineData("N3")] | ||
[InlineData("N4")] | ||
[InlineData("N5")] | ||
[InlineData("N6")] | ||
[InlineData("n")] | ||
[InlineData("n0")] | ||
[InlineData("n1")] | ||
[InlineData("n2")] | ||
[InlineData("n3")] | ||
[InlineData("n4")] | ||
[InlineData("n5")] | ||
[InlineData("n6")] | ||
[InlineData("P")] | ||
[InlineData("P0")] | ||
[InlineData("P1")] | ||
[InlineData("P2")] | ||
[InlineData("P3")] | ||
[InlineData("P4")] | ||
[InlineData("P5")] | ||
[InlineData("P6")] | ||
[InlineData("p")] | ||
[InlineData("p0")] | ||
[InlineData("p1")] | ||
[InlineData("p2")] | ||
[InlineData("p3")] | ||
[InlineData("p4")] | ||
[InlineData("p5")] | ||
[InlineData("p6")] | ||
[InlineData("R")] | ||
[InlineData("R0")] | ||
[InlineData("R1")] | ||
[InlineData("R2")] | ||
[InlineData("R3")] | ||
[InlineData("R4")] | ||
[InlineData("R5")] | ||
[InlineData("R6")] | ||
[InlineData("r")] | ||
[InlineData("r0")] | ||
[InlineData("r1")] | ||
[InlineData("r2")] | ||
[InlineData("r3")] | ||
[InlineData("r4")] | ||
[InlineData("r5")] | ||
[InlineData("r6")] | ||
public static void StandardNumericFormatStrings_Equals_ValueWithFormatStringAndAbbreviation(string format) | ||
{ | ||
var length = Length.FromMeters(123456789.987654321); | ||
|
||
var expected = string.Format($"{{0:{format}}} {{1:a}}", length.Value, length); | ||
Assert.Equal(expected, QuantityFormatter.Format(length, format)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("000")] | ||
[InlineData("0.00")] | ||
[InlineData("#####")] | ||
[InlineData("#.##")] | ||
[InlineData("##,#")] | ||
[InlineData("#,#,,")] | ||
[InlineData("%#0.00")] | ||
[InlineData("##.0 %")] | ||
[InlineData("#0.00‰")] | ||
[InlineData("#0.0e0")] | ||
[InlineData("0.0##e+00")] | ||
[InlineData("0.0e+00")] | ||
[InlineData(@"\###00\#")] | ||
[InlineData("#0.0#;(#0.0#);-\0-")] | ||
[InlineData("#0.0#;(#0.0#)")] | ||
public static void CustomNumericFormatStrings_Equals_ValueWithFormatStringAndAbbreviation(string format) | ||
{ | ||
var length = Length.FromMeters(123456789.987654321); | ||
|
||
var expected = string.Format($"{{0:{format}}} {{1:a}}", length.Value, length); | ||
Assert.Equal(expected, QuantityFormatter.Format(length, format)); | ||
} | ||
} | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.