diff --git a/Common/UnitDefinitions/Volume.json b/Common/UnitDefinitions/Volume.json index 6abde4c0d0..60734a1b7d 100644 --- a/Common/UnitDefinitions/Volume.json +++ b/Common/UnitDefinitions/Volume.json @@ -329,15 +329,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [] - }, - { - "Culture": "ru-RU", - "Abbreviations": [] - }, - { - "Culture": "nb-NO", - "Abbreviations": [] + "Abbreviations": [ "tablespoon (U.S.)" ] } ] }, @@ -351,15 +343,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [] - }, - { - "Culture": "ru-RU", - "Abbreviations": [] - }, - { - "Culture": "nb-NO", - "Abbreviations": [] + "Abbreviations": [ "tablespoon (A.U.)" ] } ] }, @@ -373,15 +357,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [] - }, - { - "Culture": "ru-RU", - "Abbreviations": [] - }, - { - "Culture": "nb-NO", - "Abbreviations": [] + "Abbreviations": [ "tablespoon (U.K.)" ] } ] }, @@ -396,14 +372,6 @@ { "Culture": "en-US", "Abbreviations": [ "tsp", "t", "ts", "tspn", "t.", "ts.", "tsp.", "tspn.", "teaspoon" ] - }, - { - "Culture": "ru-RU", - "Abbreviations": [] - }, - { - "Culture": "nb-NO", - "Abbreviations": [] } ] }, @@ -417,15 +385,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [] - }, - { - "Culture": "ru-RU", - "Abbreviations": [] - }, - { - "Culture": "nb-NO", - "Abbreviations": [] + "Abbreviations": [ "teaspoon (U.S.)" ] } ] }, @@ -439,7 +399,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [] + "Abbreviations": [ "metric cup" ] } ] }, @@ -453,7 +413,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [] + "Abbreviations": ["cup (U.S. customary)"] } ] }, @@ -467,7 +427,7 @@ "Localization": [ { "Culture": "en-US", - "Abbreviations": [] + "Abbreviations": ["cup (U.S.)"] } ] }, diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs index ae35867748..849af02b43 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs @@ -821,6 +821,13 @@ public void Parse() Assert.Equal(VolumeUnit.AcreFoot, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = Volume.Parse("1 tablespoon (A.U.)", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.AuTablespoons, AuTablespoonsTolerance); + Assert.Equal(VolumeUnit.AuTablespoon, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = Volume.Parse("1 bf", CultureInfo.GetCultureInfo("en-US")); @@ -1353,6 +1360,13 @@ public void Parse() Assert.Equal(VolumeUnit.MegausGallon, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = Volume.Parse("1 metric cup", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.MetricCups, MetricCupsTolerance); + Assert.Equal(VolumeUnit.MetricCup, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = Volume.Parse("1 tsp", CultureInfo.GetCultureInfo("en-US")); @@ -1465,6 +1479,13 @@ public void Parse() Assert.Equal(VolumeUnit.OilBarrel, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = Volume.Parse("1 tablespoon (U.K.)", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.UkTablespoons, UkTablespoonsTolerance); + Assert.Equal(VolumeUnit.UkTablespoon, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = Volume.Parse("1 bl (U.S.)", CultureInfo.GetCultureInfo("en-US")); @@ -1472,6 +1493,13 @@ public void Parse() Assert.Equal(VolumeUnit.UsBeerBarrel, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = Volume.Parse("1 cup (U.S. customary)", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.UsCustomaryCups, UsCustomaryCupsTolerance); + Assert.Equal(VolumeUnit.UsCustomaryCup, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = Volume.Parse("1 gal (U.S.)", CultureInfo.GetCultureInfo("en-US")); @@ -1486,6 +1514,13 @@ public void Parse() Assert.Equal(VolumeUnit.UsGallon, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = Volume.Parse("1 cup (U.S.)", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.UsLegalCups, UsLegalCupsTolerance); + Assert.Equal(VolumeUnit.UsLegalCup, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try { var parsed = Volume.Parse("1 oz (U.S.)", CultureInfo.GetCultureInfo("en-US")); @@ -1514,6 +1549,20 @@ public void Parse() Assert.Equal(VolumeUnit.UsQuart, parsed.Unit); } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + try + { + var parsed = Volume.Parse("1 tablespoon (U.S.)", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.UsTablespoons, UsTablespoonsTolerance); + Assert.Equal(VolumeUnit.UsTablespoon, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + + try + { + var parsed = Volume.Parse("1 teaspoon (U.S.)", CultureInfo.GetCultureInfo("en-US")); + AssertEx.EqualTolerance(1, parsed.UsTeaspoons, UsTeaspoonsTolerance); + Assert.Equal(VolumeUnit.UsTeaspoon, parsed.Unit); + } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + } [Fact] @@ -1537,6 +1586,12 @@ public void TryParse() Assert.Equal(VolumeUnit.AcreFoot, parsed.Unit); } + { + Assert.True(Volume.TryParse("1 tablespoon (A.U.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.AuTablespoons, AuTablespoonsTolerance); + Assert.Equal(VolumeUnit.AuTablespoon, parsed.Unit); + } + { Assert.True(Volume.TryParse("1 bf", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.BoardFeet, BoardFeetTolerance); @@ -1933,6 +1988,12 @@ public void TryParse() Assert.Equal(VolumeUnit.MegausGallon, parsed.Unit); } + { + Assert.True(Volume.TryParse("1 metric cup", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.MetricCups, MetricCupsTolerance); + Assert.Equal(VolumeUnit.MetricCup, parsed.Unit); + } + { Assert.True(Volume.TryParse("1 tsp", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.MetricTeaspoons, MetricTeaspoonsTolerance); @@ -2017,12 +2078,24 @@ public void TryParse() Assert.Equal(VolumeUnit.OilBarrel, parsed.Unit); } + { + Assert.True(Volume.TryParse("1 tablespoon (U.K.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.UkTablespoons, UkTablespoonsTolerance); + Assert.Equal(VolumeUnit.UkTablespoon, parsed.Unit); + } + { Assert.True(Volume.TryParse("1 bl (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.UsBeerBarrels, UsBeerBarrelsTolerance); Assert.Equal(VolumeUnit.UsBeerBarrel, parsed.Unit); } + { + Assert.True(Volume.TryParse("1 cup (U.S. customary)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.UsCustomaryCups, UsCustomaryCupsTolerance); + Assert.Equal(VolumeUnit.UsCustomaryCup, parsed.Unit); + } + { Assert.True(Volume.TryParse("1 gal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.UsGallons, UsGallonsTolerance); @@ -2035,6 +2108,12 @@ public void TryParse() Assert.Equal(VolumeUnit.UsGallon, parsed.Unit); } + { + Assert.True(Volume.TryParse("1 cup (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.UsLegalCups, UsLegalCupsTolerance); + Assert.Equal(VolumeUnit.UsLegalCup, parsed.Unit); + } + { Assert.True(Volume.TryParse("1 oz (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); AssertEx.EqualTolerance(1, parsed.UsOunces, UsOuncesTolerance); @@ -2059,12 +2138,25 @@ public void TryParse() Assert.Equal(VolumeUnit.UsQuart, parsed.Unit); } + { + Assert.True(Volume.TryParse("1 tablespoon (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.UsTablespoons, UsTablespoonsTolerance); + Assert.Equal(VolumeUnit.UsTablespoon, parsed.Unit); + } + + { + Assert.True(Volume.TryParse("1 teaspoon (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsed)); + AssertEx.EqualTolerance(1, parsed.UsTeaspoons, UsTeaspoonsTolerance); + Assert.Equal(VolumeUnit.UsTeaspoon, parsed.Unit); + } + } [Theory] [InlineData("ac-ft", VolumeUnit.AcreFoot)] [InlineData("acre-foot", VolumeUnit.AcreFoot)] [InlineData("acre-feet", VolumeUnit.AcreFoot)] + [InlineData("tablespoon (A.U.)", VolumeUnit.AuTablespoon)] [InlineData("bf", VolumeUnit.BoardFoot)] [InlineData("board foot", VolumeUnit.BoardFoot)] [InlineData("board feet", VolumeUnit.BoardFoot)] @@ -2102,6 +2194,7 @@ public void TryParse() [InlineData("Mgal (imp.)", VolumeUnit.MegaimperialGallon)] [InlineData("Ml", VolumeUnit.Megaliter)] [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("metric cup", VolumeUnit.MetricCup)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2115,11 +2208,16 @@ public void TryParse() [InlineData("ml", VolumeUnit.Milliliter)] [InlineData("nl", VolumeUnit.Nanoliter)] [InlineData("bbl", VolumeUnit.OilBarrel)] + [InlineData("tablespoon (U.K.)", VolumeUnit.UkTablespoon)] [InlineData("bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("cup (U.S. customary)", VolumeUnit.UsCustomaryCup)] [InlineData("gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("cup (U.S.)", VolumeUnit.UsLegalCup)] [InlineData("oz (U.S.)", VolumeUnit.UsOunce)] [InlineData("pt (U.S.)", VolumeUnit.UsPint)] [InlineData("qt (U.S.)", VolumeUnit.UsQuart)] + [InlineData("tablespoon (U.S.)", VolumeUnit.UsTablespoon)] + [InlineData("teaspoon (U.S.)", VolumeUnit.UsTeaspoon)] public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeUnit expectedUnit) { // Fallback culture "en-US" is always localized @@ -2132,6 +2230,7 @@ public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeUni [InlineData("ac-ft", VolumeUnit.AcreFoot)] [InlineData("acre-foot", VolumeUnit.AcreFoot)] [InlineData("acre-feet", VolumeUnit.AcreFoot)] + [InlineData("tablespoon (A.U.)", VolumeUnit.AuTablespoon)] [InlineData("bf", VolumeUnit.BoardFoot)] [InlineData("board foot", VolumeUnit.BoardFoot)] [InlineData("board feet", VolumeUnit.BoardFoot)] @@ -2169,6 +2268,7 @@ public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeUni [InlineData("Mgal (imp.)", VolumeUnit.MegaimperialGallon)] [InlineData("Ml", VolumeUnit.Megaliter)] [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("metric cup", VolumeUnit.MetricCup)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2182,11 +2282,16 @@ public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeUni [InlineData("ml", VolumeUnit.Milliliter)] [InlineData("nl", VolumeUnit.Nanoliter)] [InlineData("bbl", VolumeUnit.OilBarrel)] + [InlineData("tablespoon (U.K.)", VolumeUnit.UkTablespoon)] [InlineData("bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("cup (U.S. customary)", VolumeUnit.UsCustomaryCup)] [InlineData("gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("cup (U.S.)", VolumeUnit.UsLegalCup)] [InlineData("oz (U.S.)", VolumeUnit.UsOunce)] [InlineData("pt (U.S.)", VolumeUnit.UsPint)] [InlineData("qt (U.S.)", VolumeUnit.UsQuart)] + [InlineData("tablespoon (U.S.)", VolumeUnit.UsTablespoon)] + [InlineData("teaspoon (U.S.)", VolumeUnit.UsTeaspoon)] public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumeUnit expectedUnit) { // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. @@ -2199,6 +2304,7 @@ public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string [InlineData("en-US", "ac-ft", VolumeUnit.AcreFoot)] [InlineData("en-US", "acre-foot", VolumeUnit.AcreFoot)] [InlineData("en-US", "acre-feet", VolumeUnit.AcreFoot)] + [InlineData("en-US", "tablespoon (A.U.)", VolumeUnit.AuTablespoon)] [InlineData("en-US", "bf", VolumeUnit.BoardFoot)] [InlineData("en-US", "board foot", VolumeUnit.BoardFoot)] [InlineData("en-US", "board feet", VolumeUnit.BoardFoot)] @@ -2236,6 +2342,7 @@ public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string [InlineData("en-US", "Mgal (imp.)", VolumeUnit.MegaimperialGallon)] [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("en-US", "metric cup", VolumeUnit.MetricCup)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] @@ -2249,11 +2356,19 @@ public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string [InlineData("en-US", "ml", VolumeUnit.Milliliter)] [InlineData("en-US", "nl", VolumeUnit.Nanoliter)] [InlineData("en-US", "bbl", VolumeUnit.OilBarrel)] + [InlineData("en-US", "tablespoon (U.K.)", VolumeUnit.UkTablespoon)] [InlineData("en-US", "bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("en-US", "cup (U.S. customary)", VolumeUnit.UsCustomaryCup)] [InlineData("en-US", "gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("en-US", "cup (U.S.)", VolumeUnit.UsLegalCup)] [InlineData("en-US", "oz (U.S.)", VolumeUnit.UsOunce)] [InlineData("en-US", "pt (U.S.)", VolumeUnit.UsPint)] [InlineData("en-US", "qt (U.S.)", VolumeUnit.UsQuart)] + [InlineData("en-US", "tablespoon (U.S.)", VolumeUnit.UsTablespoon)] + [InlineData("en-US", "teaspoon (U.S.)", VolumeUnit.UsTeaspoon)] + [InlineData("fr-CA", "pmp", VolumeUnit.BoardFoot)] + [InlineData("fr-CA", "pied-planche", VolumeUnit.BoardFoot)] + [InlineData("fr-CA", "pied de planche", VolumeUnit.BoardFoot)] [InlineData("ru-RU", "сл", VolumeUnit.Centiliter)] [InlineData("ru-RU", "см³", VolumeUnit.CubicCentimeter)] [InlineData("ru-RU", "дм³", VolumeUnit.CubicDecimeter)] @@ -2287,9 +2402,6 @@ public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string [InlineData("ru-RU", "нл", VolumeUnit.Nanoliter)] [InlineData("ru-RU", "Американский галлон", VolumeUnit.UsGallon)] [InlineData("ru-RU", "Американская унция", VolumeUnit.UsOunce)] - [InlineData("fr-CA", "pmp", VolumeUnit.BoardFoot)] - [InlineData("fr-CA", "pied-planche", VolumeUnit.BoardFoot)] - [InlineData("fr-CA", "pied de planche", VolumeUnit.BoardFoot)] public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumeUnit expectedUnit) { using var _ = new CultureScope(culture); @@ -2301,6 +2413,7 @@ public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, Vo [InlineData("en-US", "ac-ft", VolumeUnit.AcreFoot)] [InlineData("en-US", "acre-foot", VolumeUnit.AcreFoot)] [InlineData("en-US", "acre-feet", VolumeUnit.AcreFoot)] + [InlineData("en-US", "tablespoon (A.U.)", VolumeUnit.AuTablespoon)] [InlineData("en-US", "bf", VolumeUnit.BoardFoot)] [InlineData("en-US", "board foot", VolumeUnit.BoardFoot)] [InlineData("en-US", "board feet", VolumeUnit.BoardFoot)] @@ -2338,6 +2451,7 @@ public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, Vo [InlineData("en-US", "Mgal (imp.)", VolumeUnit.MegaimperialGallon)] [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("en-US", "metric cup", VolumeUnit.MetricCup)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] @@ -2351,11 +2465,19 @@ public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, Vo [InlineData("en-US", "ml", VolumeUnit.Milliliter)] [InlineData("en-US", "nl", VolumeUnit.Nanoliter)] [InlineData("en-US", "bbl", VolumeUnit.OilBarrel)] + [InlineData("en-US", "tablespoon (U.K.)", VolumeUnit.UkTablespoon)] [InlineData("en-US", "bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("en-US", "cup (U.S. customary)", VolumeUnit.UsCustomaryCup)] [InlineData("en-US", "gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("en-US", "cup (U.S.)", VolumeUnit.UsLegalCup)] [InlineData("en-US", "oz (U.S.)", VolumeUnit.UsOunce)] [InlineData("en-US", "pt (U.S.)", VolumeUnit.UsPint)] [InlineData("en-US", "qt (U.S.)", VolumeUnit.UsQuart)] + [InlineData("en-US", "tablespoon (U.S.)", VolumeUnit.UsTablespoon)] + [InlineData("en-US", "teaspoon (U.S.)", VolumeUnit.UsTeaspoon)] + [InlineData("fr-CA", "pmp", VolumeUnit.BoardFoot)] + [InlineData("fr-CA", "pied-planche", VolumeUnit.BoardFoot)] + [InlineData("fr-CA", "pied de planche", VolumeUnit.BoardFoot)] [InlineData("ru-RU", "сл", VolumeUnit.Centiliter)] [InlineData("ru-RU", "см³", VolumeUnit.CubicCentimeter)] [InlineData("ru-RU", "дм³", VolumeUnit.CubicDecimeter)] @@ -2389,9 +2511,6 @@ public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, Vo [InlineData("ru-RU", "нл", VolumeUnit.Nanoliter)] [InlineData("ru-RU", "Американский галлон", VolumeUnit.UsGallon)] [InlineData("ru-RU", "Американская унция", VolumeUnit.UsOunce)] - [InlineData("fr-CA", "pmp", VolumeUnit.BoardFoot)] - [InlineData("fr-CA", "pied-planche", VolumeUnit.BoardFoot)] - [InlineData("fr-CA", "pied de planche", VolumeUnit.BoardFoot)] public void ParseUnit_WithCulture(string culture, string abbreviation, VolumeUnit expectedUnit) { VolumeUnit parsedUnit = Volume.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); @@ -2412,6 +2531,7 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati [InlineData("ac-ft", VolumeUnit.AcreFoot)] [InlineData("acre-foot", VolumeUnit.AcreFoot)] [InlineData("acre-feet", VolumeUnit.AcreFoot)] + [InlineData("tablespoon (A.U.)", VolumeUnit.AuTablespoon)] [InlineData("bf", VolumeUnit.BoardFoot)] [InlineData("board foot", VolumeUnit.BoardFoot)] [InlineData("board feet", VolumeUnit.BoardFoot)] @@ -2449,6 +2569,7 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati [InlineData("Mgal (imp.)", VolumeUnit.MegaimperialGallon)] [InlineData("Ml", VolumeUnit.Megaliter)] [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("metric cup", VolumeUnit.MetricCup)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2462,11 +2583,16 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati [InlineData("ml", VolumeUnit.Milliliter)] [InlineData("nl", VolumeUnit.Nanoliter)] [InlineData("bbl", VolumeUnit.OilBarrel)] + [InlineData("tablespoon (U.K.)", VolumeUnit.UkTablespoon)] [InlineData("bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("cup (U.S. customary)", VolumeUnit.UsCustomaryCup)] [InlineData("gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("cup (U.S.)", VolumeUnit.UsLegalCup)] [InlineData("oz (U.S.)", VolumeUnit.UsOunce)] [InlineData("pt (U.S.)", VolumeUnit.UsPint)] [InlineData("qt (U.S.)", VolumeUnit.UsQuart)] + [InlineData("tablespoon (U.S.)", VolumeUnit.UsTablespoon)] + [InlineData("teaspoon (U.S.)", VolumeUnit.UsTeaspoon)] public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeUnit expectedUnit) { // Fallback culture "en-US" is always localized @@ -2479,6 +2605,7 @@ public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, Volume [InlineData("ac-ft", VolumeUnit.AcreFoot)] [InlineData("acre-foot", VolumeUnit.AcreFoot)] [InlineData("acre-feet", VolumeUnit.AcreFoot)] + [InlineData("tablespoon (A.U.)", VolumeUnit.AuTablespoon)] [InlineData("bf", VolumeUnit.BoardFoot)] [InlineData("board foot", VolumeUnit.BoardFoot)] [InlineData("board feet", VolumeUnit.BoardFoot)] @@ -2516,6 +2643,7 @@ public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, Volume [InlineData("Mgal (imp.)", VolumeUnit.MegaimperialGallon)] [InlineData("Ml", VolumeUnit.Megaliter)] [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("metric cup", VolumeUnit.MetricCup)] [InlineData("tsp", VolumeUnit.MetricTeaspoon)] [InlineData("t", VolumeUnit.MetricTeaspoon)] [InlineData("ts", VolumeUnit.MetricTeaspoon)] @@ -2529,11 +2657,16 @@ public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, Volume [InlineData("ml", VolumeUnit.Milliliter)] [InlineData("nl", VolumeUnit.Nanoliter)] [InlineData("bbl", VolumeUnit.OilBarrel)] + [InlineData("tablespoon (U.K.)", VolumeUnit.UkTablespoon)] [InlineData("bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("cup (U.S. customary)", VolumeUnit.UsCustomaryCup)] [InlineData("gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("cup (U.S.)", VolumeUnit.UsLegalCup)] [InlineData("oz (U.S.)", VolumeUnit.UsOunce)] [InlineData("pt (U.S.)", VolumeUnit.UsPint)] [InlineData("qt (U.S.)", VolumeUnit.UsQuart)] + [InlineData("tablespoon (U.S.)", VolumeUnit.UsTablespoon)] + [InlineData("teaspoon (U.S.)", VolumeUnit.UsTeaspoon)] public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumeUnit expectedUnit) { // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. @@ -2546,6 +2679,7 @@ public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(stri [InlineData("en-US", "ac-ft", VolumeUnit.AcreFoot)] [InlineData("en-US", "acre-foot", VolumeUnit.AcreFoot)] [InlineData("en-US", "acre-feet", VolumeUnit.AcreFoot)] + [InlineData("en-US", "tablespoon (A.U.)", VolumeUnit.AuTablespoon)] [InlineData("en-US", "bf", VolumeUnit.BoardFoot)] [InlineData("en-US", "board foot", VolumeUnit.BoardFoot)] [InlineData("en-US", "board feet", VolumeUnit.BoardFoot)] @@ -2583,6 +2717,7 @@ public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(stri [InlineData("en-US", "Mgal (imp.)", VolumeUnit.MegaimperialGallon)] [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("en-US", "metric cup", VolumeUnit.MetricCup)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] @@ -2596,11 +2731,19 @@ public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(stri [InlineData("en-US", "ml", VolumeUnit.Milliliter)] [InlineData("en-US", "nl", VolumeUnit.Nanoliter)] [InlineData("en-US", "bbl", VolumeUnit.OilBarrel)] + [InlineData("en-US", "tablespoon (U.K.)", VolumeUnit.UkTablespoon)] [InlineData("en-US", "bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("en-US", "cup (U.S. customary)", VolumeUnit.UsCustomaryCup)] [InlineData("en-US", "gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("en-US", "cup (U.S.)", VolumeUnit.UsLegalCup)] [InlineData("en-US", "oz (U.S.)", VolumeUnit.UsOunce)] [InlineData("en-US", "pt (U.S.)", VolumeUnit.UsPint)] [InlineData("en-US", "qt (U.S.)", VolumeUnit.UsQuart)] + [InlineData("en-US", "tablespoon (U.S.)", VolumeUnit.UsTablespoon)] + [InlineData("en-US", "teaspoon (U.S.)", VolumeUnit.UsTeaspoon)] + [InlineData("fr-CA", "pmp", VolumeUnit.BoardFoot)] + [InlineData("fr-CA", "pied-planche", VolumeUnit.BoardFoot)] + [InlineData("fr-CA", "pied de planche", VolumeUnit.BoardFoot)] [InlineData("ru-RU", "сл", VolumeUnit.Centiliter)] [InlineData("ru-RU", "см³", VolumeUnit.CubicCentimeter)] [InlineData("ru-RU", "дм³", VolumeUnit.CubicDecimeter)] @@ -2634,9 +2777,6 @@ public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(stri [InlineData("ru-RU", "нл", VolumeUnit.Nanoliter)] [InlineData("ru-RU", "Американский галлон", VolumeUnit.UsGallon)] [InlineData("ru-RU", "Американская унция", VolumeUnit.UsOunce)] - [InlineData("fr-CA", "pmp", VolumeUnit.BoardFoot)] - [InlineData("fr-CA", "pied-planche", VolumeUnit.BoardFoot)] - [InlineData("fr-CA", "pied de planche", VolumeUnit.BoardFoot)] public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumeUnit expectedUnit) { using var _ = new CultureScope(culture); @@ -2648,6 +2788,7 @@ public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, [InlineData("en-US", "ac-ft", VolumeUnit.AcreFoot)] [InlineData("en-US", "acre-foot", VolumeUnit.AcreFoot)] [InlineData("en-US", "acre-feet", VolumeUnit.AcreFoot)] + [InlineData("en-US", "tablespoon (A.U.)", VolumeUnit.AuTablespoon)] [InlineData("en-US", "bf", VolumeUnit.BoardFoot)] [InlineData("en-US", "board foot", VolumeUnit.BoardFoot)] [InlineData("en-US", "board feet", VolumeUnit.BoardFoot)] @@ -2685,6 +2826,7 @@ public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, [InlineData("en-US", "Mgal (imp.)", VolumeUnit.MegaimperialGallon)] [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("en-US", "metric cup", VolumeUnit.MetricCup)] [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] @@ -2698,11 +2840,19 @@ public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, [InlineData("en-US", "ml", VolumeUnit.Milliliter)] [InlineData("en-US", "nl", VolumeUnit.Nanoliter)] [InlineData("en-US", "bbl", VolumeUnit.OilBarrel)] + [InlineData("en-US", "tablespoon (U.K.)", VolumeUnit.UkTablespoon)] [InlineData("en-US", "bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("en-US", "cup (U.S. customary)", VolumeUnit.UsCustomaryCup)] [InlineData("en-US", "gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("en-US", "cup (U.S.)", VolumeUnit.UsLegalCup)] [InlineData("en-US", "oz (U.S.)", VolumeUnit.UsOunce)] [InlineData("en-US", "pt (U.S.)", VolumeUnit.UsPint)] [InlineData("en-US", "qt (U.S.)", VolumeUnit.UsQuart)] + [InlineData("en-US", "tablespoon (U.S.)", VolumeUnit.UsTablespoon)] + [InlineData("en-US", "teaspoon (U.S.)", VolumeUnit.UsTeaspoon)] + [InlineData("fr-CA", "pmp", VolumeUnit.BoardFoot)] + [InlineData("fr-CA", "pied-planche", VolumeUnit.BoardFoot)] + [InlineData("fr-CA", "pied de planche", VolumeUnit.BoardFoot)] [InlineData("ru-RU", "сл", VolumeUnit.Centiliter)] [InlineData("ru-RU", "см³", VolumeUnit.CubicCentimeter)] [InlineData("ru-RU", "дм³", VolumeUnit.CubicDecimeter)] @@ -2736,9 +2886,6 @@ public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, [InlineData("ru-RU", "нл", VolumeUnit.Nanoliter)] [InlineData("ru-RU", "Американский галлон", VolumeUnit.UsGallon)] [InlineData("ru-RU", "Американская унция", VolumeUnit.UsOunce)] - [InlineData("fr-CA", "pmp", VolumeUnit.BoardFoot)] - [InlineData("fr-CA", "pied-planche", VolumeUnit.BoardFoot)] - [InlineData("fr-CA", "pied de planche", VolumeUnit.BoardFoot)] public void TryParseUnit_WithCulture(string culture, string abbreviation, VolumeUnit expectedUnit) { Assert.True(Volume.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumeUnit parsedUnit)); @@ -3022,7 +3169,7 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() { using var _ = new CultureScope("en-US"); Assert.Equal("1 ac-ft", new Volume(1, VolumeUnit.AcreFoot).ToString()); - Assert.Equal("1", new Volume(1, VolumeUnit.AuTablespoon).ToString()); + Assert.Equal("1 tablespoon (A.U.)", new Volume(1, VolumeUnit.AuTablespoon).ToString()); Assert.Equal("1 bf", new Volume(1, VolumeUnit.BoardFoot).ToString()); Assert.Equal("1 cl", new Volume(1, VolumeUnit.Centiliter).ToString()); Assert.Equal("1 cm³", new Volume(1, VolumeUnit.CubicCentimeter).ToString()); @@ -3059,22 +3206,22 @@ public void ToString_ReturnsValueAndUnitAbbreviationInCurrentCulture() Assert.Equal("1 Mgal (imp.)", new Volume(1, VolumeUnit.MegaimperialGallon).ToString()); Assert.Equal("1 Ml", new Volume(1, VolumeUnit.Megaliter).ToString()); Assert.Equal("1 Mgal (U.S.)", new Volume(1, VolumeUnit.MegausGallon).ToString()); - Assert.Equal("1", new Volume(1, VolumeUnit.MetricCup).ToString()); + Assert.Equal("1 metric cup", new Volume(1, VolumeUnit.MetricCup).ToString()); Assert.Equal("1 tsp", new Volume(1, VolumeUnit.MetricTeaspoon).ToString()); Assert.Equal("1 µl", new Volume(1, VolumeUnit.Microliter).ToString()); Assert.Equal("1 ml", new Volume(1, VolumeUnit.Milliliter).ToString()); Assert.Equal("1 nl", new Volume(1, VolumeUnit.Nanoliter).ToString()); Assert.Equal("1 bbl", new Volume(1, VolumeUnit.OilBarrel).ToString()); - Assert.Equal("1", new Volume(1, VolumeUnit.UkTablespoon).ToString()); + Assert.Equal("1 tablespoon (U.K.)", new Volume(1, VolumeUnit.UkTablespoon).ToString()); Assert.Equal("1 bl (U.S.)", new Volume(1, VolumeUnit.UsBeerBarrel).ToString()); - Assert.Equal("1", new Volume(1, VolumeUnit.UsCustomaryCup).ToString()); + Assert.Equal("1 cup (U.S. customary)", new Volume(1, VolumeUnit.UsCustomaryCup).ToString()); Assert.Equal("1 gal (U.S.)", new Volume(1, VolumeUnit.UsGallon).ToString()); - Assert.Equal("1", new Volume(1, VolumeUnit.UsLegalCup).ToString()); + Assert.Equal("1 cup (U.S.)", new Volume(1, VolumeUnit.UsLegalCup).ToString()); Assert.Equal("1 oz (U.S.)", new Volume(1, VolumeUnit.UsOunce).ToString()); Assert.Equal("1 pt (U.S.)", new Volume(1, VolumeUnit.UsPint).ToString()); Assert.Equal("1 qt (U.S.)", new Volume(1, VolumeUnit.UsQuart).ToString()); - Assert.Equal("1", new Volume(1, VolumeUnit.UsTablespoon).ToString()); - Assert.Equal("1", new Volume(1, VolumeUnit.UsTeaspoon).ToString()); + Assert.Equal("1 tablespoon (U.S.)", new Volume(1, VolumeUnit.UsTablespoon).ToString()); + Assert.Equal("1 teaspoon (U.S.)", new Volume(1, VolumeUnit.UsTeaspoon).ToString()); } [Fact] @@ -3084,7 +3231,7 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture var swedishCulture = CultureInfo.GetCultureInfo("sv-SE"); Assert.Equal("1 ac-ft", new Volume(1, VolumeUnit.AcreFoot).ToString(swedishCulture)); - Assert.Equal("1", new Volume(1, VolumeUnit.AuTablespoon).ToString(swedishCulture)); + Assert.Equal("1 tablespoon (A.U.)", new Volume(1, VolumeUnit.AuTablespoon).ToString(swedishCulture)); Assert.Equal("1 bf", new Volume(1, VolumeUnit.BoardFoot).ToString(swedishCulture)); Assert.Equal("1 cl", new Volume(1, VolumeUnit.Centiliter).ToString(swedishCulture)); Assert.Equal("1 cm³", new Volume(1, VolumeUnit.CubicCentimeter).ToString(swedishCulture)); @@ -3121,22 +3268,22 @@ public void ToString_WithSwedishCulture_ReturnsUnitAbbreviationForEnglishCulture Assert.Equal("1 Mgal (imp.)", new Volume(1, VolumeUnit.MegaimperialGallon).ToString(swedishCulture)); Assert.Equal("1 Ml", new Volume(1, VolumeUnit.Megaliter).ToString(swedishCulture)); Assert.Equal("1 Mgal (U.S.)", new Volume(1, VolumeUnit.MegausGallon).ToString(swedishCulture)); - Assert.Equal("1", new Volume(1, VolumeUnit.MetricCup).ToString(swedishCulture)); + Assert.Equal("1 metric cup", new Volume(1, VolumeUnit.MetricCup).ToString(swedishCulture)); Assert.Equal("1 tsp", new Volume(1, VolumeUnit.MetricTeaspoon).ToString(swedishCulture)); Assert.Equal("1 µl", new Volume(1, VolumeUnit.Microliter).ToString(swedishCulture)); Assert.Equal("1 ml", new Volume(1, VolumeUnit.Milliliter).ToString(swedishCulture)); Assert.Equal("1 nl", new Volume(1, VolumeUnit.Nanoliter).ToString(swedishCulture)); Assert.Equal("1 bbl", new Volume(1, VolumeUnit.OilBarrel).ToString(swedishCulture)); - Assert.Equal("1", new Volume(1, VolumeUnit.UkTablespoon).ToString(swedishCulture)); + Assert.Equal("1 tablespoon (U.K.)", new Volume(1, VolumeUnit.UkTablespoon).ToString(swedishCulture)); Assert.Equal("1 bl (U.S.)", new Volume(1, VolumeUnit.UsBeerBarrel).ToString(swedishCulture)); - Assert.Equal("1", new Volume(1, VolumeUnit.UsCustomaryCup).ToString(swedishCulture)); + Assert.Equal("1 cup (U.S. customary)", new Volume(1, VolumeUnit.UsCustomaryCup).ToString(swedishCulture)); Assert.Equal("1 gal (U.S.)", new Volume(1, VolumeUnit.UsGallon).ToString(swedishCulture)); - Assert.Equal("1", new Volume(1, VolumeUnit.UsLegalCup).ToString(swedishCulture)); + Assert.Equal("1 cup (U.S.)", new Volume(1, VolumeUnit.UsLegalCup).ToString(swedishCulture)); Assert.Equal("1 oz (U.S.)", new Volume(1, VolumeUnit.UsOunce).ToString(swedishCulture)); Assert.Equal("1 pt (U.S.)", new Volume(1, VolumeUnit.UsPint).ToString(swedishCulture)); Assert.Equal("1 qt (U.S.)", new Volume(1, VolumeUnit.UsQuart).ToString(swedishCulture)); - Assert.Equal("1", new Volume(1, VolumeUnit.UsTablespoon).ToString(swedishCulture)); - Assert.Equal("1", new Volume(1, VolumeUnit.UsTeaspoon).ToString(swedishCulture)); + Assert.Equal("1 tablespoon (U.S.)", new Volume(1, VolumeUnit.UsTablespoon).ToString(swedishCulture)); + Assert.Equal("1 teaspoon (U.S.)", new Volume(1, VolumeUnit.UsTeaspoon).ToString(swedishCulture)); } [Fact] diff --git a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs index bcfea9a4fe..264caa0d93 100644 --- a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs +++ b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs @@ -210,8 +210,13 @@ public string GetDefaultAbbreviation(Type unitType, int unitValue, IFormatProvid /// The default unit abbreviation string. public string GetDefaultAbbreviation(UnitKey unitKey, IFormatProvider? formatProvider = null) { - var abbreviations = GetUnitAbbreviations(unitKey, formatProvider); - return abbreviations.Count > 0 ? abbreviations[0] : string.Empty; + IReadOnlyList abbreviations = GetUnitAbbreviations(unitKey, formatProvider); + if (abbreviations.Count == 0) + { + throw new InvalidOperationException($"No abbreviations were found for {unitKey.UnitType.Name}.{(Enum)unitKey}. Make sure that the unit abbreviations are mapped."); + } + + return abbreviations[0]; } /// diff --git a/UnitsNet/GeneratedCode/Resources/Volume.restext b/UnitsNet/GeneratedCode/Resources/Volume.restext index b88e0a84b1..ddf8cb58da 100644 --- a/UnitsNet/GeneratedCode/Resources/Volume.restext +++ b/UnitsNet/GeneratedCode/Resources/Volume.restext @@ -1,4 +1,5 @@ AcreFeet=ac-ft,acre-foot,acre-feet +AuTablespoons=tablespoon (A.U.) BoardFeet=bf,board foot,board feet Centiliters=cl CubicCentimeters=cm³ @@ -35,13 +36,19 @@ MegacubicFeet=Mft³ MegaimperialGallons=Mgal (imp.) Megaliters=Ml MegausGallons=Mgal (U.S.) +MetricCups=metric cup MetricTeaspoons=tsp,t,ts,tspn,t.,ts.,tsp.,tspn.,teaspoon Microliters=µl Milliliters=ml Nanoliters=nl OilBarrels=bbl +UkTablespoons=tablespoon (U.K.) UsBeerBarrels=bl (U.S.) +UsCustomaryCups=cup (U.S. customary) UsGallons=gal (U.S.) +UsLegalCups=cup (U.S.) UsOunces=oz (U.S.) UsPints=pt (U.S.) UsQuarts=qt (U.S.) +UsTablespoons=tablespoon (U.S.) +UsTeaspoons=teaspoon (U.S.)