From ea3a23ffe30453a9ae6496584a1b1d84f4cf796a Mon Sep 17 00:00:00 2001 From: lipchev Date: Thu, 19 Dec 2024 14:27:33 +0200 Subject: [PATCH 1/3] Fix #1443: UnitParser.TryParse doesn't try with FallbackCulture - UnitParser: extracting a FindMatchingUnits function (used by both Parse and TryParse for a given abbreviation and culture) - UnitAbbreviationsCache: just a cosmetic change (flipping the order of the items in the tuple) - UnitParserTests: added the missing tests for the FallbackCulture --- UnitsNet.Tests/UnitParserTests.cs | 41 ++++++- UnitsNet/CustomCode/UnitAbbreviationsCache.cs | 8 +- UnitsNet/CustomCode/UnitParser.cs | 112 ++++++++++-------- 3 files changed, 109 insertions(+), 52 deletions(-) diff --git a/UnitsNet.Tests/UnitParserTests.cs b/UnitsNet.Tests/UnitParserTests.cs index 93322f624f..d3bc0d513d 100644 --- a/UnitsNet.Tests/UnitParserTests.cs +++ b/UnitsNet.Tests/UnitParserTests.cs @@ -57,6 +57,12 @@ public void Parse_GivenAbbreviationsThatAreAmbiguousWhenLowerCase_ReturnsCorrect Assert.Equal(PressureUnit.Millibar, Pressure.ParseUnit("mbar")); } + [Fact] + public void Parse_NullAbbreviation_Throws_ArgumentNullException() + { + Assert.Throws(() => UnitsNetSetup.Default.UnitParser.Parse(null!, typeof(LengthUnit))); + } + [Fact] public void Parse_UnknownAbbreviationThrowsUnitNotFoundException() { @@ -95,7 +101,7 @@ public void Parse_CanParseMultiplySigns(string unitAbbreviation, Type unitType, [InlineData("kg·s⁻¹·m⁻² ", typeof(MassFluxUnit), MassFluxUnit.KilogramPerSecondPerSquareMeter)] [InlineData("k g · s ⁻ ¹ · m ⁻ ² ", typeof(MassFluxUnit), MassFluxUnit.KilogramPerSecondPerSquareMeter)] [InlineData(" k g · s ⁻ ¹ · m ⁻ ² ", typeof(MassFluxUnit), MassFluxUnit.KilogramPerSecondPerSquareMeter)] - public void Parse_CanParseWithWithspacesInUnit(string unitAbbreviation, Type unitType, Enum resultUnitType) + public void Parse_CanParseWithWhitespacesInUnit(string unitAbbreviation, Type unitType, Enum resultUnitType) { Assert.Equal(resultUnitType, UnitParser.Default.Parse(unitAbbreviation, unitType)); } @@ -121,6 +127,7 @@ public void Parse_AmbiguousUnitsThrowsException() [InlineData("г", "ru-RU", MassUnit.Gram)] [InlineData("kg", "en-US", MassUnit.Kilogram)] [InlineData("кг", "ru-RU", MassUnit.Kilogram)] + [InlineData("kg", "ru-RU", MassUnit.Kilogram)] // should work with the "FallbackCulture" public void ParseMassUnit_GivenCulture(string str, string cultureName, Enum expectedUnit) { Assert.Equal(expectedUnit, UnitParser.Default.Parse(str, CultureInfo.GetCultureInfo(cultureName))); @@ -152,5 +159,37 @@ public void TryParse_WithNullAbbreviation_ReturnsFalse() Assert.False(success); }); } + + [Fact] + public void TryParse_UnknownAbbreviation_ReturnsFalse() + { + Assert.False(UnitsNetSetup.Default.UnitParser.TryParse("nonexistingunit", out AreaUnit _)); + } + + [Fact] + public void TryParse_WithAmbiguousUnits_ReturnsFalse() + { + UnitParser unitParser = UnitsNetSetup.Default.UnitParser; + Assert.False(unitParser.TryParse("pt", CultureInfo.InvariantCulture, out LengthUnit _)); + } + + [Theory] + [InlineData("ng", "en-US", MassUnit.Nanogram)] + [InlineData("нг", "ru-RU", MassUnit.Nanogram)] + [InlineData("g", "en-US", MassUnit.Gram)] + [InlineData("г", "ru-RU", MassUnit.Gram)] + [InlineData("kg", "en-US", MassUnit.Kilogram)] + [InlineData("кг", "ru-RU", MassUnit.Kilogram)] + [InlineData("kg", "ru-RU", MassUnit.Kilogram)] // should work with the "FallbackCulture" + public void TryParseMassUnit_GivenCulture(string str, string cultureName, Enum expectedUnit) + { + var formatProvider = CultureInfo.GetCultureInfo(cultureName); + UnitParser unitParser = UnitsNetSetup.Default.UnitParser; + + var success = unitParser.TryParse(str, formatProvider, out MassUnit unitParsed); + + Assert.True(success); + Assert.Equal(expectedUnit, unitParsed); + } } } diff --git a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs index 9307d8b2f1..273629a7db 100644 --- a/UnitsNet/CustomCode/UnitAbbreviationsCache.cs +++ b/UnitsNet/CustomCode/UnitAbbreviationsCache.cs @@ -271,12 +271,12 @@ public IReadOnlyList GetAllUnitAbbreviationsForQuantity(Type unitEnumTyp { var enumValues = Enum.GetValues(unitEnumType).Cast(); var all = GetStringUnitPairs(enumValues, formatProvider); - return all.Select(pair => pair.Item1).ToList(); + return all.Select(pair => pair.Item2).ToList(); } - internal List<(string Abbreviation, Enum Unit)> GetStringUnitPairs(IEnumerable enumValues, IFormatProvider? formatProvider = null) + internal List<(Enum Unit, string Abbreviation)> GetStringUnitPairs(IEnumerable enumValues, IFormatProvider? formatProvider = null) { - var ret = new List<(string, Enum)>(); + var ret = new List<(Enum, string)>(); formatProvider ??= CultureInfo.CurrentCulture; foreach(var enumValue in enumValues) @@ -285,7 +285,7 @@ public IReadOnlyList GetAllUnitAbbreviationsForQuantity(Type unitEnumTyp { foreach(var abbrev in abbreviations) { - ret.Add((abbrev, enumValue)); + ret.Add((enumValue, abbrev)); } } } diff --git a/UnitsNet/CustomCode/UnitParser.cs b/UnitsNet/CustomCode/UnitParser.cs index 71cbf4a903..740c44284f 100644 --- a/UnitsNet/CustomCode/UnitParser.cs +++ b/UnitsNet/CustomCode/UnitParser.cs @@ -2,6 +2,7 @@ // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; @@ -44,7 +45,8 @@ public UnitParser(UnitAbbreviationsCache? unitAbbreviationsCache) /// The format provider to use for lookup. Defaults to if null. /// /// - public TUnitType Parse(string unitAbbreviation, IFormatProvider? formatProvider = null) where TUnitType : Enum + public TUnitType Parse(string unitAbbreviation, IFormatProvider? formatProvider = null) + where TUnitType : Enum { return (TUnitType)Parse(unitAbbreviation, typeof(TUnitType), formatProvider); } @@ -66,37 +68,27 @@ public Enum Parse(string unitAbbreviation, Type unitType, IFormatProvider? forma { if (unitAbbreviation == null) throw new ArgumentNullException(nameof(unitAbbreviation)); unitAbbreviation = unitAbbreviation.Trim(); - - var enumValues = Enum.GetValues(unitType).Cast(); - var stringUnitPairs = _unitAbbreviationsCache.GetStringUnitPairs(enumValues, formatProvider); - var matches = stringUnitPairs.Where(pair => pair.Item1.Equals(unitAbbreviation, StringComparison.OrdinalIgnoreCase)).ToArray(); - - if(matches.Length == 0) - { - unitAbbreviation = NormalizeUnitString(unitAbbreviation); - matches = stringUnitPairs.Where(pair => pair.Item1.Equals(unitAbbreviation, StringComparison.OrdinalIgnoreCase)).ToArray(); - } - - // Narrow the search if too many hits, for example Megabar "Mbar" and Millibar "mbar" need to be distinguished - if(matches.Length > 1) - matches = stringUnitPairs.Where(pair => pair.Item1.Equals(unitAbbreviation)).ToArray(); - - switch(matches.Length) + Enum[] enumValues = Enum.GetValues(unitType).Cast().ToArray(); + while (true) { - case 1: - return (Enum)Enum.ToObject(unitType, matches[0].Unit); - case 0: - // Retry with fallback culture, if different. - if(!Equals(formatProvider, UnitAbbreviationsCache.FallbackCulture)) - { - return Parse(unitAbbreviation, unitType, UnitAbbreviationsCache.FallbackCulture); - } - - throw new UnitNotFoundException($"Unit not found with abbreviation [{unitAbbreviation}] for unit type [{unitType}]."); - default: - string unitsCsv = string.Join(", ", matches.Select(x => Enum.GetName(unitType, x.Unit)).ToArray()); - throw new AmbiguousUnitParseException( - $"Cannot parse \"{unitAbbreviation}\" since it could be either of these: {unitsCsv}"); + (Enum Unit, string Abbreviation)[] matches = FindMatchingUnits(unitAbbreviation, enumValues, formatProvider); + switch(matches.Length) + { + case 1: + return matches[0].Unit; + case 0: + // Retry with fallback culture, if different. + if (Equals(formatProvider, UnitAbbreviationsCache.FallbackCulture)) + { + throw new UnitNotFoundException($"Unit not found with abbreviation [{unitAbbreviation}] for unit type [{unitType}]."); + } + + formatProvider = UnitAbbreviationsCache.FallbackCulture; + continue; + default: + var unitsCsv = string.Join(", ", matches.Select(x => Enum.GetName(unitType, x.Unit)).ToArray()); + throw new AmbiguousUnitParseException($"Cannot parse \"{unitAbbreviation}\" since it could be either of these: {unitsCsv}"); + } } } @@ -138,7 +130,8 @@ internal static string NormalizeUnitString(string unitAbbreviation) /// The unit enum value as out result. /// Type of unit enum. /// True if successful. - public bool TryParse([NotNullWhen(true)]string? unitAbbreviation, out TUnitType unit) where TUnitType : struct, Enum + public bool TryParse([NotNullWhen(true)]string? unitAbbreviation, out TUnitType unit) + where TUnitType : struct, Enum { return TryParse(unitAbbreviation, null, out unit); } @@ -151,7 +144,8 @@ public bool TryParse([NotNullWhen(true)]string? unitAbbreviation, out /// The unit enum value as out result. /// Type of unit enum. /// True if successful. - public bool TryParse([NotNullWhen(true)]string? unitAbbreviation, IFormatProvider? formatProvider, out TUnitType unit) where TUnitType : struct, Enum + public bool TryParse([NotNullWhen(true)]string? unitAbbreviation, IFormatProvider? formatProvider, out TUnitType unit) + where TUnitType : struct, Enum { unit = default; @@ -184,34 +178,58 @@ public bool TryParse([NotNullWhen(true)] string? unitAbbreviation, Type unitType /// True if successful. public bool TryParse([NotNullWhen(true)] string? unitAbbreviation, Type unitType, IFormatProvider? formatProvider, [NotNullWhen(true)] out Enum? unit) { + unit = null; if (unitAbbreviation == null) { - unit = default; return false; } unitAbbreviation = unitAbbreviation.Trim(); - unit = default; + Enum[] enumValues = Enum.GetValues(unitType).Cast().ToArray(); + (Enum Unit, string Abbreviation)[] matches = FindMatchingUnits(unitAbbreviation, enumValues, formatProvider); - var enumValues = Enum.GetValues(unitType).Cast(); - var stringUnitPairs = _unitAbbreviationsCache.GetStringUnitPairs(enumValues, formatProvider); - var matches = stringUnitPairs.Where(pair => pair.Item1.Equals(unitAbbreviation, StringComparison.OrdinalIgnoreCase)).ToArray(); + if (matches.Length == 1) + { + unit = matches[0].Unit; + return true; + } + + if (matches.Length != 0 || Equals(formatProvider, UnitAbbreviationsCache.FallbackCulture)) + { + return false; // either there are duplicates or nothing was matched and we're already using the fallback culture + } - if(matches.Length == 0) + // retry the lookup using the fallback culture + matches = FindMatchingUnits(unitAbbreviation, enumValues, UnitAbbreviationsCache.FallbackCulture); + if (matches.Length != 1) + { + return false; + } + + unit = matches[0].Unit; + return true; + } + + private (Enum Unit, string Abbreviation)[] FindMatchingUnits(string unitAbbreviation, IEnumerable enumValues, IFormatProvider? formatProvider) + { + // TODO see about optimizing this method: both Parse and TryParse only care about having one match (in case of a failure we could return the number of matches) + List<(Enum Unit, string Abbreviation)> stringUnitPairs = _unitAbbreviationsCache.GetStringUnitPairs(enumValues, formatProvider); + (Enum Unit, string Abbreviation)[] matches = + stringUnitPairs.Where(pair => pair.Item2.Equals(unitAbbreviation, StringComparison.OrdinalIgnoreCase)).ToArray(); + + if (matches.Length == 0) { unitAbbreviation = NormalizeUnitString(unitAbbreviation); - matches = stringUnitPairs.Where(pair => pair.Item1.Equals(unitAbbreviation, StringComparison.OrdinalIgnoreCase)).ToArray(); + matches = stringUnitPairs.Where(pair => pair.Item2.Equals(unitAbbreviation, StringComparison.OrdinalIgnoreCase)).ToArray(); } // Narrow the search if too many hits, for example Megabar "Mbar" and Millibar "mbar" need to be distinguished - if(matches.Length > 1) - matches = stringUnitPairs.Where(pair => pair.Item1.Equals(unitAbbreviation)).ToArray(); - - if(matches.Length != 1) - return false; + if (matches.Length > 1) + { + matches = stringUnitPairs.Where(pair => pair.Item2.Equals(unitAbbreviation)).ToArray(); + } - unit = (Enum)Enum.ToObject(unitType, matches[ 0 ].Unit); - return true; + return matches; } } } From dcd4fb00d6782ed7862b5fa80f6ef5c6ad972551 Mon Sep 17 00:00:00 2001 From: lipchev Date: Thu, 19 Dec 2024 19:45:34 +0200 Subject: [PATCH 2/3] Improve the test coverage for the static ParseUnit and TryParseUnit tests --- .../UnitsNetGen/UnitTestBaseClassGenerator.cs | 203 +- ...orbedDoseOfIonizingRadiationTestsBase.g.cs | 416 +-- .../TestsBase/AccelerationTestsBase.g.cs | 420 +-- .../TestsBase/AmountOfSubstanceTestsBase.g.cs | 273 +- .../TestsBase/AmplitudeRatioTestsBase.g.cs | 84 +- .../TestsBase/AngleTestsBase.g.cs | 559 +--- .../TestsBase/ApparentEnergyTestsBase.g.cs | 69 +- .../TestsBase/ApparentPowerTestsBase.g.cs | 104 +- .../TestsBase/AreaDensityTestsBase.g.cs | 84 +- .../AreaMomentOfInertiaTestsBase.g.cs | 208 +- .../TestsBase/AreaTestsBase.g.cs | 583 +--- .../TestsBase/BitRateTestsBase.g.cs | 613 ++--- ...BrakeSpecificFuelConsumptionTestsBase.g.cs | 69 +- .../TestsBase/CapacitanceTestsBase.g.cs | 119 +- ...oefficientOfThermalExpansionTestsBase.g.cs | 114 +- .../TestsBase/CompressibilityTestsBase.g.cs | 238 +- .../TestsBase/DensityTestsBase.g.cs | 920 ++----- .../TestsBase/DurationTestsBase.g.cs | 911 ++----- .../TestsBase/DynamicViscosityTestsBase.g.cs | 223 +- .../ElectricAdmittanceTestsBase.g.cs | 84 +- .../ElectricChargeDensityTestsBase.g.cs | 39 +- .../TestsBase/ElectricChargeTestsBase.g.cs | 223 +- .../ElectricConductanceTestsBase.g.cs | 99 +- .../ElectricConductivityTestsBase.g.cs | 114 +- .../ElectricCurrentDensityTestsBase.g.cs | 69 +- .../ElectricCurrentGradientTestsBase.g.cs | 129 +- .../TestsBase/ElectricCurrentTestsBase.g.cs | 151 +- .../TestsBase/ElectricFieldTestsBase.g.cs | 39 +- .../ElectricInductanceTestsBase.g.cs | 99 +- .../ElectricPotentialAcTestsBase.g.cs | 89 +- .../ElectricPotentialChangeRateTestsBase.g.cs | 288 +- .../ElectricPotentialDcTestsBase.g.cs | 89 +- .../TestsBase/ElectricPotentialTestsBase.g.cs | 172 +- .../ElectricResistanceTestsBase.g.cs | 119 +- .../ElectricResistivityTestsBase.g.cs | 218 +- ...ElectricSurfaceChargeDensityTestsBase.g.cs | 69 +- .../TestsBase/EnergyDensityTestsBase.g.cs | 208 +- .../TestsBase/EnergyTestsBase.g.cs | 891 ++---- .../TestsBase/EntropyTestsBase.g.cs | 129 +- .../TestsBase/ForceChangeRateTestsBase.g.cs | 313 +-- .../TestsBase/ForcePerLengthTestsBase.g.cs | 706 ++--- .../TestsBase/ForceTestsBase.g.cs | 497 +--- .../TestsBase/FrequencyTestsBase.g.cs | 320 +-- .../TestsBase/FuelEfficiencyTestsBase.g.cs | 84 +- .../TestsBase/HeatFluxTestsBase.g.cs | 313 +-- .../HeatTransferCoefficientTestsBase.g.cs | 238 +- .../TestsBase/IlluminanceTestsBase.g.cs | 74 +- .../TestsBase/ImpulseTestsBase.g.cs | 213 +- .../TestsBase/InformationTestsBase.g.cs | 288 +- .../TestsBase/IrradianceTestsBase.g.cs | 218 +- .../TestsBase/IrradiationTestsBase.g.cs | 161 +- .../TestsBase/JerkTestsBase.g.cs | 336 +-- .../KinematicViscosityTestsBase.g.cs | 267 +- .../TestsBase/LeakRateTestsBase.g.cs | 69 +- .../TestsBase/LengthTestsBase.g.cs | 1280 +++------ .../TestsBase/LevelTestsBase.g.cs | 54 +- .../TestsBase/LinearDensityTestsBase.g.cs | 298 +- .../LinearPowerDensityTestsBase.g.cs | 353 +-- .../TestsBase/LuminanceTestsBase.g.cs | 178 +- .../TestsBase/LuminosityTestsBase.g.cs | 218 +- .../TestsBase/LuminousFluxTestsBase.g.cs | 39 +- .../TestsBase/LuminousIntensityTestsBase.g.cs | 39 +- .../TestsBase/MagneticFieldTestsBase.g.cs | 114 +- .../TestsBase/MagneticFluxTestsBase.g.cs | 39 +- .../TestsBase/MagnetizationTestsBase.g.cs | 39 +- .../TestsBase/MassConcentrationTestsBase.g.cs | 815 ++---- .../TestsBase/MassFlowTestsBase.g.cs | 674 ++--- .../TestsBase/MassFluxTestsBase.g.cs | 208 +- .../TestsBase/MassFractionTestsBase.g.cs | 403 +-- .../MassMomentOfInertiaTestsBase.g.cs | 448 +--- .../TestsBase/MassTestsBase.g.cs | 1055 ++------ .../TestsBase/MolalityTestsBase.g.cs | 69 +- .../TestsBase/MolarEnergyTestsBase.g.cs | 69 +- .../TestsBase/MolarEntropyTestsBase.g.cs | 69 +- .../TestsBase/MolarFlowTestsBase.g.cs | 161 +- .../TestsBase/MolarMassTestsBase.g.cs | 379 +-- .../TestsBase/MolarityTestsBase.g.cs | 313 +-- .../TestsBase/PermeabilityTestsBase.g.cs | 39 +- .../TestsBase/PermittivityTestsBase.g.cs | 39 +- .../PorousMediumPermeabilityTestsBase.g.cs | 99 +- .../TestsBase/PowerDensityTestsBase.g.cs | 648 ++--- .../TestsBase/PowerRatioTestsBase.g.cs | 69 +- .../TestsBase/PowerTestsBase.g.cs | 448 +--- .../PressureChangeRateTestsBase.g.cs | 700 ++--- .../TestsBase/PressureTestsBase.g.cs | 1369 +++------- .../RadiationEquivalentDoseTestsBase.g.cs | 166 +- .../TestsBase/RadiationExposureTestsBase.g.cs | 144 +- .../TestsBase/RadioactivityTestsBase.g.cs | 760 ++---- .../TestsBase/RatioChangeRateTestsBase.g.cs | 54 +- .../TestsBase/RatioTestsBase.g.cs | 114 +- .../TestsBase/ReactiveEnergyTestsBase.g.cs | 69 +- .../TestsBase/ReactivePowerTestsBase.g.cs | 84 +- .../TestsBase/ReciprocalAreaTestsBase.g.cs | 193 +- .../TestsBase/ReciprocalLengthTestsBase.g.cs | 328 +-- .../TestsBase/RelativeHumidityTestsBase.g.cs | 39 +- .../RotationalAccelerationTestsBase.g.cs | 99 +- .../TestsBase/RotationalSpeedTestsBase.g.cs | 469 +--- ...RotationalStiffnessPerLengthTestsBase.g.cs | 223 +- .../RotationalStiffnessTestsBase.g.cs | 1490 +++------- .../TestsBase/ScalarTestsBase.g.cs | 39 +- .../TestsBase/SolidAngleTestsBase.g.cs | 39 +- .../TestsBase/SpecificEnergyTestsBase.g.cs | 478 +--- .../TestsBase/SpecificEntropyTestsBase.g.cs | 178 +- .../SpecificFuelConsumptionTestsBase.g.cs | 84 +- .../TestsBase/SpecificVolumeTestsBase.g.cs | 69 +- .../TestsBase/SpecificWeightTestsBase.g.cs | 283 +- .../TestsBase/SpeedTestsBase.g.cs | 925 ++----- .../StandardVolumeFlowTestsBase.g.cs | 161 +- .../TemperatureChangeRateTestsBase.g.cs | 178 +- .../TestsBase/TemperatureDeltaTestsBase.g.cs | 161 +- .../TemperatureGradientTestsBase.g.cs | 84 +- .../TestsBase/TemperatureTestsBase.g.cs | 178 +- .../ThermalConductivityTestsBase.g.cs | 54 +- .../TestsBase/ThermalInsulanceTestsBase.g.cs | 114 +- .../TestsBase/TorqueTestsBase.g.cs | 442 +-- .../TestsBase/TurbidityTestsBase.g.cs | 39 +- .../TestsBase/VitaminATestsBase.g.cs | 39 +- .../VolumeConcentrationTestsBase.g.cs | 343 +-- .../TestsBase/VolumeFlowPerAreaTestsBase.g.cs | 54 +- .../TestsBase/VolumeFlowTestsBase.g.cs | 2386 +++++------------ .../TestsBase/VolumePerLengthTestsBase.g.cs | 161 +- .../TestsBase/VolumeTestsBase.g.cs | 1412 +++------- .../VolumetricHeatCapacityTestsBase.g.cs | 161 +- .../WarpingMomentOfInertiaTestsBase.g.cs | 208 +- 124 files changed, 11560 insertions(+), 25292 deletions(-) diff --git a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs index 65e192f2c1..3ff853dd38 100644 --- a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using CodeGen.JsonTypes; @@ -50,6 +51,38 @@ internal class UnitTestBaseClassGenerator : GeneratorBase /// private readonly string _otherOrBaseUnitFullName; + /// + /// Stores a mapping of culture names to their corresponding unique unit abbreviations. + /// Each culture maps to a dictionary where the key is the unit abbreviation and the value is the corresponding + /// . + /// This ensures that unit abbreviations are unique within the context of a specific culture. + /// + /// + /// Used for testing culture-specific parsing with non-ambiguous (unique) abbreviations. + /// + private readonly Dictionary> _uniqueAbbreviationsForCulture; + + /// + /// Stores a mapping of culture names to their respective ambiguous unit abbreviations. + /// Each culture maps to a dictionary where the key is the ambiguous abbreviation, and the value is a list of + /// objects + /// that share the same abbreviation within that culture. + /// + /// + /// This field is used to identify and handle unit abbreviations that are not unique within a specific culture. + /// Ambiguities arise when multiple units share the same abbreviation, requiring additional logic to resolve. + /// + private readonly Dictionary>> _ambiguousAbbreviationsForCulture; + + /// + /// The default or fallback culture for unit localizations. + /// + /// + /// This culture, "en-US", is used as a fallback when a specific + /// is not available for the defined unit localizations. + /// + private const string FallbackCultureName = "en-US"; + public UnitTestBaseClassGenerator(Quantity quantity) { _quantity = quantity; @@ -65,6 +98,52 @@ public UnitTestBaseClassGenerator(Quantity quantity) // Try to pick another unit, or fall back to base unit if only a single unit. _otherOrBaseUnit = quantity.Units.Where(u => u != _baseUnit).DefaultIfEmpty(_baseUnit).First(); _otherOrBaseUnitFullName = $"{_unitEnumName}.{_otherOrBaseUnit.SingularName}"; + + var abbreviationsForCulture = new Dictionary>>(); + foreach (Unit unit in quantity.Units) + { + if (unit.ObsoleteText != null) + { + continue; + } + + foreach (Localization localization in unit.Localization) + { + if (!abbreviationsForCulture.TryGetValue(localization.Culture, out Dictionary>? localizationsForCulture)) + { + abbreviationsForCulture[localization.Culture] = localizationsForCulture = new Dictionary>(); + } + + foreach (var abbreviation in localization.Abbreviations) + { + if (localizationsForCulture.TryGetValue(abbreviation, out List? matchingUnits)) + { + matchingUnits.Add(unit); + } + else + { + localizationsForCulture[abbreviation] = [unit]; + } + } + } + } + + _uniqueAbbreviationsForCulture = new Dictionary>(); + _ambiguousAbbreviationsForCulture = new Dictionary>>(); + foreach ((var cultureName, Dictionary>? abbreviations) in abbreviationsForCulture) + { + var uniqueAbbreviations = abbreviations.Where(pair => pair.Value.Count == 1).ToDictionary(pair => pair.Key, pair => pair.Value[0]); + if (uniqueAbbreviations.Count != 0) + { + _uniqueAbbreviationsForCulture.Add(cultureName, uniqueAbbreviations); + } + + var ambiguousAbbreviations = abbreviations.Where(pair => pair.Value.Count > 1).ToDictionary(); + if (ambiguousAbbreviations.Count != 0) + { + _ambiguousAbbreviationsForCulture.Add(cultureName, ambiguousAbbreviations); + } + } } private string GetUnitFullName(Unit unit) => $"{_unitEnumName}.{unit.SingularName}"; @@ -323,45 +402,115 @@ public void TryParse() } Writer.WL($@" }} - - [Fact] - public void ParseUnit() - {{"); - foreach (var unit in _quantity.Units.Where(u => string.IsNullOrEmpty(u.ObsoleteText))) - foreach (var localization in unit.Localization) - foreach (var abbreviation in localization.Abbreviations) +"); + + Writer.WL($@" + [Theory]"); + foreach ((var abbreviation, Unit unit) in _uniqueAbbreviationsForCulture[FallbackCultureName]) { Writer.WL($@" - try - {{ - var parsedUnit = {_quantity.Name}.ParseUnit(""{abbreviation}"", CultureInfo.GetCultureInfo(""{localization.Culture}"")); - Assert.Equal({GetUnitFullName(unit)}, parsedUnit); - }} catch (AmbiguousUnitParseException) {{ /* Some units have the same abbreviations */ }} + [InlineData(""{abbreviation}"", {GetUnitFullName(unit)})]"); + } + Writer.WL($@" + public void ParseUnit(string abbreviation, {_unitEnumName} expectedUnit) + {{ + // regardless of the CurrentCulture is, this should always work with the FallbackCulture (""{FallbackCultureName}"") + {_unitEnumName} parsedUnit = {_quantity.Name}.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + }} "); + Writer.WL($@" + [Theory]"); + foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) + { + foreach ((var abbreviation, Unit unit) in abbreviations) + { + Writer.WL($@" + [InlineData(""{cultureName}"", ""{abbreviation}"", {GetUnitFullName(unit)})]"); + } } Writer.WL($@" + public void ParseUnitWithCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) + {{ + {_unitEnumName} parsedUnit = {_quantity.Name}.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); }} - - [Fact] - public void TryParseUnit() - {{"); - foreach (var unit in _quantity.Units.Where(u => string.IsNullOrEmpty(u.ObsoleteText))) - foreach (var localization in unit.Localization) - foreach (var abbreviation in localization.Abbreviations) +"); + // we only generate these for a few of the quantities + if (_ambiguousAbbreviationsForCulture.Count != 0) { - // Skip units with ambiguous abbreviations, since there is no exception to describe this is why TryParse failed. - if (IsAmbiguousAbbreviation(localization, abbreviation)) continue; - Writer.WL($@" - {{ - Assert.True({_quantity.Name}.TryParseUnit(""{abbreviation}"", CultureInfo.GetCultureInfo(""{localization.Culture}""), out var parsedUnit)); - Assert.Equal({GetUnitFullName(unit)}, parsedUnit); - }} + [Theory]"); + foreach ((var cultureName, Dictionary>? abbreviations) in _ambiguousAbbreviationsForCulture) + { + foreach (KeyValuePair> ambiguousPair in abbreviations) + { + Writer.WL($@" + [InlineData(""{cultureName}"", ""{ambiguousPair.Key}"")] // [{string.Join(", ", ambiguousPair.Value.Select(x => x.SingularName))}] "); + } + } + Writer.WL($@" + public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) + {{ + Assert.Throws(() => {_quantity.Name}.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture))); + }} +"); + } // ambiguousAbbreviations + + Writer.WL($@" + [Theory]"); + foreach ((var abbreviation, Unit unit) in _uniqueAbbreviationsForCulture[FallbackCultureName]) + { + Writer.WL($@" + [InlineData(""{abbreviation}"", {GetUnitFullName(unit)})]"); + } + Writer.WL($@" + public void TryParseUnit(string abbreviation, {_unitEnumName} expectedUnit) + {{ + // regardless of the CurrentCulture is, this should always work with the FallbackCulture (""{FallbackCultureName}"") + Assert.True({_quantity.Name}.TryParseUnit(abbreviation, out {_unitEnumName} parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + }} "); + Writer.WL($@" + [Theory]"); + foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) + { + foreach ((var abbreviation, Unit unit) in abbreviations) + { + Writer.WL($@" + [InlineData(""{cultureName}"", ""{abbreviation}"", {GetUnitFullName(unit)})]"); + } } Writer.WL($@" + public void TryParseUnitWithCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) + {{ + Assert.True({_quantity.Name}.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out {_unitEnumName} parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); }} - +"); + // we only generate these for a few of the quantities + if (_ambiguousAbbreviationsForCulture.Count != 0) + { + Writer.WL($@" + [Theory]"); + foreach ((var cultureName, Dictionary>? abbreviations) in _ambiguousAbbreviationsForCulture) + { + foreach (KeyValuePair> ambiguousPair in abbreviations) + { + Writer.WL($@" + [InlineData(""{cultureName}"", ""{ambiguousPair.Key}"")] // [{string.Join(", ", ambiguousPair.Value.Select(x => x.SingularName))}] "); + } + } + Writer.WL($@" + public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) + {{ + Assert.False({_quantity.Name}.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out _)); + }} +"); + } // ambiguousAbbreviations + + Writer.WL($@" [Theory] [MemberData(nameof(UnitTypes))] public void ToUnit({_unitEnumName} unit) diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs index 26a878427d..cb3fee8e9a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs @@ -681,306 +681,130 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("cGy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Centigray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("сГр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Centigray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("fGy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Femtogray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("фГр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Femtogray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("GGy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gigagray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("ГГр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gigagray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("Gy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("Гр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("kGy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilogray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("кГр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilogray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("krad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilorad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("крад", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilorad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("MGy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Megagray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("МГр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Megagray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("Mrad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Megarad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("Мрад", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Megarad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("µGy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Microgray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("мкГр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Microgray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("mGy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Milligray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("мГр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Milligray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("mrad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Millirad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("мрад", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Millirad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("nGy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Nanogray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("нГр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Nanogray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("PGy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Petagray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("ПГр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Petagray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("pGy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Picogray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("пГр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Picogray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Rad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("рад", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Rad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("TGy", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Teragray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit("ТГр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Teragray, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cGy", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("fGy", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("GGy", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("Gy", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("kGy", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("krad", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("MGy", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("Mrad", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("µGy", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("mGy", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("mrad", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("nGy", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("PGy", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("rad", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + public void ParseUnit(string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + AbsorbedDoseOfIonizingRadiationUnit parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("cGy", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Centigray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("сГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Centigray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("fGy", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Femtogray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("фГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Femtogray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("GGy", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gigagray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("ГГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gigagray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("Gy", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("Гр", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Gray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("kGy", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilogray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("кГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilogray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("krad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilorad, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("крад", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Kilorad, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("µGy", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Microgray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("мкГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Microgray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("nGy", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Nanogray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("нГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Nanogray, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Rad, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("рад", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Rad, parsedUnit); - } - - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("TGy", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Teragray, parsedUnit); - } + [Theory] + [InlineData("en-US", "cGy", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("en-US", "fGy", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("en-US", "GGy", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("en-US", "Gy", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("en-US", "kGy", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("en-US", "krad", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("en-US", "MGy", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("en-US", "Mrad", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("en-US", "µGy", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("en-US", "mGy", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("en-US", "mrad", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("en-US", "nGy", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("en-US", "PGy", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("en-US", "pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("en-US", "rad", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("en-US", "TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + [InlineData("ru-RU", "сГр", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("ru-RU", "фГр", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("ru-RU", "ГГр", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("ru-RU", "Гр", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("ru-RU", "кГр", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("ru-RU", "крад", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("ru-RU", "МГр", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("ru-RU", "Мрад", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("ru-RU", "мкГр", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("ru-RU", "мГр", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("ru-RU", "мрад", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("ru-RU", "нГр", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("ru-RU", "ПГр", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("ru-RU", "пГр", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("ru-RU", "рад", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("ru-RU", "ТГр", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + public void ParseUnitWithCulture(string culture, string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + { + AbsorbedDoseOfIonizingRadiationUnit parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit("ТГр", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AbsorbedDoseOfIonizingRadiationUnit.Teragray, parsedUnit); - } + [Theory] + [InlineData("cGy", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("fGy", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("GGy", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("Gy", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("kGy", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("krad", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("MGy", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("Mrad", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("µGy", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("mGy", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("mrad", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("nGy", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("PGy", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("rad", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + public void TryParseUnit(string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit(abbreviation, out AbsorbedDoseOfIonizingRadiationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cGy", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("en-US", "fGy", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("en-US", "GGy", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("en-US", "Gy", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("en-US", "kGy", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("en-US", "krad", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("en-US", "MGy", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("en-US", "Mrad", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("en-US", "µGy", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("en-US", "mGy", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("en-US", "mrad", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("en-US", "nGy", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("en-US", "PGy", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("en-US", "pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("en-US", "rad", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("en-US", "TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + [InlineData("ru-RU", "сГр", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("ru-RU", "фГр", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("ru-RU", "ГГр", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("ru-RU", "Гр", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("ru-RU", "кГр", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("ru-RU", "крад", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("ru-RU", "МГр", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("ru-RU", "Мрад", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("ru-RU", "мкГр", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("ru-RU", "мГр", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("ru-RU", "мрад", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("ru-RU", "нГр", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("ru-RU", "ПГр", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("ru-RU", "пГр", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("ru-RU", "рад", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("ru-RU", "ТГр", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + public void TryParseUnitWithCulture(string culture, string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + { + Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AbsorbedDoseOfIonizingRadiationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs index 63b086c6c6..fbff93d050 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs @@ -681,322 +681,118 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Acceleration.ParseUnit("cm/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.CentimeterPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("см/с²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.CentimeterPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("dm/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.DecimeterPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("дм/с²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.DecimeterPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("ft/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.FootPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("фут/с²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.FootPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("in/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.InchPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("дюйм/с²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.InchPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("km/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.KilometerPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("км/с²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.KilometerPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("kn/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.KnotPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("узел/час", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.KnotPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("kn/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.KnotPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("узел/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.KnotPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("kn/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.KnotPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("узел/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.KnotPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("m/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.MeterPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("м/с²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.MeterPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("µm/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.MicrometerPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("мкм/с²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.MicrometerPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("mm/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.MillimeterPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("мм/с²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.MillimeterPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("mg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.MillistandardGravity, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("мg", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.MillistandardGravity, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("nm/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.NanometerPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("нм/с²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.NanometerPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AccelerationUnit.StandardGravity, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Acceleration.ParseUnit("g", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AccelerationUnit.StandardGravity, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cm/s²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("dm/s²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("ft/s²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("in/s²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("km/s²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("kn/h", AccelerationUnit.KnotPerHour)] + [InlineData("kn/min", AccelerationUnit.KnotPerMinute)] + [InlineData("kn/s", AccelerationUnit.KnotPerSecond)] + [InlineData("m/s²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("µm/s²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("mm/s²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("mg", AccelerationUnit.MillistandardGravity)] + [InlineData("nm/s²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("g", AccelerationUnit.StandardGravity)] + public void ParseUnit(string abbreviation, AccelerationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + AccelerationUnit parsedUnit = Acceleration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Acceleration.TryParseUnit("cm/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.CentimeterPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("см/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.CentimeterPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("dm/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.DecimeterPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("дм/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.DecimeterPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("ft/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.FootPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("фут/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.FootPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("in/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.InchPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("дюйм/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.InchPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("km/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.KilometerPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("км/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.KilometerPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("kn/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.KnotPerHour, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("узел/час", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.KnotPerHour, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("kn/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.KnotPerMinute, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("узел/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.KnotPerMinute, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("kn/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.KnotPerSecond, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("узел/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.KnotPerSecond, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("m/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.MeterPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("м/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.MeterPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("µm/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.MicrometerPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("мкм/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.MicrometerPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("mm/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.MillimeterPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("мм/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.MillimeterPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("mg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.MillistandardGravity, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("мg", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.MillistandardGravity, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("nm/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.NanometerPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("нм/с²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.NanometerPerSecondSquared, parsedUnit); - } - - { - Assert.True(Acceleration.TryParseUnit("g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.StandardGravity, parsedUnit); - } + [Theory] + [InlineData("en-US", "cm/s²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("en-US", "dm/s²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("en-US", "ft/s²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("en-US", "in/s²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("en-US", "km/s²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("en-US", "kn/h", AccelerationUnit.KnotPerHour)] + [InlineData("en-US", "kn/min", AccelerationUnit.KnotPerMinute)] + [InlineData("en-US", "kn/s", AccelerationUnit.KnotPerSecond)] + [InlineData("en-US", "m/s²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("en-US", "µm/s²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("en-US", "mm/s²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("en-US", "mg", AccelerationUnit.MillistandardGravity)] + [InlineData("en-US", "nm/s²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("en-US", "g", AccelerationUnit.StandardGravity)] + [InlineData("ru-RU", "см/с²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("ru-RU", "дм/с²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("ru-RU", "фут/с²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("ru-RU", "дюйм/с²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("ru-RU", "км/с²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("ru-RU", "узел/час", AccelerationUnit.KnotPerHour)] + [InlineData("ru-RU", "узел/мин", AccelerationUnit.KnotPerMinute)] + [InlineData("ru-RU", "узел/с", AccelerationUnit.KnotPerSecond)] + [InlineData("ru-RU", "м/с²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("ru-RU", "мкм/с²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("ru-RU", "мм/с²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("ru-RU", "мg", AccelerationUnit.MillistandardGravity)] + [InlineData("ru-RU", "нм/с²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("ru-RU", "g", AccelerationUnit.StandardGravity)] + public void ParseUnitWithCulture(string culture, string abbreviation, AccelerationUnit expectedUnit) + { + AccelerationUnit parsedUnit = Acceleration.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Acceleration.TryParseUnit("g", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AccelerationUnit.StandardGravity, parsedUnit); - } + [Theory] + [InlineData("cm/s²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("dm/s²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("ft/s²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("in/s²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("km/s²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("kn/h", AccelerationUnit.KnotPerHour)] + [InlineData("kn/min", AccelerationUnit.KnotPerMinute)] + [InlineData("kn/s", AccelerationUnit.KnotPerSecond)] + [InlineData("m/s²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("µm/s²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("mm/s²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("mg", AccelerationUnit.MillistandardGravity)] + [InlineData("nm/s²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("g", AccelerationUnit.StandardGravity)] + public void TryParseUnit(string abbreviation, AccelerationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Acceleration.TryParseUnit(abbreviation, out AccelerationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cm/s²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("en-US", "dm/s²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("en-US", "ft/s²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("en-US", "in/s²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("en-US", "km/s²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("en-US", "kn/h", AccelerationUnit.KnotPerHour)] + [InlineData("en-US", "kn/min", AccelerationUnit.KnotPerMinute)] + [InlineData("en-US", "kn/s", AccelerationUnit.KnotPerSecond)] + [InlineData("en-US", "m/s²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("en-US", "µm/s²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("en-US", "mm/s²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("en-US", "mg", AccelerationUnit.MillistandardGravity)] + [InlineData("en-US", "nm/s²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("en-US", "g", AccelerationUnit.StandardGravity)] + [InlineData("ru-RU", "см/с²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("ru-RU", "дм/с²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("ru-RU", "фут/с²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("ru-RU", "дюйм/с²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("ru-RU", "км/с²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("ru-RU", "узел/час", AccelerationUnit.KnotPerHour)] + [InlineData("ru-RU", "узел/мин", AccelerationUnit.KnotPerMinute)] + [InlineData("ru-RU", "узел/с", AccelerationUnit.KnotPerSecond)] + [InlineData("ru-RU", "м/с²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("ru-RU", "мкм/с²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("ru-RU", "мм/с²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("ru-RU", "мg", AccelerationUnit.MillistandardGravity)] + [InlineData("ru-RU", "нм/с²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("ru-RU", "g", AccelerationUnit.StandardGravity)] + public void TryParseUnitWithCulture(string culture, string abbreviation, AccelerationUnit expectedUnit) + { + Assert.True(Acceleration.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AccelerationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs index 411cf680e3..9af206c2c1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs @@ -556,191 +556,102 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("cmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.Centimole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("clbmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.CentipoundMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("dmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.Decimole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("dlbmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.DecipoundMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("fmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.Femtomole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("kmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.Kilomole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("klbmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.KilopoundMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("Mmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.Megamole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("µmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.Micromole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("µlbmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.MicropoundMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("mmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.Millimole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("mlbmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.MillipoundMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.Mole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("nmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.Nanomole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("nlbmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.NanopoundMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("pmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.Picomole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmountOfSubstance.ParseUnit("lbmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmountOfSubstanceUnit.PoundMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cmol", AmountOfSubstanceUnit.Centimole)] + [InlineData("clbmol", AmountOfSubstanceUnit.CentipoundMole)] + [InlineData("dmol", AmountOfSubstanceUnit.Decimole)] + [InlineData("dlbmol", AmountOfSubstanceUnit.DecipoundMole)] + [InlineData("fmol", AmountOfSubstanceUnit.Femtomole)] + [InlineData("kmol", AmountOfSubstanceUnit.Kilomole)] + [InlineData("klbmol", AmountOfSubstanceUnit.KilopoundMole)] + [InlineData("Mmol", AmountOfSubstanceUnit.Megamole)] + [InlineData("µmol", AmountOfSubstanceUnit.Micromole)] + [InlineData("µlbmol", AmountOfSubstanceUnit.MicropoundMole)] + [InlineData("mmol", AmountOfSubstanceUnit.Millimole)] + [InlineData("mlbmol", AmountOfSubstanceUnit.MillipoundMole)] + [InlineData("mol", AmountOfSubstanceUnit.Mole)] + [InlineData("nmol", AmountOfSubstanceUnit.Nanomole)] + [InlineData("nlbmol", AmountOfSubstanceUnit.NanopoundMole)] + [InlineData("pmol", AmountOfSubstanceUnit.Picomole)] + [InlineData("lbmol", AmountOfSubstanceUnit.PoundMole)] + public void ParseUnit(string abbreviation, AmountOfSubstanceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + AmountOfSubstanceUnit parsedUnit = AmountOfSubstance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(AmountOfSubstance.TryParseUnit("cmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.Centimole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("clbmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.CentipoundMole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("dmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.Decimole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("dlbmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.DecipoundMole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("fmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.Femtomole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("kmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.Kilomole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("klbmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.KilopoundMole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("µmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.Micromole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("µlbmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.MicropoundMole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("mlbmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.MillipoundMole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.Mole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("nmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.Nanomole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("nlbmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.NanopoundMole, parsedUnit); - } - - { - Assert.True(AmountOfSubstance.TryParseUnit("pmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.Picomole, parsedUnit); - } + [Theory] + [InlineData("en-US", "cmol", AmountOfSubstanceUnit.Centimole)] + [InlineData("en-US", "clbmol", AmountOfSubstanceUnit.CentipoundMole)] + [InlineData("en-US", "dmol", AmountOfSubstanceUnit.Decimole)] + [InlineData("en-US", "dlbmol", AmountOfSubstanceUnit.DecipoundMole)] + [InlineData("en-US", "fmol", AmountOfSubstanceUnit.Femtomole)] + [InlineData("en-US", "kmol", AmountOfSubstanceUnit.Kilomole)] + [InlineData("en-US", "klbmol", AmountOfSubstanceUnit.KilopoundMole)] + [InlineData("en-US", "Mmol", AmountOfSubstanceUnit.Megamole)] + [InlineData("en-US", "µmol", AmountOfSubstanceUnit.Micromole)] + [InlineData("en-US", "µlbmol", AmountOfSubstanceUnit.MicropoundMole)] + [InlineData("en-US", "mmol", AmountOfSubstanceUnit.Millimole)] + [InlineData("en-US", "mlbmol", AmountOfSubstanceUnit.MillipoundMole)] + [InlineData("en-US", "mol", AmountOfSubstanceUnit.Mole)] + [InlineData("en-US", "nmol", AmountOfSubstanceUnit.Nanomole)] + [InlineData("en-US", "nlbmol", AmountOfSubstanceUnit.NanopoundMole)] + [InlineData("en-US", "pmol", AmountOfSubstanceUnit.Picomole)] + [InlineData("en-US", "lbmol", AmountOfSubstanceUnit.PoundMole)] + public void ParseUnitWithCulture(string culture, string abbreviation, AmountOfSubstanceUnit expectedUnit) + { + AmountOfSubstanceUnit parsedUnit = AmountOfSubstance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(AmountOfSubstance.TryParseUnit("lbmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmountOfSubstanceUnit.PoundMole, parsedUnit); - } + [Theory] + [InlineData("cmol", AmountOfSubstanceUnit.Centimole)] + [InlineData("clbmol", AmountOfSubstanceUnit.CentipoundMole)] + [InlineData("dmol", AmountOfSubstanceUnit.Decimole)] + [InlineData("dlbmol", AmountOfSubstanceUnit.DecipoundMole)] + [InlineData("fmol", AmountOfSubstanceUnit.Femtomole)] + [InlineData("kmol", AmountOfSubstanceUnit.Kilomole)] + [InlineData("klbmol", AmountOfSubstanceUnit.KilopoundMole)] + [InlineData("Mmol", AmountOfSubstanceUnit.Megamole)] + [InlineData("µmol", AmountOfSubstanceUnit.Micromole)] + [InlineData("µlbmol", AmountOfSubstanceUnit.MicropoundMole)] + [InlineData("mmol", AmountOfSubstanceUnit.Millimole)] + [InlineData("mlbmol", AmountOfSubstanceUnit.MillipoundMole)] + [InlineData("mol", AmountOfSubstanceUnit.Mole)] + [InlineData("nmol", AmountOfSubstanceUnit.Nanomole)] + [InlineData("nlbmol", AmountOfSubstanceUnit.NanopoundMole)] + [InlineData("pmol", AmountOfSubstanceUnit.Picomole)] + [InlineData("lbmol", AmountOfSubstanceUnit.PoundMole)] + public void TryParseUnit(string abbreviation, AmountOfSubstanceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(AmountOfSubstance.TryParseUnit(abbreviation, out AmountOfSubstanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cmol", AmountOfSubstanceUnit.Centimole)] + [InlineData("en-US", "clbmol", AmountOfSubstanceUnit.CentipoundMole)] + [InlineData("en-US", "dmol", AmountOfSubstanceUnit.Decimole)] + [InlineData("en-US", "dlbmol", AmountOfSubstanceUnit.DecipoundMole)] + [InlineData("en-US", "fmol", AmountOfSubstanceUnit.Femtomole)] + [InlineData("en-US", "kmol", AmountOfSubstanceUnit.Kilomole)] + [InlineData("en-US", "klbmol", AmountOfSubstanceUnit.KilopoundMole)] + [InlineData("en-US", "Mmol", AmountOfSubstanceUnit.Megamole)] + [InlineData("en-US", "µmol", AmountOfSubstanceUnit.Micromole)] + [InlineData("en-US", "µlbmol", AmountOfSubstanceUnit.MicropoundMole)] + [InlineData("en-US", "mmol", AmountOfSubstanceUnit.Millimole)] + [InlineData("en-US", "mlbmol", AmountOfSubstanceUnit.MillipoundMole)] + [InlineData("en-US", "mol", AmountOfSubstanceUnit.Mole)] + [InlineData("en-US", "nmol", AmountOfSubstanceUnit.Nanomole)] + [InlineData("en-US", "nlbmol", AmountOfSubstanceUnit.NanopoundMole)] + [InlineData("en-US", "pmol", AmountOfSubstanceUnit.Picomole)] + [InlineData("en-US", "lbmol", AmountOfSubstanceUnit.PoundMole)] + public void TryParseUnitWithCulture(string culture, string abbreviation, AmountOfSubstanceUnit expectedUnit) + { + Assert.True(AmountOfSubstance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AmountOfSubstanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs index 6bcda2f8c4..8d3765aaf9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs @@ -269,58 +269,50 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("dBµV", AmplitudeRatioUnit.DecibelMicrovolt)] + [InlineData("dBmV", AmplitudeRatioUnit.DecibelMillivolt)] + [InlineData("dBu", AmplitudeRatioUnit.DecibelUnloaded)] + [InlineData("dBV", AmplitudeRatioUnit.DecibelVolt)] + public void ParseUnit(string abbreviation, AmplitudeRatioUnit expectedUnit) { - try - { - var parsedUnit = AmplitudeRatio.ParseUnit("dBµV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmplitudeRatioUnit.DecibelMicrovolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmplitudeRatio.ParseUnit("dBmV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmplitudeRatioUnit.DecibelMillivolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmplitudeRatio.ParseUnit("dBu", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmplitudeRatioUnit.DecibelUnloaded, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AmplitudeRatio.ParseUnit("dBV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AmplitudeRatioUnit.DecibelVolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + AmplitudeRatioUnit parsedUnit = AmplitudeRatio.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "dBµV", AmplitudeRatioUnit.DecibelMicrovolt)] + [InlineData("en-US", "dBmV", AmplitudeRatioUnit.DecibelMillivolt)] + [InlineData("en-US", "dBu", AmplitudeRatioUnit.DecibelUnloaded)] + [InlineData("en-US", "dBV", AmplitudeRatioUnit.DecibelVolt)] + public void ParseUnitWithCulture(string culture, string abbreviation, AmplitudeRatioUnit expectedUnit) { - { - Assert.True(AmplitudeRatio.TryParseUnit("dBµV", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmplitudeRatioUnit.DecibelMicrovolt, parsedUnit); - } - - { - Assert.True(AmplitudeRatio.TryParseUnit("dBmV", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmplitudeRatioUnit.DecibelMillivolt, parsedUnit); - } - - { - Assert.True(AmplitudeRatio.TryParseUnit("dBu", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmplitudeRatioUnit.DecibelUnloaded, parsedUnit); - } + AmplitudeRatioUnit parsedUnit = AmplitudeRatio.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(AmplitudeRatio.TryParseUnit("dBV", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AmplitudeRatioUnit.DecibelVolt, parsedUnit); - } + [Theory] + [InlineData("dBµV", AmplitudeRatioUnit.DecibelMicrovolt)] + [InlineData("dBmV", AmplitudeRatioUnit.DecibelMillivolt)] + [InlineData("dBu", AmplitudeRatioUnit.DecibelUnloaded)] + [InlineData("dBV", AmplitudeRatioUnit.DecibelVolt)] + public void TryParseUnit(string abbreviation, AmplitudeRatioUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(AmplitudeRatio.TryParseUnit(abbreviation, out AmplitudeRatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "dBµV", AmplitudeRatioUnit.DecibelMicrovolt)] + [InlineData("en-US", "dBmV", AmplitudeRatioUnit.DecibelMillivolt)] + [InlineData("en-US", "dBu", AmplitudeRatioUnit.DecibelUnloaded)] + [InlineData("en-US", "dBV", AmplitudeRatioUnit.DecibelVolt)] + public void TryParseUnitWithCulture(string culture, string abbreviation, AmplitudeRatioUnit expectedUnit) + { + Assert.True(AmplitudeRatio.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AmplitudeRatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs index ddf3616aa1..3f574bd34b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs @@ -808,421 +808,158 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Angle.ParseUnit("'", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Arcminute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("arcmin", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Arcminute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("amin", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Arcminute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Arcminute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("″", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Arcsecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("arcsec", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Arcsecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("asec", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Arcsecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("sec", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Arcsecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("crad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Centiradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("срад", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Centiradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("drad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Deciradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("драд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Deciradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Degree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Degree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("°", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Degree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Gradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("g", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Gradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("µ°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Microdegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("µdeg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Microdegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("мк°", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Microdegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("µrad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Microradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("мкрад", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Microradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("m°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Millidegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("mdeg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Millidegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("м°", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Millidegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("mrad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Milliradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("мрад", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Milliradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("n°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Nanodegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("ndeg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Nanodegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("н°", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Nanodegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("nrad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Nanoradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("нрад", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Nanoradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("mil", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.NatoMil, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Radian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("рад", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Radian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("r", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AngleUnit.Revolution, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Angle.ParseUnit("r", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AngleUnit.Revolution, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("'", AngleUnit.Arcminute)] + [InlineData("arcmin", AngleUnit.Arcminute)] + [InlineData("amin", AngleUnit.Arcminute)] + [InlineData("min", AngleUnit.Arcminute)] + [InlineData("″", AngleUnit.Arcsecond)] + [InlineData("arcsec", AngleUnit.Arcsecond)] + [InlineData("asec", AngleUnit.Arcsecond)] + [InlineData("sec", AngleUnit.Arcsecond)] + [InlineData("crad", AngleUnit.Centiradian)] + [InlineData("drad", AngleUnit.Deciradian)] + [InlineData("°", AngleUnit.Degree)] + [InlineData("deg", AngleUnit.Degree)] + [InlineData("g", AngleUnit.Gradian)] + [InlineData("µ°", AngleUnit.Microdegree)] + [InlineData("µdeg", AngleUnit.Microdegree)] + [InlineData("µrad", AngleUnit.Microradian)] + [InlineData("m°", AngleUnit.Millidegree)] + [InlineData("mdeg", AngleUnit.Millidegree)] + [InlineData("mrad", AngleUnit.Milliradian)] + [InlineData("n°", AngleUnit.Nanodegree)] + [InlineData("ndeg", AngleUnit.Nanodegree)] + [InlineData("nrad", AngleUnit.Nanoradian)] + [InlineData("mil", AngleUnit.NatoMil)] + [InlineData("rad", AngleUnit.Radian)] + [InlineData("r", AngleUnit.Revolution)] + public void ParseUnit(string abbreviation, AngleUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + AngleUnit parsedUnit = Angle.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Angle.TryParseUnit("'", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Arcminute, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("arcmin", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Arcminute, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("amin", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Arcminute, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Arcminute, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("″", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Arcsecond, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("arcsec", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Arcsecond, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("asec", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Arcsecond, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("sec", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Arcsecond, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("crad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Centiradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("срад", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Centiradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("drad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Deciradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("драд", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Deciradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Degree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Degree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("°", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Degree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Gradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("g", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Gradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("µ°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Microdegree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("µdeg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Microdegree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("мк°", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Microdegree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("µrad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Microradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("мкрад", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Microradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("m°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Millidegree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("mdeg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Millidegree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("м°", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Millidegree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("mrad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Milliradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("мрад", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Milliradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("n°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Nanodegree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("ndeg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Nanodegree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("н°", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Nanodegree, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("nrad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Nanoradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("нрад", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Nanoradian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("mil", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.NatoMil, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Radian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("рад", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Radian, parsedUnit); - } - - { - Assert.True(Angle.TryParseUnit("r", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AngleUnit.Revolution, parsedUnit); - } + [Theory] + [InlineData("en-US", "'", AngleUnit.Arcminute)] + [InlineData("en-US", "arcmin", AngleUnit.Arcminute)] + [InlineData("en-US", "amin", AngleUnit.Arcminute)] + [InlineData("en-US", "min", AngleUnit.Arcminute)] + [InlineData("en-US", "″", AngleUnit.Arcsecond)] + [InlineData("en-US", "arcsec", AngleUnit.Arcsecond)] + [InlineData("en-US", "asec", AngleUnit.Arcsecond)] + [InlineData("en-US", "sec", AngleUnit.Arcsecond)] + [InlineData("en-US", "crad", AngleUnit.Centiradian)] + [InlineData("en-US", "drad", AngleUnit.Deciradian)] + [InlineData("en-US", "°", AngleUnit.Degree)] + [InlineData("en-US", "deg", AngleUnit.Degree)] + [InlineData("en-US", "g", AngleUnit.Gradian)] + [InlineData("en-US", "µ°", AngleUnit.Microdegree)] + [InlineData("en-US", "µdeg", AngleUnit.Microdegree)] + [InlineData("en-US", "µrad", AngleUnit.Microradian)] + [InlineData("en-US", "m°", AngleUnit.Millidegree)] + [InlineData("en-US", "mdeg", AngleUnit.Millidegree)] + [InlineData("en-US", "mrad", AngleUnit.Milliradian)] + [InlineData("en-US", "n°", AngleUnit.Nanodegree)] + [InlineData("en-US", "ndeg", AngleUnit.Nanodegree)] + [InlineData("en-US", "nrad", AngleUnit.Nanoradian)] + [InlineData("en-US", "mil", AngleUnit.NatoMil)] + [InlineData("en-US", "rad", AngleUnit.Radian)] + [InlineData("en-US", "r", AngleUnit.Revolution)] + [InlineData("ru-RU", "срад", AngleUnit.Centiradian)] + [InlineData("ru-RU", "драд", AngleUnit.Deciradian)] + [InlineData("ru-RU", "°", AngleUnit.Degree)] + [InlineData("ru-RU", "g", AngleUnit.Gradian)] + [InlineData("ru-RU", "мк°", AngleUnit.Microdegree)] + [InlineData("ru-RU", "мкрад", AngleUnit.Microradian)] + [InlineData("ru-RU", "м°", AngleUnit.Millidegree)] + [InlineData("ru-RU", "мрад", AngleUnit.Milliradian)] + [InlineData("ru-RU", "н°", AngleUnit.Nanodegree)] + [InlineData("ru-RU", "нрад", AngleUnit.Nanoradian)] + [InlineData("ru-RU", "рад", AngleUnit.Radian)] + [InlineData("ru-RU", "r", AngleUnit.Revolution)] + public void ParseUnitWithCulture(string culture, string abbreviation, AngleUnit expectedUnit) + { + AngleUnit parsedUnit = Angle.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Angle.TryParseUnit("r", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AngleUnit.Revolution, parsedUnit); - } + [Theory] + [InlineData("'", AngleUnit.Arcminute)] + [InlineData("arcmin", AngleUnit.Arcminute)] + [InlineData("amin", AngleUnit.Arcminute)] + [InlineData("min", AngleUnit.Arcminute)] + [InlineData("″", AngleUnit.Arcsecond)] + [InlineData("arcsec", AngleUnit.Arcsecond)] + [InlineData("asec", AngleUnit.Arcsecond)] + [InlineData("sec", AngleUnit.Arcsecond)] + [InlineData("crad", AngleUnit.Centiradian)] + [InlineData("drad", AngleUnit.Deciradian)] + [InlineData("°", AngleUnit.Degree)] + [InlineData("deg", AngleUnit.Degree)] + [InlineData("g", AngleUnit.Gradian)] + [InlineData("µ°", AngleUnit.Microdegree)] + [InlineData("µdeg", AngleUnit.Microdegree)] + [InlineData("µrad", AngleUnit.Microradian)] + [InlineData("m°", AngleUnit.Millidegree)] + [InlineData("mdeg", AngleUnit.Millidegree)] + [InlineData("mrad", AngleUnit.Milliradian)] + [InlineData("n°", AngleUnit.Nanodegree)] + [InlineData("ndeg", AngleUnit.Nanodegree)] + [InlineData("nrad", AngleUnit.Nanoradian)] + [InlineData("mil", AngleUnit.NatoMil)] + [InlineData("rad", AngleUnit.Radian)] + [InlineData("r", AngleUnit.Revolution)] + public void TryParseUnit(string abbreviation, AngleUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Angle.TryParseUnit(abbreviation, out AngleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "'", AngleUnit.Arcminute)] + [InlineData("en-US", "arcmin", AngleUnit.Arcminute)] + [InlineData("en-US", "amin", AngleUnit.Arcminute)] + [InlineData("en-US", "min", AngleUnit.Arcminute)] + [InlineData("en-US", "″", AngleUnit.Arcsecond)] + [InlineData("en-US", "arcsec", AngleUnit.Arcsecond)] + [InlineData("en-US", "asec", AngleUnit.Arcsecond)] + [InlineData("en-US", "sec", AngleUnit.Arcsecond)] + [InlineData("en-US", "crad", AngleUnit.Centiradian)] + [InlineData("en-US", "drad", AngleUnit.Deciradian)] + [InlineData("en-US", "°", AngleUnit.Degree)] + [InlineData("en-US", "deg", AngleUnit.Degree)] + [InlineData("en-US", "g", AngleUnit.Gradian)] + [InlineData("en-US", "µ°", AngleUnit.Microdegree)] + [InlineData("en-US", "µdeg", AngleUnit.Microdegree)] + [InlineData("en-US", "µrad", AngleUnit.Microradian)] + [InlineData("en-US", "m°", AngleUnit.Millidegree)] + [InlineData("en-US", "mdeg", AngleUnit.Millidegree)] + [InlineData("en-US", "mrad", AngleUnit.Milliradian)] + [InlineData("en-US", "n°", AngleUnit.Nanodegree)] + [InlineData("en-US", "ndeg", AngleUnit.Nanodegree)] + [InlineData("en-US", "nrad", AngleUnit.Nanoradian)] + [InlineData("en-US", "mil", AngleUnit.NatoMil)] + [InlineData("en-US", "rad", AngleUnit.Radian)] + [InlineData("en-US", "r", AngleUnit.Revolution)] + [InlineData("ru-RU", "срад", AngleUnit.Centiradian)] + [InlineData("ru-RU", "драд", AngleUnit.Deciradian)] + [InlineData("ru-RU", "°", AngleUnit.Degree)] + [InlineData("ru-RU", "g", AngleUnit.Gradian)] + [InlineData("ru-RU", "мк°", AngleUnit.Microdegree)] + [InlineData("ru-RU", "мкрад", AngleUnit.Microradian)] + [InlineData("ru-RU", "м°", AngleUnit.Millidegree)] + [InlineData("ru-RU", "мрад", AngleUnit.Milliradian)] + [InlineData("ru-RU", "н°", AngleUnit.Nanodegree)] + [InlineData("ru-RU", "нрад", AngleUnit.Nanoradian)] + [InlineData("ru-RU", "рад", AngleUnit.Radian)] + [InlineData("ru-RU", "r", AngleUnit.Revolution)] + public void TryParseUnitWithCulture(string culture, string abbreviation, AngleUnit expectedUnit) + { + Assert.True(Angle.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AngleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs index d2ec853351..ff6d078ce1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs @@ -246,47 +246,46 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("kVAh", ApparentEnergyUnit.KilovoltampereHour)] + [InlineData("MVAh", ApparentEnergyUnit.MegavoltampereHour)] + [InlineData("VAh", ApparentEnergyUnit.VoltampereHour)] + public void ParseUnit(string abbreviation, ApparentEnergyUnit expectedUnit) { - try - { - var parsedUnit = ApparentEnergy.ParseUnit("kVAh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ApparentEnergyUnit.KilovoltampereHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ApparentEnergy.ParseUnit("MVAh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ApparentEnergyUnit.MegavoltampereHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ApparentEnergy.ParseUnit("VAh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ApparentEnergyUnit.VoltampereHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ApparentEnergyUnit parsedUnit = ApparentEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "kVAh", ApparentEnergyUnit.KilovoltampereHour)] + [InlineData("en-US", "MVAh", ApparentEnergyUnit.MegavoltampereHour)] + [InlineData("en-US", "VAh", ApparentEnergyUnit.VoltampereHour)] + public void ParseUnitWithCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) { - { - Assert.True(ApparentEnergy.TryParseUnit("kVAh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ApparentEnergyUnit.KilovoltampereHour, parsedUnit); - } - - { - Assert.True(ApparentEnergy.TryParseUnit("MVAh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ApparentEnergyUnit.MegavoltampereHour, parsedUnit); - } + ApparentEnergyUnit parsedUnit = ApparentEnergy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ApparentEnergy.TryParseUnit("VAh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ApparentEnergyUnit.VoltampereHour, parsedUnit); - } + [Theory] + [InlineData("kVAh", ApparentEnergyUnit.KilovoltampereHour)] + [InlineData("MVAh", ApparentEnergyUnit.MegavoltampereHour)] + [InlineData("VAh", ApparentEnergyUnit.VoltampereHour)] + public void TryParseUnit(string abbreviation, ApparentEnergyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ApparentEnergy.TryParseUnit(abbreviation, out ApparentEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kVAh", ApparentEnergyUnit.KilovoltampereHour)] + [InlineData("en-US", "MVAh", ApparentEnergyUnit.MegavoltampereHour)] + [InlineData("en-US", "VAh", ApparentEnergyUnit.VoltampereHour)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) + { + Assert.True(ApparentEnergy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ApparentEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs index ccd3c7e761..edba712ac8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs @@ -303,70 +303,58 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("GVA", ApparentPowerUnit.Gigavoltampere)] + [InlineData("kVA", ApparentPowerUnit.Kilovoltampere)] + [InlineData("MVA", ApparentPowerUnit.Megavoltampere)] + [InlineData("µVA", ApparentPowerUnit.Microvoltampere)] + [InlineData("mVA", ApparentPowerUnit.Millivoltampere)] + [InlineData("VA", ApparentPowerUnit.Voltampere)] + public void ParseUnit(string abbreviation, ApparentPowerUnit expectedUnit) { - try - { - var parsedUnit = ApparentPower.ParseUnit("GVA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ApparentPowerUnit.Gigavoltampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ApparentPower.ParseUnit("kVA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ApparentPowerUnit.Kilovoltampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ApparentPower.ParseUnit("MVA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ApparentPowerUnit.Megavoltampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ApparentPower.ParseUnit("µVA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ApparentPowerUnit.Microvoltampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ApparentPower.ParseUnit("mVA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ApparentPowerUnit.Millivoltampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ApparentPower.ParseUnit("VA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ApparentPowerUnit.Voltampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ApparentPowerUnit parsedUnit = ApparentPower.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "GVA", ApparentPowerUnit.Gigavoltampere)] + [InlineData("en-US", "kVA", ApparentPowerUnit.Kilovoltampere)] + [InlineData("en-US", "MVA", ApparentPowerUnit.Megavoltampere)] + [InlineData("en-US", "µVA", ApparentPowerUnit.Microvoltampere)] + [InlineData("en-US", "mVA", ApparentPowerUnit.Millivoltampere)] + [InlineData("en-US", "VA", ApparentPowerUnit.Voltampere)] + public void ParseUnitWithCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) { - { - Assert.True(ApparentPower.TryParseUnit("GVA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ApparentPowerUnit.Gigavoltampere, parsedUnit); - } - - { - Assert.True(ApparentPower.TryParseUnit("kVA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ApparentPowerUnit.Kilovoltampere, parsedUnit); - } - - { - Assert.True(ApparentPower.TryParseUnit("µVA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ApparentPowerUnit.Microvoltampere, parsedUnit); - } + ApparentPowerUnit parsedUnit = ApparentPower.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ApparentPower.TryParseUnit("VA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ApparentPowerUnit.Voltampere, parsedUnit); - } + [Theory] + [InlineData("GVA", ApparentPowerUnit.Gigavoltampere)] + [InlineData("kVA", ApparentPowerUnit.Kilovoltampere)] + [InlineData("MVA", ApparentPowerUnit.Megavoltampere)] + [InlineData("µVA", ApparentPowerUnit.Microvoltampere)] + [InlineData("mVA", ApparentPowerUnit.Millivoltampere)] + [InlineData("VA", ApparentPowerUnit.Voltampere)] + public void TryParseUnit(string abbreviation, ApparentPowerUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ApparentPower.TryParseUnit(abbreviation, out ApparentPowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "GVA", ApparentPowerUnit.Gigavoltampere)] + [InlineData("en-US", "kVA", ApparentPowerUnit.Kilovoltampere)] + [InlineData("en-US", "MVA", ApparentPowerUnit.Megavoltampere)] + [InlineData("en-US", "µVA", ApparentPowerUnit.Microvoltampere)] + [InlineData("en-US", "mVA", ApparentPowerUnit.Millivoltampere)] + [InlineData("en-US", "VA", ApparentPowerUnit.Voltampere)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) + { + Assert.True(ApparentPower.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ApparentPowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs index e201892b46..767001e0ab 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs @@ -259,58 +259,50 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("g/m²", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("gsm", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] + [InlineData("mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] + public void ParseUnit(string abbreviation, AreaDensityUnit expectedUnit) { - try - { - var parsedUnit = AreaDensity.ParseUnit("g/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaDensityUnit.GramPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaDensity.ParseUnit("gsm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaDensityUnit.GramPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaDensity.ParseUnit("kg/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaDensityUnit.KilogramPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaDensity.ParseUnit("mg/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaDensityUnit.MilligramPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + AreaDensityUnit parsedUnit = AreaDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "g/m²", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("en-US", "gsm", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("en-US", "kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] + [InlineData("en-US", "mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, AreaDensityUnit expectedUnit) { - { - Assert.True(AreaDensity.TryParseUnit("g/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaDensityUnit.GramPerSquareMeter, parsedUnit); - } - - { - Assert.True(AreaDensity.TryParseUnit("gsm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaDensityUnit.GramPerSquareMeter, parsedUnit); - } - - { - Assert.True(AreaDensity.TryParseUnit("kg/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaDensityUnit.KilogramPerSquareMeter, parsedUnit); - } + AreaDensityUnit parsedUnit = AreaDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(AreaDensity.TryParseUnit("mg/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaDensityUnit.MilligramPerSquareMeter, parsedUnit); - } + [Theory] + [InlineData("g/m²", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("gsm", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] + [InlineData("mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] + public void TryParseUnit(string abbreviation, AreaDensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(AreaDensity.TryParseUnit(abbreviation, out AreaDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "g/m²", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("en-US", "gsm", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("en-US", "kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] + [InlineData("en-US", "mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, AreaDensityUnit expectedUnit) + { + Assert.True(AreaDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AreaDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs index 56fed36471..4bfae0e4fb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs @@ -393,146 +393,82 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("cm⁴", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.CentimeterToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("cm^4", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.CentimeterToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("dm⁴", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.DecimeterToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("dm^4", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.DecimeterToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("ft⁴", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.FootToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("ft^4", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.FootToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("in⁴", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.InchToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("in^4", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.InchToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("m⁴", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.MeterToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("m^4", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.MeterToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("mm⁴", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.MillimeterToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = AreaMomentOfInertia.ParseUnit("mm^4", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaMomentOfInertiaUnit.MillimeterToTheFourth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cm⁴", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("cm^4", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("dm⁴", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("dm^4", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("ft⁴", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("ft^4", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("in⁴", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("in^4", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("m⁴", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + [InlineData("mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + public void ParseUnit(string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + AreaMomentOfInertiaUnit parsedUnit = AreaMomentOfInertia.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(AreaMomentOfInertia.TryParseUnit("cm⁴", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.CentimeterToTheFourth, parsedUnit); - } - - { - Assert.True(AreaMomentOfInertia.TryParseUnit("cm^4", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.CentimeterToTheFourth, parsedUnit); - } - - { - Assert.True(AreaMomentOfInertia.TryParseUnit("dm⁴", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.DecimeterToTheFourth, parsedUnit); - } - - { - Assert.True(AreaMomentOfInertia.TryParseUnit("dm^4", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.DecimeterToTheFourth, parsedUnit); - } - - { - Assert.True(AreaMomentOfInertia.TryParseUnit("ft⁴", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.FootToTheFourth, parsedUnit); - } - - { - Assert.True(AreaMomentOfInertia.TryParseUnit("ft^4", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.FootToTheFourth, parsedUnit); - } - - { - Assert.True(AreaMomentOfInertia.TryParseUnit("in⁴", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.InchToTheFourth, parsedUnit); - } - - { - Assert.True(AreaMomentOfInertia.TryParseUnit("in^4", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.InchToTheFourth, parsedUnit); - } - - { - Assert.True(AreaMomentOfInertia.TryParseUnit("m⁴", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.MeterToTheFourth, parsedUnit); - } - - { - Assert.True(AreaMomentOfInertia.TryParseUnit("m^4", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.MeterToTheFourth, parsedUnit); - } - - { - Assert.True(AreaMomentOfInertia.TryParseUnit("mm⁴", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.MillimeterToTheFourth, parsedUnit); - } + [Theory] + [InlineData("en-US", "cm⁴", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("en-US", "cm^4", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("en-US", "dm⁴", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("en-US", "dm^4", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("en-US", "ft⁴", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("en-US", "ft^4", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("en-US", "in⁴", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("en-US", "in^4", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("en-US", "m⁴", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("en-US", "m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("en-US", "mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + [InlineData("en-US", "mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + public void ParseUnitWithCulture(string culture, string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + { + AreaMomentOfInertiaUnit parsedUnit = AreaMomentOfInertia.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(AreaMomentOfInertia.TryParseUnit("mm^4", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaMomentOfInertiaUnit.MillimeterToTheFourth, parsedUnit); - } + [Theory] + [InlineData("cm⁴", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("cm^4", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("dm⁴", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("dm^4", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("ft⁴", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("ft^4", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("in⁴", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("in^4", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("m⁴", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + [InlineData("mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + public void TryParseUnit(string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(AreaMomentOfInertia.TryParseUnit(abbreviation, out AreaMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cm⁴", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("en-US", "cm^4", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("en-US", "dm⁴", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("en-US", "dm^4", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("en-US", "ft⁴", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("en-US", "ft^4", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("en-US", "in⁴", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("en-US", "in^4", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("en-US", "m⁴", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("en-US", "m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("en-US", "mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + [InlineData("en-US", "mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + public void TryParseUnitWithCulture(string culture, string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + { + Assert.True(AreaMomentOfInertia.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AreaMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs index 6f67d1c189..7035b42f49 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs @@ -838,455 +838,154 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Area.ParseUnit("ac", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.Acre, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("акр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.Acre, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("英亩", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.Acre, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("ha", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.Hectare, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("га", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.Hectare, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("英亩", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.Hectare, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.SquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("см²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.SquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("平方厘米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.SquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("dm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.SquareDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("дм²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.SquareDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("平方分米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.SquareDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.SquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("фут²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.SquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("平方英尺", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.SquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("in²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.SquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("дюйм²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.SquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("平方英寸", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.SquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("km²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.SquareKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("км²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.SquareKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("平方公里", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.SquareKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.SquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("м²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.SquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("平方米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.SquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("µm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.SquareMicrometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("мкм²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.SquareMicrometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("平方微米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.SquareMicrometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("mi²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.SquareMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("миля²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.SquareMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("平方英里", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.SquareMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.SquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("мм²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.SquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("平方毫米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.SquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("nmi²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.SquareNauticalMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("морск.миля²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.SquareNauticalMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("平方海里", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.SquareNauticalMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("yd²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.SquareYard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("ярд²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.SquareYard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("平方码", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(AreaUnit.SquareYard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("ft² (US)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(AreaUnit.UsSurveySquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Area.ParseUnit("фут² (US)", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(AreaUnit.UsSurveySquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + [Theory] + [InlineData("ac", AreaUnit.Acre)] + [InlineData("ha", AreaUnit.Hectare)] + [InlineData("cm²", AreaUnit.SquareCentimeter)] + [InlineData("dm²", AreaUnit.SquareDecimeter)] + [InlineData("ft²", AreaUnit.SquareFoot)] + [InlineData("in²", AreaUnit.SquareInch)] + [InlineData("km²", AreaUnit.SquareKilometer)] + [InlineData("m²", AreaUnit.SquareMeter)] + [InlineData("µm²", AreaUnit.SquareMicrometer)] + [InlineData("mi²", AreaUnit.SquareMile)] + [InlineData("mm²", AreaUnit.SquareMillimeter)] + [InlineData("nmi²", AreaUnit.SquareNauticalMile)] + [InlineData("yd²", AreaUnit.SquareYard)] + [InlineData("ft² (US)", AreaUnit.UsSurveySquareFoot)] + public void ParseUnit(string abbreviation, AreaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + AreaUnit parsedUnit = Area.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "ac", AreaUnit.Acre)] + [InlineData("en-US", "ha", AreaUnit.Hectare)] + [InlineData("en-US", "cm²", AreaUnit.SquareCentimeter)] + [InlineData("en-US", "dm²", AreaUnit.SquareDecimeter)] + [InlineData("en-US", "ft²", AreaUnit.SquareFoot)] + [InlineData("en-US", "in²", AreaUnit.SquareInch)] + [InlineData("en-US", "km²", AreaUnit.SquareKilometer)] + [InlineData("en-US", "m²", AreaUnit.SquareMeter)] + [InlineData("en-US", "µm²", AreaUnit.SquareMicrometer)] + [InlineData("en-US", "mi²", AreaUnit.SquareMile)] + [InlineData("en-US", "mm²", AreaUnit.SquareMillimeter)] + [InlineData("en-US", "nmi²", AreaUnit.SquareNauticalMile)] + [InlineData("en-US", "yd²", AreaUnit.SquareYard)] + [InlineData("en-US", "ft² (US)", AreaUnit.UsSurveySquareFoot)] + [InlineData("ru-RU", "акр", AreaUnit.Acre)] + [InlineData("ru-RU", "га", AreaUnit.Hectare)] + [InlineData("ru-RU", "см²", AreaUnit.SquareCentimeter)] + [InlineData("ru-RU", "дм²", AreaUnit.SquareDecimeter)] + [InlineData("ru-RU", "фут²", AreaUnit.SquareFoot)] + [InlineData("ru-RU", "дюйм²", AreaUnit.SquareInch)] + [InlineData("ru-RU", "км²", AreaUnit.SquareKilometer)] + [InlineData("ru-RU", "м²", AreaUnit.SquareMeter)] + [InlineData("ru-RU", "мкм²", AreaUnit.SquareMicrometer)] + [InlineData("ru-RU", "миля²", AreaUnit.SquareMile)] + [InlineData("ru-RU", "мм²", AreaUnit.SquareMillimeter)] + [InlineData("ru-RU", "морск.миля²", AreaUnit.SquareNauticalMile)] + [InlineData("ru-RU", "ярд²", AreaUnit.SquareYard)] + [InlineData("ru-RU", "фут² (US)", AreaUnit.UsSurveySquareFoot)] + [InlineData("zh-CN", "平方厘米", AreaUnit.SquareCentimeter)] + [InlineData("zh-CN", "平方分米", AreaUnit.SquareDecimeter)] + [InlineData("zh-CN", "平方英尺", AreaUnit.SquareFoot)] + [InlineData("zh-CN", "平方英寸", AreaUnit.SquareInch)] + [InlineData("zh-CN", "平方公里", AreaUnit.SquareKilometer)] + [InlineData("zh-CN", "平方米", AreaUnit.SquareMeter)] + [InlineData("zh-CN", "平方微米", AreaUnit.SquareMicrometer)] + [InlineData("zh-CN", "平方英里", AreaUnit.SquareMile)] + [InlineData("zh-CN", "平方毫米", AreaUnit.SquareMillimeter)] + [InlineData("zh-CN", "平方海里", AreaUnit.SquareNauticalMile)] + [InlineData("zh-CN", "平方码", AreaUnit.SquareYard)] + public void ParseUnitWithCulture(string culture, string abbreviation, AreaUnit expectedUnit) + { + AreaUnit parsedUnit = Area.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("zh-CN", "英亩")] // [Acre, Hectare] + public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) { - { - Assert.True(Area.TryParseUnit("ac", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.Acre, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("акр", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.Acre, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("ha", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.Hectare, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("га", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.Hectare, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareCentimeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareCentimeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("平方厘米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareCentimeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("dm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareDecimeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("дм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareDecimeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("平方分米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareDecimeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareFoot, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("фут²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareFoot, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("平方英尺", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareFoot, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("in²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareInch, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("дюйм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareInch, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("平方英寸", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareInch, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("km²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareKilometer, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("км²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareKilometer, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("平方公里", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareKilometer, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("平方米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("µm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMicrometer, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("мкм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMicrometer, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("平方微米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMicrometer, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("mi²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMile, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("миля²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMile, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("平方英里", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMile, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMillimeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMillimeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("平方毫米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareMillimeter, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("nmi²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareNauticalMile, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("морск.миля²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareNauticalMile, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("平方海里", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareNauticalMile, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("yd²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareYard, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("ярд²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareYard, parsedUnit); - } - - { - Assert.True(Area.TryParseUnit("平方码", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(AreaUnit.SquareYard, parsedUnit); - } + Assert.Throws(() => Area.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture))); + } - { - Assert.True(Area.TryParseUnit("ft² (US)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(AreaUnit.UsSurveySquareFoot, parsedUnit); - } + [Theory] + [InlineData("ac", AreaUnit.Acre)] + [InlineData("ha", AreaUnit.Hectare)] + [InlineData("cm²", AreaUnit.SquareCentimeter)] + [InlineData("dm²", AreaUnit.SquareDecimeter)] + [InlineData("ft²", AreaUnit.SquareFoot)] + [InlineData("in²", AreaUnit.SquareInch)] + [InlineData("km²", AreaUnit.SquareKilometer)] + [InlineData("m²", AreaUnit.SquareMeter)] + [InlineData("µm²", AreaUnit.SquareMicrometer)] + [InlineData("mi²", AreaUnit.SquareMile)] + [InlineData("mm²", AreaUnit.SquareMillimeter)] + [InlineData("nmi²", AreaUnit.SquareNauticalMile)] + [InlineData("yd²", AreaUnit.SquareYard)] + [InlineData("ft² (US)", AreaUnit.UsSurveySquareFoot)] + public void TryParseUnit(string abbreviation, AreaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Area.TryParseUnit(abbreviation, out AreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Area.TryParseUnit("фут² (US)", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(AreaUnit.UsSurveySquareFoot, parsedUnit); - } + [Theory] + [InlineData("en-US", "ac", AreaUnit.Acre)] + [InlineData("en-US", "ha", AreaUnit.Hectare)] + [InlineData("en-US", "cm²", AreaUnit.SquareCentimeter)] + [InlineData("en-US", "dm²", AreaUnit.SquareDecimeter)] + [InlineData("en-US", "ft²", AreaUnit.SquareFoot)] + [InlineData("en-US", "in²", AreaUnit.SquareInch)] + [InlineData("en-US", "km²", AreaUnit.SquareKilometer)] + [InlineData("en-US", "m²", AreaUnit.SquareMeter)] + [InlineData("en-US", "µm²", AreaUnit.SquareMicrometer)] + [InlineData("en-US", "mi²", AreaUnit.SquareMile)] + [InlineData("en-US", "mm²", AreaUnit.SquareMillimeter)] + [InlineData("en-US", "nmi²", AreaUnit.SquareNauticalMile)] + [InlineData("en-US", "yd²", AreaUnit.SquareYard)] + [InlineData("en-US", "ft² (US)", AreaUnit.UsSurveySquareFoot)] + [InlineData("ru-RU", "акр", AreaUnit.Acre)] + [InlineData("ru-RU", "га", AreaUnit.Hectare)] + [InlineData("ru-RU", "см²", AreaUnit.SquareCentimeter)] + [InlineData("ru-RU", "дм²", AreaUnit.SquareDecimeter)] + [InlineData("ru-RU", "фут²", AreaUnit.SquareFoot)] + [InlineData("ru-RU", "дюйм²", AreaUnit.SquareInch)] + [InlineData("ru-RU", "км²", AreaUnit.SquareKilometer)] + [InlineData("ru-RU", "м²", AreaUnit.SquareMeter)] + [InlineData("ru-RU", "мкм²", AreaUnit.SquareMicrometer)] + [InlineData("ru-RU", "миля²", AreaUnit.SquareMile)] + [InlineData("ru-RU", "мм²", AreaUnit.SquareMillimeter)] + [InlineData("ru-RU", "морск.миля²", AreaUnit.SquareNauticalMile)] + [InlineData("ru-RU", "ярд²", AreaUnit.SquareYard)] + [InlineData("ru-RU", "фут² (US)", AreaUnit.UsSurveySquareFoot)] + [InlineData("zh-CN", "平方厘米", AreaUnit.SquareCentimeter)] + [InlineData("zh-CN", "平方分米", AreaUnit.SquareDecimeter)] + [InlineData("zh-CN", "平方英尺", AreaUnit.SquareFoot)] + [InlineData("zh-CN", "平方英寸", AreaUnit.SquareInch)] + [InlineData("zh-CN", "平方公里", AreaUnit.SquareKilometer)] + [InlineData("zh-CN", "平方米", AreaUnit.SquareMeter)] + [InlineData("zh-CN", "平方微米", AreaUnit.SquareMicrometer)] + [InlineData("zh-CN", "平方英里", AreaUnit.SquareMile)] + [InlineData("zh-CN", "平方毫米", AreaUnit.SquareMillimeter)] + [InlineData("zh-CN", "平方海里", AreaUnit.SquareNauticalMile)] + [InlineData("zh-CN", "平方码", AreaUnit.SquareYard)] + public void TryParseUnitWithCulture(string culture, string abbreviation, AreaUnit expectedUnit) + { + Assert.True(Area.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("zh-CN", "英亩")] // [Acre, Hectare] + public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) + { + Assert.False(Area.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out _)); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs index 97d8ea7d6a..e952925d43 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs @@ -944,443 +944,190 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = BitRate.ParseUnit("bit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.BitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("bps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.BitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("B/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.BytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Ebit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.ExabitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Ebps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.ExabitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("EB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.ExabytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Eibit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.ExbibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Eibps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.ExbibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("EiB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.ExbibytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Gibit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.GibibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Gibps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.GibibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("GiB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.GibibytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Gbit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.GigabitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Gbps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.GigabitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("GB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.GigabytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Kibit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.KibibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Kibps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.KibibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("KiB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.KibibytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("kbit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.KilobitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("kbps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.KilobitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("kB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.KilobytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Mibit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.MebibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Mibps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.MebibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("MiB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.MebibytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Mbit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.MegabitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Mbps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.MegabitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("MB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.MegabytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Pibit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.PebibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Pibps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.PebibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("PiB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.PebibytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Pbit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.PetabitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Pbps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.PetabitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("PB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.PetabytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Tibit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.TebibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Tibps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.TebibitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("TiB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.TebibytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Tbit/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.TerabitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("Tbps", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.TerabitPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BitRate.ParseUnit("TB/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BitRateUnit.TerabytePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("bit/s", BitRateUnit.BitPerSecond)] + [InlineData("bps", BitRateUnit.BitPerSecond)] + [InlineData("B/s", BitRateUnit.BytePerSecond)] + [InlineData("Ebit/s", BitRateUnit.ExabitPerSecond)] + [InlineData("Ebps", BitRateUnit.ExabitPerSecond)] + [InlineData("EB/s", BitRateUnit.ExabytePerSecond)] + [InlineData("Eibit/s", BitRateUnit.ExbibitPerSecond)] + [InlineData("Eibps", BitRateUnit.ExbibitPerSecond)] + [InlineData("EiB/s", BitRateUnit.ExbibytePerSecond)] + [InlineData("Gibit/s", BitRateUnit.GibibitPerSecond)] + [InlineData("Gibps", BitRateUnit.GibibitPerSecond)] + [InlineData("GiB/s", BitRateUnit.GibibytePerSecond)] + [InlineData("Gbit/s", BitRateUnit.GigabitPerSecond)] + [InlineData("Gbps", BitRateUnit.GigabitPerSecond)] + [InlineData("GB/s", BitRateUnit.GigabytePerSecond)] + [InlineData("Kibit/s", BitRateUnit.KibibitPerSecond)] + [InlineData("Kibps", BitRateUnit.KibibitPerSecond)] + [InlineData("KiB/s", BitRateUnit.KibibytePerSecond)] + [InlineData("kbit/s", BitRateUnit.KilobitPerSecond)] + [InlineData("kbps", BitRateUnit.KilobitPerSecond)] + [InlineData("kB/s", BitRateUnit.KilobytePerSecond)] + [InlineData("Mibit/s", BitRateUnit.MebibitPerSecond)] + [InlineData("Mibps", BitRateUnit.MebibitPerSecond)] + [InlineData("MiB/s", BitRateUnit.MebibytePerSecond)] + [InlineData("Mbit/s", BitRateUnit.MegabitPerSecond)] + [InlineData("Mbps", BitRateUnit.MegabitPerSecond)] + [InlineData("MB/s", BitRateUnit.MegabytePerSecond)] + [InlineData("Pibit/s", BitRateUnit.PebibitPerSecond)] + [InlineData("Pibps", BitRateUnit.PebibitPerSecond)] + [InlineData("PiB/s", BitRateUnit.PebibytePerSecond)] + [InlineData("Pbit/s", BitRateUnit.PetabitPerSecond)] + [InlineData("Pbps", BitRateUnit.PetabitPerSecond)] + [InlineData("PB/s", BitRateUnit.PetabytePerSecond)] + [InlineData("Tibit/s", BitRateUnit.TebibitPerSecond)] + [InlineData("Tibps", BitRateUnit.TebibitPerSecond)] + [InlineData("TiB/s", BitRateUnit.TebibytePerSecond)] + [InlineData("Tbit/s", BitRateUnit.TerabitPerSecond)] + [InlineData("Tbps", BitRateUnit.TerabitPerSecond)] + [InlineData("TB/s", BitRateUnit.TerabytePerSecond)] + public void ParseUnit(string abbreviation, BitRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + BitRateUnit parsedUnit = BitRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(BitRate.TryParseUnit("bit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.BitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("bps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.BitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("B/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.BytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Ebit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.ExabitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Ebps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.ExabitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("EB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.ExabytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Eibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.ExbibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Eibps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.ExbibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("EiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.ExbibytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Gibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.GibibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Gibps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.GibibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("GiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.GibibytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Gbit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.GigabitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Gbps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.GigabitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("GB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.GigabytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Kibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.KibibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Kibps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.KibibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("KiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.KibibytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("kbit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.KilobitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("kbps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.KilobitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("kB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.KilobytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Mibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.MebibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Mibps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.MebibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("MiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.MebibytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Mbit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.MegabitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Mbps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.MegabitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("MB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.MegabytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Pibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.PebibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Pibps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.PebibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("PiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.PebibytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Pbit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.PetabitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Pbps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.PetabitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("PB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.PetabytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Tibit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.TebibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Tibps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.TebibitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("TiB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.TebibytePerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Tbit/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.TerabitPerSecond, parsedUnit); - } - - { - Assert.True(BitRate.TryParseUnit("Tbps", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.TerabitPerSecond, parsedUnit); - } + [Theory] + [InlineData("en-US", "bit/s", BitRateUnit.BitPerSecond)] + [InlineData("en-US", "bps", BitRateUnit.BitPerSecond)] + [InlineData("en-US", "B/s", BitRateUnit.BytePerSecond)] + [InlineData("en-US", "Ebit/s", BitRateUnit.ExabitPerSecond)] + [InlineData("en-US", "Ebps", BitRateUnit.ExabitPerSecond)] + [InlineData("en-US", "EB/s", BitRateUnit.ExabytePerSecond)] + [InlineData("en-US", "Eibit/s", BitRateUnit.ExbibitPerSecond)] + [InlineData("en-US", "Eibps", BitRateUnit.ExbibitPerSecond)] + [InlineData("en-US", "EiB/s", BitRateUnit.ExbibytePerSecond)] + [InlineData("en-US", "Gibit/s", BitRateUnit.GibibitPerSecond)] + [InlineData("en-US", "Gibps", BitRateUnit.GibibitPerSecond)] + [InlineData("en-US", "GiB/s", BitRateUnit.GibibytePerSecond)] + [InlineData("en-US", "Gbit/s", BitRateUnit.GigabitPerSecond)] + [InlineData("en-US", "Gbps", BitRateUnit.GigabitPerSecond)] + [InlineData("en-US", "GB/s", BitRateUnit.GigabytePerSecond)] + [InlineData("en-US", "Kibit/s", BitRateUnit.KibibitPerSecond)] + [InlineData("en-US", "Kibps", BitRateUnit.KibibitPerSecond)] + [InlineData("en-US", "KiB/s", BitRateUnit.KibibytePerSecond)] + [InlineData("en-US", "kbit/s", BitRateUnit.KilobitPerSecond)] + [InlineData("en-US", "kbps", BitRateUnit.KilobitPerSecond)] + [InlineData("en-US", "kB/s", BitRateUnit.KilobytePerSecond)] + [InlineData("en-US", "Mibit/s", BitRateUnit.MebibitPerSecond)] + [InlineData("en-US", "Mibps", BitRateUnit.MebibitPerSecond)] + [InlineData("en-US", "MiB/s", BitRateUnit.MebibytePerSecond)] + [InlineData("en-US", "Mbit/s", BitRateUnit.MegabitPerSecond)] + [InlineData("en-US", "Mbps", BitRateUnit.MegabitPerSecond)] + [InlineData("en-US", "MB/s", BitRateUnit.MegabytePerSecond)] + [InlineData("en-US", "Pibit/s", BitRateUnit.PebibitPerSecond)] + [InlineData("en-US", "Pibps", BitRateUnit.PebibitPerSecond)] + [InlineData("en-US", "PiB/s", BitRateUnit.PebibytePerSecond)] + [InlineData("en-US", "Pbit/s", BitRateUnit.PetabitPerSecond)] + [InlineData("en-US", "Pbps", BitRateUnit.PetabitPerSecond)] + [InlineData("en-US", "PB/s", BitRateUnit.PetabytePerSecond)] + [InlineData("en-US", "Tibit/s", BitRateUnit.TebibitPerSecond)] + [InlineData("en-US", "Tibps", BitRateUnit.TebibitPerSecond)] + [InlineData("en-US", "TiB/s", BitRateUnit.TebibytePerSecond)] + [InlineData("en-US", "Tbit/s", BitRateUnit.TerabitPerSecond)] + [InlineData("en-US", "Tbps", BitRateUnit.TerabitPerSecond)] + [InlineData("en-US", "TB/s", BitRateUnit.TerabytePerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, BitRateUnit expectedUnit) + { + BitRateUnit parsedUnit = BitRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(BitRate.TryParseUnit("TB/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BitRateUnit.TerabytePerSecond, parsedUnit); - } + [Theory] + [InlineData("bit/s", BitRateUnit.BitPerSecond)] + [InlineData("bps", BitRateUnit.BitPerSecond)] + [InlineData("B/s", BitRateUnit.BytePerSecond)] + [InlineData("Ebit/s", BitRateUnit.ExabitPerSecond)] + [InlineData("Ebps", BitRateUnit.ExabitPerSecond)] + [InlineData("EB/s", BitRateUnit.ExabytePerSecond)] + [InlineData("Eibit/s", BitRateUnit.ExbibitPerSecond)] + [InlineData("Eibps", BitRateUnit.ExbibitPerSecond)] + [InlineData("EiB/s", BitRateUnit.ExbibytePerSecond)] + [InlineData("Gibit/s", BitRateUnit.GibibitPerSecond)] + [InlineData("Gibps", BitRateUnit.GibibitPerSecond)] + [InlineData("GiB/s", BitRateUnit.GibibytePerSecond)] + [InlineData("Gbit/s", BitRateUnit.GigabitPerSecond)] + [InlineData("Gbps", BitRateUnit.GigabitPerSecond)] + [InlineData("GB/s", BitRateUnit.GigabytePerSecond)] + [InlineData("Kibit/s", BitRateUnit.KibibitPerSecond)] + [InlineData("Kibps", BitRateUnit.KibibitPerSecond)] + [InlineData("KiB/s", BitRateUnit.KibibytePerSecond)] + [InlineData("kbit/s", BitRateUnit.KilobitPerSecond)] + [InlineData("kbps", BitRateUnit.KilobitPerSecond)] + [InlineData("kB/s", BitRateUnit.KilobytePerSecond)] + [InlineData("Mibit/s", BitRateUnit.MebibitPerSecond)] + [InlineData("Mibps", BitRateUnit.MebibitPerSecond)] + [InlineData("MiB/s", BitRateUnit.MebibytePerSecond)] + [InlineData("Mbit/s", BitRateUnit.MegabitPerSecond)] + [InlineData("Mbps", BitRateUnit.MegabitPerSecond)] + [InlineData("MB/s", BitRateUnit.MegabytePerSecond)] + [InlineData("Pibit/s", BitRateUnit.PebibitPerSecond)] + [InlineData("Pibps", BitRateUnit.PebibitPerSecond)] + [InlineData("PiB/s", BitRateUnit.PebibytePerSecond)] + [InlineData("Pbit/s", BitRateUnit.PetabitPerSecond)] + [InlineData("Pbps", BitRateUnit.PetabitPerSecond)] + [InlineData("PB/s", BitRateUnit.PetabytePerSecond)] + [InlineData("Tibit/s", BitRateUnit.TebibitPerSecond)] + [InlineData("Tibps", BitRateUnit.TebibitPerSecond)] + [InlineData("TiB/s", BitRateUnit.TebibytePerSecond)] + [InlineData("Tbit/s", BitRateUnit.TerabitPerSecond)] + [InlineData("Tbps", BitRateUnit.TerabitPerSecond)] + [InlineData("TB/s", BitRateUnit.TerabytePerSecond)] + public void TryParseUnit(string abbreviation, BitRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(BitRate.TryParseUnit(abbreviation, out BitRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "bit/s", BitRateUnit.BitPerSecond)] + [InlineData("en-US", "bps", BitRateUnit.BitPerSecond)] + [InlineData("en-US", "B/s", BitRateUnit.BytePerSecond)] + [InlineData("en-US", "Ebit/s", BitRateUnit.ExabitPerSecond)] + [InlineData("en-US", "Ebps", BitRateUnit.ExabitPerSecond)] + [InlineData("en-US", "EB/s", BitRateUnit.ExabytePerSecond)] + [InlineData("en-US", "Eibit/s", BitRateUnit.ExbibitPerSecond)] + [InlineData("en-US", "Eibps", BitRateUnit.ExbibitPerSecond)] + [InlineData("en-US", "EiB/s", BitRateUnit.ExbibytePerSecond)] + [InlineData("en-US", "Gibit/s", BitRateUnit.GibibitPerSecond)] + [InlineData("en-US", "Gibps", BitRateUnit.GibibitPerSecond)] + [InlineData("en-US", "GiB/s", BitRateUnit.GibibytePerSecond)] + [InlineData("en-US", "Gbit/s", BitRateUnit.GigabitPerSecond)] + [InlineData("en-US", "Gbps", BitRateUnit.GigabitPerSecond)] + [InlineData("en-US", "GB/s", BitRateUnit.GigabytePerSecond)] + [InlineData("en-US", "Kibit/s", BitRateUnit.KibibitPerSecond)] + [InlineData("en-US", "Kibps", BitRateUnit.KibibitPerSecond)] + [InlineData("en-US", "KiB/s", BitRateUnit.KibibytePerSecond)] + [InlineData("en-US", "kbit/s", BitRateUnit.KilobitPerSecond)] + [InlineData("en-US", "kbps", BitRateUnit.KilobitPerSecond)] + [InlineData("en-US", "kB/s", BitRateUnit.KilobytePerSecond)] + [InlineData("en-US", "Mibit/s", BitRateUnit.MebibitPerSecond)] + [InlineData("en-US", "Mibps", BitRateUnit.MebibitPerSecond)] + [InlineData("en-US", "MiB/s", BitRateUnit.MebibytePerSecond)] + [InlineData("en-US", "Mbit/s", BitRateUnit.MegabitPerSecond)] + [InlineData("en-US", "Mbps", BitRateUnit.MegabitPerSecond)] + [InlineData("en-US", "MB/s", BitRateUnit.MegabytePerSecond)] + [InlineData("en-US", "Pibit/s", BitRateUnit.PebibitPerSecond)] + [InlineData("en-US", "Pibps", BitRateUnit.PebibitPerSecond)] + [InlineData("en-US", "PiB/s", BitRateUnit.PebibytePerSecond)] + [InlineData("en-US", "Pbit/s", BitRateUnit.PetabitPerSecond)] + [InlineData("en-US", "Pbps", BitRateUnit.PetabitPerSecond)] + [InlineData("en-US", "PB/s", BitRateUnit.PetabytePerSecond)] + [InlineData("en-US", "Tibit/s", BitRateUnit.TebibitPerSecond)] + [InlineData("en-US", "Tibps", BitRateUnit.TebibitPerSecond)] + [InlineData("en-US", "TiB/s", BitRateUnit.TebibytePerSecond)] + [InlineData("en-US", "Tbit/s", BitRateUnit.TerabitPerSecond)] + [InlineData("en-US", "Tbps", BitRateUnit.TerabitPerSecond)] + [InlineData("en-US", "TB/s", BitRateUnit.TerabytePerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, BitRateUnit expectedUnit) + { + Assert.True(BitRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out BitRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs index 8d53bb7b45..421941a2fa 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs @@ -246,47 +246,46 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] + [InlineData("kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] + [InlineData("lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] + public void ParseUnit(string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) { - try - { - var parsedUnit = BrakeSpecificFuelConsumption.ParseUnit("g/kWh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BrakeSpecificFuelConsumption.ParseUnit("kg/J", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = BrakeSpecificFuelConsumption.ParseUnit("lb/hph", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + BrakeSpecificFuelConsumptionUnit parsedUnit = BrakeSpecificFuelConsumption.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] + [InlineData("en-US", "kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] + [InlineData("en-US", "lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] + public void ParseUnitWithCulture(string culture, string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) { - { - Assert.True(BrakeSpecificFuelConsumption.TryParseUnit("g/kWh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour, parsedUnit); - } - - { - Assert.True(BrakeSpecificFuelConsumption.TryParseUnit("kg/J", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.KilogramPerJoule, parsedUnit); - } + BrakeSpecificFuelConsumptionUnit parsedUnit = BrakeSpecificFuelConsumption.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(BrakeSpecificFuelConsumption.TryParseUnit("lb/hph", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour, parsedUnit); - } + [Theory] + [InlineData("g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] + [InlineData("kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] + [InlineData("lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] + public void TryParseUnit(string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(BrakeSpecificFuelConsumption.TryParseUnit(abbreviation, out BrakeSpecificFuelConsumptionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] + [InlineData("en-US", "kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] + [InlineData("en-US", "lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] + public void TryParseUnitWithCulture(string culture, string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) + { + Assert.True(BrakeSpecificFuelConsumption.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out BrakeSpecificFuelConsumptionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs index 74fd690b22..288238184e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs @@ -326,81 +326,62 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("F", CapacitanceUnit.Farad)] + [InlineData("kF", CapacitanceUnit.Kilofarad)] + [InlineData("MF", CapacitanceUnit.Megafarad)] + [InlineData("µF", CapacitanceUnit.Microfarad)] + [InlineData("mF", CapacitanceUnit.Millifarad)] + [InlineData("nF", CapacitanceUnit.Nanofarad)] + [InlineData("pF", CapacitanceUnit.Picofarad)] + public void ParseUnit(string abbreviation, CapacitanceUnit expectedUnit) { - try - { - var parsedUnit = Capacitance.ParseUnit("F", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CapacitanceUnit.Farad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Capacitance.ParseUnit("kF", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CapacitanceUnit.Kilofarad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Capacitance.ParseUnit("MF", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CapacitanceUnit.Megafarad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Capacitance.ParseUnit("µF", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CapacitanceUnit.Microfarad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Capacitance.ParseUnit("mF", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CapacitanceUnit.Millifarad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Capacitance.ParseUnit("nF", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CapacitanceUnit.Nanofarad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Capacitance.ParseUnit("pF", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CapacitanceUnit.Picofarad, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + CapacitanceUnit parsedUnit = Capacitance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "F", CapacitanceUnit.Farad)] + [InlineData("en-US", "kF", CapacitanceUnit.Kilofarad)] + [InlineData("en-US", "MF", CapacitanceUnit.Megafarad)] + [InlineData("en-US", "µF", CapacitanceUnit.Microfarad)] + [InlineData("en-US", "mF", CapacitanceUnit.Millifarad)] + [InlineData("en-US", "nF", CapacitanceUnit.Nanofarad)] + [InlineData("en-US", "pF", CapacitanceUnit.Picofarad)] + public void ParseUnitWithCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) { - { - Assert.True(Capacitance.TryParseUnit("F", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CapacitanceUnit.Farad, parsedUnit); - } - - { - Assert.True(Capacitance.TryParseUnit("kF", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CapacitanceUnit.Kilofarad, parsedUnit); - } - - { - Assert.True(Capacitance.TryParseUnit("µF", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CapacitanceUnit.Microfarad, parsedUnit); - } - - { - Assert.True(Capacitance.TryParseUnit("nF", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CapacitanceUnit.Nanofarad, parsedUnit); - } + CapacitanceUnit parsedUnit = Capacitance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Capacitance.TryParseUnit("pF", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CapacitanceUnit.Picofarad, parsedUnit); - } + [Theory] + [InlineData("F", CapacitanceUnit.Farad)] + [InlineData("kF", CapacitanceUnit.Kilofarad)] + [InlineData("MF", CapacitanceUnit.Megafarad)] + [InlineData("µF", CapacitanceUnit.Microfarad)] + [InlineData("mF", CapacitanceUnit.Millifarad)] + [InlineData("nF", CapacitanceUnit.Nanofarad)] + [InlineData("pF", CapacitanceUnit.Picofarad)] + public void TryParseUnit(string abbreviation, CapacitanceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Capacitance.TryParseUnit(abbreviation, out CapacitanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "F", CapacitanceUnit.Farad)] + [InlineData("en-US", "kF", CapacitanceUnit.Kilofarad)] + [InlineData("en-US", "MF", CapacitanceUnit.Megafarad)] + [InlineData("en-US", "µF", CapacitanceUnit.Microfarad)] + [InlineData("en-US", "mF", CapacitanceUnit.Millifarad)] + [InlineData("en-US", "nF", CapacitanceUnit.Nanofarad)] + [InlineData("en-US", "pF", CapacitanceUnit.Picofarad)] + public void TryParseUnitWithCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) + { + Assert.True(Capacitance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out CapacitanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs index 3ac807c0c4..925c4f0825 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs @@ -315,80 +315,58 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("°C⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeCelsius)] + [InlineData("°F⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit)] + [InlineData("K⁻¹", CoefficientOfThermalExpansionUnit.PerKelvin)] + [InlineData("ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] + [InlineData("ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] + [InlineData("ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] + public void ParseUnit(string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) { - try - { - var parsedUnit = CoefficientOfThermalExpansion.ParseUnit("°C⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = CoefficientOfThermalExpansion.ParseUnit("°F⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = CoefficientOfThermalExpansion.ParseUnit("K⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = CoefficientOfThermalExpansion.ParseUnit("ppm/°C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = CoefficientOfThermalExpansion.ParseUnit("ppm/°F", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = CoefficientOfThermalExpansion.ParseUnit("ppm/K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + CoefficientOfThermalExpansionUnit parsedUnit = CoefficientOfThermalExpansion.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "°C⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeCelsius)] + [InlineData("en-US", "°F⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit)] + [InlineData("en-US", "K⁻¹", CoefficientOfThermalExpansionUnit.PerKelvin)] + [InlineData("en-US", "ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] + [InlineData("en-US", "ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] + [InlineData("en-US", "ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] + public void ParseUnitWithCulture(string culture, string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) { - { - Assert.True(CoefficientOfThermalExpansion.TryParseUnit("°C⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerDegreeCelsius, parsedUnit); - } - - { - Assert.True(CoefficientOfThermalExpansion.TryParseUnit("°F⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit, parsedUnit); - } - - { - Assert.True(CoefficientOfThermalExpansion.TryParseUnit("K⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CoefficientOfThermalExpansionUnit.PerKelvin, parsedUnit); - } - - { - Assert.True(CoefficientOfThermalExpansion.TryParseUnit("ppm/°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius, parsedUnit); - } - - { - Assert.True(CoefficientOfThermalExpansion.TryParseUnit("ppm/°F", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit, parsedUnit); - } + CoefficientOfThermalExpansionUnit parsedUnit = CoefficientOfThermalExpansion.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(CoefficientOfThermalExpansion.TryParseUnit("ppm/K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CoefficientOfThermalExpansionUnit.PpmPerKelvin, parsedUnit); - } + [Theory] + [InlineData("°C⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeCelsius)] + [InlineData("°F⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit)] + [InlineData("K⁻¹", CoefficientOfThermalExpansionUnit.PerKelvin)] + [InlineData("ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] + [InlineData("ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] + [InlineData("ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] + public void TryParseUnit(string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(CoefficientOfThermalExpansion.TryParseUnit(abbreviation, out CoefficientOfThermalExpansionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "°C⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeCelsius)] + [InlineData("en-US", "°F⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit)] + [InlineData("en-US", "K⁻¹", CoefficientOfThermalExpansionUnit.PerKelvin)] + [InlineData("en-US", "ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] + [InlineData("en-US", "ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] + [InlineData("en-US", "ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] + public void TryParseUnitWithCulture(string culture, string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) + { + Assert.True(CoefficientOfThermalExpansion.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out CoefficientOfThermalExpansionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs index 2246da04dc..10ed669227 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs @@ -429,168 +429,90 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Compressibility.ParseUnit("atm⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InverseAtmosphere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("1/atm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InverseAtmosphere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("bar⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InverseBar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("1/bar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InverseBar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("kPa⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InverseKilopascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("1/kPa", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InverseKilopascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("MPa⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InverseMegapascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("1/MPa", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InverseMegapascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("mbar⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InverseMillibar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("1/mbar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InverseMillibar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("Pa⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InversePascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("1/Pa", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InversePascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("psi⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InversePoundForcePerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Compressibility.ParseUnit("1/psi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(CompressibilityUnit.InversePoundForcePerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("atm⁻¹", CompressibilityUnit.InverseAtmosphere)] + [InlineData("1/atm", CompressibilityUnit.InverseAtmosphere)] + [InlineData("bar⁻¹", CompressibilityUnit.InverseBar)] + [InlineData("1/bar", CompressibilityUnit.InverseBar)] + [InlineData("kPa⁻¹", CompressibilityUnit.InverseKilopascal)] + [InlineData("1/kPa", CompressibilityUnit.InverseKilopascal)] + [InlineData("MPa⁻¹", CompressibilityUnit.InverseMegapascal)] + [InlineData("1/MPa", CompressibilityUnit.InverseMegapascal)] + [InlineData("mbar⁻¹", CompressibilityUnit.InverseMillibar)] + [InlineData("1/mbar", CompressibilityUnit.InverseMillibar)] + [InlineData("Pa⁻¹", CompressibilityUnit.InversePascal)] + [InlineData("1/Pa", CompressibilityUnit.InversePascal)] + [InlineData("psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] + [InlineData("1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] + public void ParseUnit(string abbreviation, CompressibilityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + CompressibilityUnit parsedUnit = Compressibility.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Compressibility.TryParseUnit("atm⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InverseAtmosphere, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("1/atm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InverseAtmosphere, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("bar⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InverseBar, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("1/bar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InverseBar, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("kPa⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InverseKilopascal, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("1/kPa", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InverseKilopascal, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("MPa⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InverseMegapascal, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("1/MPa", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InverseMegapascal, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("mbar⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InverseMillibar, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("1/mbar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InverseMillibar, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("Pa⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InversePascal, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("1/Pa", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InversePascal, parsedUnit); - } - - { - Assert.True(Compressibility.TryParseUnit("psi⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InversePoundForcePerSquareInch, parsedUnit); - } + [Theory] + [InlineData("en-US", "atm⁻¹", CompressibilityUnit.InverseAtmosphere)] + [InlineData("en-US", "1/atm", CompressibilityUnit.InverseAtmosphere)] + [InlineData("en-US", "bar⁻¹", CompressibilityUnit.InverseBar)] + [InlineData("en-US", "1/bar", CompressibilityUnit.InverseBar)] + [InlineData("en-US", "kPa⁻¹", CompressibilityUnit.InverseKilopascal)] + [InlineData("en-US", "1/kPa", CompressibilityUnit.InverseKilopascal)] + [InlineData("en-US", "MPa⁻¹", CompressibilityUnit.InverseMegapascal)] + [InlineData("en-US", "1/MPa", CompressibilityUnit.InverseMegapascal)] + [InlineData("en-US", "mbar⁻¹", CompressibilityUnit.InverseMillibar)] + [InlineData("en-US", "1/mbar", CompressibilityUnit.InverseMillibar)] + [InlineData("en-US", "Pa⁻¹", CompressibilityUnit.InversePascal)] + [InlineData("en-US", "1/Pa", CompressibilityUnit.InversePascal)] + [InlineData("en-US", "psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] + [InlineData("en-US", "1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] + public void ParseUnitWithCulture(string culture, string abbreviation, CompressibilityUnit expectedUnit) + { + CompressibilityUnit parsedUnit = Compressibility.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Compressibility.TryParseUnit("1/psi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(CompressibilityUnit.InversePoundForcePerSquareInch, parsedUnit); - } + [Theory] + [InlineData("atm⁻¹", CompressibilityUnit.InverseAtmosphere)] + [InlineData("1/atm", CompressibilityUnit.InverseAtmosphere)] + [InlineData("bar⁻¹", CompressibilityUnit.InverseBar)] + [InlineData("1/bar", CompressibilityUnit.InverseBar)] + [InlineData("kPa⁻¹", CompressibilityUnit.InverseKilopascal)] + [InlineData("1/kPa", CompressibilityUnit.InverseKilopascal)] + [InlineData("MPa⁻¹", CompressibilityUnit.InverseMegapascal)] + [InlineData("1/MPa", CompressibilityUnit.InverseMegapascal)] + [InlineData("mbar⁻¹", CompressibilityUnit.InverseMillibar)] + [InlineData("1/mbar", CompressibilityUnit.InverseMillibar)] + [InlineData("Pa⁻¹", CompressibilityUnit.InversePascal)] + [InlineData("1/Pa", CompressibilityUnit.InversePascal)] + [InlineData("psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] + [InlineData("1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] + public void TryParseUnit(string abbreviation, CompressibilityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Compressibility.TryParseUnit(abbreviation, out CompressibilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "atm⁻¹", CompressibilityUnit.InverseAtmosphere)] + [InlineData("en-US", "1/atm", CompressibilityUnit.InverseAtmosphere)] + [InlineData("en-US", "bar⁻¹", CompressibilityUnit.InverseBar)] + [InlineData("en-US", "1/bar", CompressibilityUnit.InverseBar)] + [InlineData("en-US", "kPa⁻¹", CompressibilityUnit.InverseKilopascal)] + [InlineData("en-US", "1/kPa", CompressibilityUnit.InverseKilopascal)] + [InlineData("en-US", "MPa⁻¹", CompressibilityUnit.InverseMegapascal)] + [InlineData("en-US", "1/MPa", CompressibilityUnit.InverseMegapascal)] + [InlineData("en-US", "mbar⁻¹", CompressibilityUnit.InverseMillibar)] + [InlineData("en-US", "1/mbar", CompressibilityUnit.InverseMillibar)] + [InlineData("en-US", "Pa⁻¹", CompressibilityUnit.InversePascal)] + [InlineData("en-US", "1/Pa", CompressibilityUnit.InversePascal)] + [InlineData("en-US", "psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] + [InlineData("en-US", "1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] + public void TryParseUnitWithCulture(string culture, string abbreviation, CompressibilityUnit expectedUnit) + { + Assert.True(Compressibility.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out CompressibilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs index 9e4ed7ff8c..1028f7da0a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs @@ -1517,674 +1517,266 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Density.ParseUnit("cg/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.CentigramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("cg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.CentigramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("cg/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.CentigramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("dg/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.DecigramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("dg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.DecigramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("dg/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.DecigramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("fg/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.FemtogramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("fg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.FemtogramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("fg/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.FemtogramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("g/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.GramPerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("g/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.GramPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("g/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.GramPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("g/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.GramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("г/м³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DensityUnit.GramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("g/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.GramPerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("g/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.GramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("g/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.GramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("g/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.GramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("kg/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.KilogramPerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("kg/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.KilogramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("кг/м³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DensityUnit.KilogramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("kg/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.KilogramPerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("kg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.KilogramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("kip/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.KilopoundPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("kip/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.KilopoundPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("kip/yd³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.KilopoundPerCubicYard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("µg/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.MicrogramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("мкг/м³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DensityUnit.MicrogramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("µg/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.MicrogramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("µg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.MicrogramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("µg/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.MicrogramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("mg/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.MilligramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("мг/м³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DensityUnit.MilligramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("mg/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.MilligramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("mg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.MilligramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("mg/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.MilligramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("ng/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.NanogramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("ng/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.NanogramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("ng/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.NanogramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("pg/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.PicogramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("pg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.PicogramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("pg/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.PicogramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("lb/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.PoundPerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("lb/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.PoundPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("lb/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.PoundPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("lb/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.PoundPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("lb/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.PoundPerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("lb/yd³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.PoundPerCubicYard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("ppg (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.PoundPerImperialGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("ppg (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.PoundPerUSGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("slug/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.SlugPerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("slug/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.SlugPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("slug/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.SlugPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("slug/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.SlugPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("slug/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.SlugPerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("t/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.TonnePerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("t/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.TonnePerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("t/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.TonnePerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("t/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.TonnePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Density.ParseUnit("t/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DensityUnit.TonnePerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cg/dl", DensityUnit.CentigramPerDeciliter)] + [InlineData("cg/l", DensityUnit.CentigramPerLiter)] + [InlineData("cg/ml", DensityUnit.CentigramPerMilliliter)] + [InlineData("dg/dl", DensityUnit.DecigramPerDeciliter)] + [InlineData("dg/l", DensityUnit.DecigramPerLiter)] + [InlineData("dg/ml", DensityUnit.DecigramPerMilliliter)] + [InlineData("fg/dl", DensityUnit.FemtogramPerDeciliter)] + [InlineData("fg/l", DensityUnit.FemtogramPerLiter)] + [InlineData("fg/ml", DensityUnit.FemtogramPerMilliliter)] + [InlineData("g/cm³", DensityUnit.GramPerCubicCentimeter)] + [InlineData("g/ft³", DensityUnit.GramPerCubicFoot)] + [InlineData("g/in³", DensityUnit.GramPerCubicInch)] + [InlineData("g/m³", DensityUnit.GramPerCubicMeter)] + [InlineData("g/mm³", DensityUnit.GramPerCubicMillimeter)] + [InlineData("g/dl", DensityUnit.GramPerDeciliter)] + [InlineData("g/l", DensityUnit.GramPerLiter)] + [InlineData("g/ml", DensityUnit.GramPerMilliliter)] + [InlineData("kg/cm³", DensityUnit.KilogramPerCubicCentimeter)] + [InlineData("kg/m³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("kg/mm³", DensityUnit.KilogramPerCubicMillimeter)] + [InlineData("kg/l", DensityUnit.KilogramPerLiter)] + [InlineData("kip/ft³", DensityUnit.KilopoundPerCubicFoot)] + [InlineData("kip/in³", DensityUnit.KilopoundPerCubicInch)] + [InlineData("kip/yd³", DensityUnit.KilopoundPerCubicYard)] + [InlineData("µg/m³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("µg/dl", DensityUnit.MicrogramPerDeciliter)] + [InlineData("µg/l", DensityUnit.MicrogramPerLiter)] + [InlineData("µg/ml", DensityUnit.MicrogramPerMilliliter)] + [InlineData("mg/m³", DensityUnit.MilligramPerCubicMeter)] + [InlineData("mg/dl", DensityUnit.MilligramPerDeciliter)] + [InlineData("mg/l", DensityUnit.MilligramPerLiter)] + [InlineData("mg/ml", DensityUnit.MilligramPerMilliliter)] + [InlineData("ng/dl", DensityUnit.NanogramPerDeciliter)] + [InlineData("ng/l", DensityUnit.NanogramPerLiter)] + [InlineData("ng/ml", DensityUnit.NanogramPerMilliliter)] + [InlineData("pg/dl", DensityUnit.PicogramPerDeciliter)] + [InlineData("pg/l", DensityUnit.PicogramPerLiter)] + [InlineData("pg/ml", DensityUnit.PicogramPerMilliliter)] + [InlineData("lb/cm³", DensityUnit.PoundPerCubicCentimeter)] + [InlineData("lb/ft³", DensityUnit.PoundPerCubicFoot)] + [InlineData("lb/in³", DensityUnit.PoundPerCubicInch)] + [InlineData("lb/m³", DensityUnit.PoundPerCubicMeter)] + [InlineData("lb/mm³", DensityUnit.PoundPerCubicMillimeter)] + [InlineData("lb/yd³", DensityUnit.PoundPerCubicYard)] + [InlineData("ppg (imp.)", DensityUnit.PoundPerImperialGallon)] + [InlineData("ppg (U.S.)", DensityUnit.PoundPerUSGallon)] + [InlineData("slug/cm³", DensityUnit.SlugPerCubicCentimeter)] + [InlineData("slug/ft³", DensityUnit.SlugPerCubicFoot)] + [InlineData("slug/in³", DensityUnit.SlugPerCubicInch)] + [InlineData("slug/m³", DensityUnit.SlugPerCubicMeter)] + [InlineData("slug/mm³", DensityUnit.SlugPerCubicMillimeter)] + [InlineData("t/cm³", DensityUnit.TonnePerCubicCentimeter)] + [InlineData("t/ft³", DensityUnit.TonnePerCubicFoot)] + [InlineData("t/in³", DensityUnit.TonnePerCubicInch)] + [InlineData("t/m³", DensityUnit.TonnePerCubicMeter)] + [InlineData("t/mm³", DensityUnit.TonnePerCubicMillimeter)] + public void ParseUnit(string abbreviation, DensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + DensityUnit parsedUnit = Density.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Density.TryParseUnit("cg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.CentigramPerDeciliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("cg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.CentigramPerLiter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("cg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.CentigramPerMilliliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("dg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.DecigramPerDeciliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("dg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.DecigramPerLiter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("dg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.DecigramPerMilliliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("fg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.FemtogramPerDeciliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("fg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.FemtogramPerLiter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("fg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.FemtogramPerMilliliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("g/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.GramPerCubicCentimeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("g/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.GramPerCubicFoot, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("g/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.GramPerCubicInch, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("g/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.GramPerCubicMeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("г/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DensityUnit.GramPerCubicMeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("g/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.GramPerCubicMillimeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("g/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.GramPerDeciliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("g/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.GramPerLiter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("g/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.GramPerMilliliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("kg/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.KilogramPerCubicCentimeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("kg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.KilogramPerCubicMeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("кг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DensityUnit.KilogramPerCubicMeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("kg/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.KilogramPerCubicMillimeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("kg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.KilogramPerLiter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("kip/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.KilopoundPerCubicFoot, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("kip/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.KilopoundPerCubicInch, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("kip/yd³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.KilopoundPerCubicYard, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("µg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.MicrogramPerCubicMeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("мкг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DensityUnit.MicrogramPerCubicMeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("µg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.MicrogramPerDeciliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("µg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.MicrogramPerLiter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("µg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.MicrogramPerMilliliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("mg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.MilligramPerCubicMeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("мг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DensityUnit.MilligramPerCubicMeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("mg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.MilligramPerDeciliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("mg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.MilligramPerLiter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("mg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.MilligramPerMilliliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("ng/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.NanogramPerDeciliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("ng/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.NanogramPerLiter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("ng/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.NanogramPerMilliliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("pg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.PicogramPerDeciliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("pg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.PicogramPerLiter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("pg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.PicogramPerMilliliter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("lb/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.PoundPerCubicCentimeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("lb/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.PoundPerCubicFoot, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("lb/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.PoundPerCubicInch, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("lb/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.PoundPerCubicMeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("lb/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.PoundPerCubicMillimeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("lb/yd³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.PoundPerCubicYard, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("ppg (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.PoundPerImperialGallon, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("ppg (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.PoundPerUSGallon, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("slug/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.SlugPerCubicCentimeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("slug/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.SlugPerCubicFoot, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("slug/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.SlugPerCubicInch, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("slug/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.SlugPerCubicMeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("slug/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.SlugPerCubicMillimeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("t/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.TonnePerCubicCentimeter, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("t/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.TonnePerCubicFoot, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("t/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.TonnePerCubicInch, parsedUnit); - } - - { - Assert.True(Density.TryParseUnit("t/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.TonnePerCubicMeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "cg/dl", DensityUnit.CentigramPerDeciliter)] + [InlineData("en-US", "cg/l", DensityUnit.CentigramPerLiter)] + [InlineData("en-US", "cg/ml", DensityUnit.CentigramPerMilliliter)] + [InlineData("en-US", "dg/dl", DensityUnit.DecigramPerDeciliter)] + [InlineData("en-US", "dg/l", DensityUnit.DecigramPerLiter)] + [InlineData("en-US", "dg/ml", DensityUnit.DecigramPerMilliliter)] + [InlineData("en-US", "fg/dl", DensityUnit.FemtogramPerDeciliter)] + [InlineData("en-US", "fg/l", DensityUnit.FemtogramPerLiter)] + [InlineData("en-US", "fg/ml", DensityUnit.FemtogramPerMilliliter)] + [InlineData("en-US", "g/cm³", DensityUnit.GramPerCubicCentimeter)] + [InlineData("en-US", "g/ft³", DensityUnit.GramPerCubicFoot)] + [InlineData("en-US", "g/in³", DensityUnit.GramPerCubicInch)] + [InlineData("en-US", "g/m³", DensityUnit.GramPerCubicMeter)] + [InlineData("en-US", "g/mm³", DensityUnit.GramPerCubicMillimeter)] + [InlineData("en-US", "g/dl", DensityUnit.GramPerDeciliter)] + [InlineData("en-US", "g/l", DensityUnit.GramPerLiter)] + [InlineData("en-US", "g/ml", DensityUnit.GramPerMilliliter)] + [InlineData("en-US", "kg/cm³", DensityUnit.KilogramPerCubicCentimeter)] + [InlineData("en-US", "kg/m³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("en-US", "kg/mm³", DensityUnit.KilogramPerCubicMillimeter)] + [InlineData("en-US", "kg/l", DensityUnit.KilogramPerLiter)] + [InlineData("en-US", "kip/ft³", DensityUnit.KilopoundPerCubicFoot)] + [InlineData("en-US", "kip/in³", DensityUnit.KilopoundPerCubicInch)] + [InlineData("en-US", "kip/yd³", DensityUnit.KilopoundPerCubicYard)] + [InlineData("en-US", "µg/m³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("en-US", "µg/dl", DensityUnit.MicrogramPerDeciliter)] + [InlineData("en-US", "µg/l", DensityUnit.MicrogramPerLiter)] + [InlineData("en-US", "µg/ml", DensityUnit.MicrogramPerMilliliter)] + [InlineData("en-US", "mg/m³", DensityUnit.MilligramPerCubicMeter)] + [InlineData("en-US", "mg/dl", DensityUnit.MilligramPerDeciliter)] + [InlineData("en-US", "mg/l", DensityUnit.MilligramPerLiter)] + [InlineData("en-US", "mg/ml", DensityUnit.MilligramPerMilliliter)] + [InlineData("en-US", "ng/dl", DensityUnit.NanogramPerDeciliter)] + [InlineData("en-US", "ng/l", DensityUnit.NanogramPerLiter)] + [InlineData("en-US", "ng/ml", DensityUnit.NanogramPerMilliliter)] + [InlineData("en-US", "pg/dl", DensityUnit.PicogramPerDeciliter)] + [InlineData("en-US", "pg/l", DensityUnit.PicogramPerLiter)] + [InlineData("en-US", "pg/ml", DensityUnit.PicogramPerMilliliter)] + [InlineData("en-US", "lb/cm³", DensityUnit.PoundPerCubicCentimeter)] + [InlineData("en-US", "lb/ft³", DensityUnit.PoundPerCubicFoot)] + [InlineData("en-US", "lb/in³", DensityUnit.PoundPerCubicInch)] + [InlineData("en-US", "lb/m³", DensityUnit.PoundPerCubicMeter)] + [InlineData("en-US", "lb/mm³", DensityUnit.PoundPerCubicMillimeter)] + [InlineData("en-US", "lb/yd³", DensityUnit.PoundPerCubicYard)] + [InlineData("en-US", "ppg (imp.)", DensityUnit.PoundPerImperialGallon)] + [InlineData("en-US", "ppg (U.S.)", DensityUnit.PoundPerUSGallon)] + [InlineData("en-US", "slug/cm³", DensityUnit.SlugPerCubicCentimeter)] + [InlineData("en-US", "slug/ft³", DensityUnit.SlugPerCubicFoot)] + [InlineData("en-US", "slug/in³", DensityUnit.SlugPerCubicInch)] + [InlineData("en-US", "slug/m³", DensityUnit.SlugPerCubicMeter)] + [InlineData("en-US", "slug/mm³", DensityUnit.SlugPerCubicMillimeter)] + [InlineData("en-US", "t/cm³", DensityUnit.TonnePerCubicCentimeter)] + [InlineData("en-US", "t/ft³", DensityUnit.TonnePerCubicFoot)] + [InlineData("en-US", "t/in³", DensityUnit.TonnePerCubicInch)] + [InlineData("en-US", "t/m³", DensityUnit.TonnePerCubicMeter)] + [InlineData("en-US", "t/mm³", DensityUnit.TonnePerCubicMillimeter)] + [InlineData("ru-RU", "г/м³", DensityUnit.GramPerCubicMeter)] + [InlineData("ru-RU", "кг/м³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("ru-RU", "мкг/м³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("ru-RU", "мг/м³", DensityUnit.MilligramPerCubicMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, DensityUnit expectedUnit) + { + DensityUnit parsedUnit = Density.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Density.TryParseUnit("t/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DensityUnit.TonnePerCubicMillimeter, parsedUnit); - } + [Theory] + [InlineData("cg/dl", DensityUnit.CentigramPerDeciliter)] + [InlineData("cg/l", DensityUnit.CentigramPerLiter)] + [InlineData("cg/ml", DensityUnit.CentigramPerMilliliter)] + [InlineData("dg/dl", DensityUnit.DecigramPerDeciliter)] + [InlineData("dg/l", DensityUnit.DecigramPerLiter)] + [InlineData("dg/ml", DensityUnit.DecigramPerMilliliter)] + [InlineData("fg/dl", DensityUnit.FemtogramPerDeciliter)] + [InlineData("fg/l", DensityUnit.FemtogramPerLiter)] + [InlineData("fg/ml", DensityUnit.FemtogramPerMilliliter)] + [InlineData("g/cm³", DensityUnit.GramPerCubicCentimeter)] + [InlineData("g/ft³", DensityUnit.GramPerCubicFoot)] + [InlineData("g/in³", DensityUnit.GramPerCubicInch)] + [InlineData("g/m³", DensityUnit.GramPerCubicMeter)] + [InlineData("g/mm³", DensityUnit.GramPerCubicMillimeter)] + [InlineData("g/dl", DensityUnit.GramPerDeciliter)] + [InlineData("g/l", DensityUnit.GramPerLiter)] + [InlineData("g/ml", DensityUnit.GramPerMilliliter)] + [InlineData("kg/cm³", DensityUnit.KilogramPerCubicCentimeter)] + [InlineData("kg/m³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("kg/mm³", DensityUnit.KilogramPerCubicMillimeter)] + [InlineData("kg/l", DensityUnit.KilogramPerLiter)] + [InlineData("kip/ft³", DensityUnit.KilopoundPerCubicFoot)] + [InlineData("kip/in³", DensityUnit.KilopoundPerCubicInch)] + [InlineData("kip/yd³", DensityUnit.KilopoundPerCubicYard)] + [InlineData("µg/m³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("µg/dl", DensityUnit.MicrogramPerDeciliter)] + [InlineData("µg/l", DensityUnit.MicrogramPerLiter)] + [InlineData("µg/ml", DensityUnit.MicrogramPerMilliliter)] + [InlineData("mg/m³", DensityUnit.MilligramPerCubicMeter)] + [InlineData("mg/dl", DensityUnit.MilligramPerDeciliter)] + [InlineData("mg/l", DensityUnit.MilligramPerLiter)] + [InlineData("mg/ml", DensityUnit.MilligramPerMilliliter)] + [InlineData("ng/dl", DensityUnit.NanogramPerDeciliter)] + [InlineData("ng/l", DensityUnit.NanogramPerLiter)] + [InlineData("ng/ml", DensityUnit.NanogramPerMilliliter)] + [InlineData("pg/dl", DensityUnit.PicogramPerDeciliter)] + [InlineData("pg/l", DensityUnit.PicogramPerLiter)] + [InlineData("pg/ml", DensityUnit.PicogramPerMilliliter)] + [InlineData("lb/cm³", DensityUnit.PoundPerCubicCentimeter)] + [InlineData("lb/ft³", DensityUnit.PoundPerCubicFoot)] + [InlineData("lb/in³", DensityUnit.PoundPerCubicInch)] + [InlineData("lb/m³", DensityUnit.PoundPerCubicMeter)] + [InlineData("lb/mm³", DensityUnit.PoundPerCubicMillimeter)] + [InlineData("lb/yd³", DensityUnit.PoundPerCubicYard)] + [InlineData("ppg (imp.)", DensityUnit.PoundPerImperialGallon)] + [InlineData("ppg (U.S.)", DensityUnit.PoundPerUSGallon)] + [InlineData("slug/cm³", DensityUnit.SlugPerCubicCentimeter)] + [InlineData("slug/ft³", DensityUnit.SlugPerCubicFoot)] + [InlineData("slug/in³", DensityUnit.SlugPerCubicInch)] + [InlineData("slug/m³", DensityUnit.SlugPerCubicMeter)] + [InlineData("slug/mm³", DensityUnit.SlugPerCubicMillimeter)] + [InlineData("t/cm³", DensityUnit.TonnePerCubicCentimeter)] + [InlineData("t/ft³", DensityUnit.TonnePerCubicFoot)] + [InlineData("t/in³", DensityUnit.TonnePerCubicInch)] + [InlineData("t/m³", DensityUnit.TonnePerCubicMeter)] + [InlineData("t/mm³", DensityUnit.TonnePerCubicMillimeter)] + public void TryParseUnit(string abbreviation, DensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Density.TryParseUnit(abbreviation, out DensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cg/dl", DensityUnit.CentigramPerDeciliter)] + [InlineData("en-US", "cg/l", DensityUnit.CentigramPerLiter)] + [InlineData("en-US", "cg/ml", DensityUnit.CentigramPerMilliliter)] + [InlineData("en-US", "dg/dl", DensityUnit.DecigramPerDeciliter)] + [InlineData("en-US", "dg/l", DensityUnit.DecigramPerLiter)] + [InlineData("en-US", "dg/ml", DensityUnit.DecigramPerMilliliter)] + [InlineData("en-US", "fg/dl", DensityUnit.FemtogramPerDeciliter)] + [InlineData("en-US", "fg/l", DensityUnit.FemtogramPerLiter)] + [InlineData("en-US", "fg/ml", DensityUnit.FemtogramPerMilliliter)] + [InlineData("en-US", "g/cm³", DensityUnit.GramPerCubicCentimeter)] + [InlineData("en-US", "g/ft³", DensityUnit.GramPerCubicFoot)] + [InlineData("en-US", "g/in³", DensityUnit.GramPerCubicInch)] + [InlineData("en-US", "g/m³", DensityUnit.GramPerCubicMeter)] + [InlineData("en-US", "g/mm³", DensityUnit.GramPerCubicMillimeter)] + [InlineData("en-US", "g/dl", DensityUnit.GramPerDeciliter)] + [InlineData("en-US", "g/l", DensityUnit.GramPerLiter)] + [InlineData("en-US", "g/ml", DensityUnit.GramPerMilliliter)] + [InlineData("en-US", "kg/cm³", DensityUnit.KilogramPerCubicCentimeter)] + [InlineData("en-US", "kg/m³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("en-US", "kg/mm³", DensityUnit.KilogramPerCubicMillimeter)] + [InlineData("en-US", "kg/l", DensityUnit.KilogramPerLiter)] + [InlineData("en-US", "kip/ft³", DensityUnit.KilopoundPerCubicFoot)] + [InlineData("en-US", "kip/in³", DensityUnit.KilopoundPerCubicInch)] + [InlineData("en-US", "kip/yd³", DensityUnit.KilopoundPerCubicYard)] + [InlineData("en-US", "µg/m³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("en-US", "µg/dl", DensityUnit.MicrogramPerDeciliter)] + [InlineData("en-US", "µg/l", DensityUnit.MicrogramPerLiter)] + [InlineData("en-US", "µg/ml", DensityUnit.MicrogramPerMilliliter)] + [InlineData("en-US", "mg/m³", DensityUnit.MilligramPerCubicMeter)] + [InlineData("en-US", "mg/dl", DensityUnit.MilligramPerDeciliter)] + [InlineData("en-US", "mg/l", DensityUnit.MilligramPerLiter)] + [InlineData("en-US", "mg/ml", DensityUnit.MilligramPerMilliliter)] + [InlineData("en-US", "ng/dl", DensityUnit.NanogramPerDeciliter)] + [InlineData("en-US", "ng/l", DensityUnit.NanogramPerLiter)] + [InlineData("en-US", "ng/ml", DensityUnit.NanogramPerMilliliter)] + [InlineData("en-US", "pg/dl", DensityUnit.PicogramPerDeciliter)] + [InlineData("en-US", "pg/l", DensityUnit.PicogramPerLiter)] + [InlineData("en-US", "pg/ml", DensityUnit.PicogramPerMilliliter)] + [InlineData("en-US", "lb/cm³", DensityUnit.PoundPerCubicCentimeter)] + [InlineData("en-US", "lb/ft³", DensityUnit.PoundPerCubicFoot)] + [InlineData("en-US", "lb/in³", DensityUnit.PoundPerCubicInch)] + [InlineData("en-US", "lb/m³", DensityUnit.PoundPerCubicMeter)] + [InlineData("en-US", "lb/mm³", DensityUnit.PoundPerCubicMillimeter)] + [InlineData("en-US", "lb/yd³", DensityUnit.PoundPerCubicYard)] + [InlineData("en-US", "ppg (imp.)", DensityUnit.PoundPerImperialGallon)] + [InlineData("en-US", "ppg (U.S.)", DensityUnit.PoundPerUSGallon)] + [InlineData("en-US", "slug/cm³", DensityUnit.SlugPerCubicCentimeter)] + [InlineData("en-US", "slug/ft³", DensityUnit.SlugPerCubicFoot)] + [InlineData("en-US", "slug/in³", DensityUnit.SlugPerCubicInch)] + [InlineData("en-US", "slug/m³", DensityUnit.SlugPerCubicMeter)] + [InlineData("en-US", "slug/mm³", DensityUnit.SlugPerCubicMillimeter)] + [InlineData("en-US", "t/cm³", DensityUnit.TonnePerCubicCentimeter)] + [InlineData("en-US", "t/ft³", DensityUnit.TonnePerCubicFoot)] + [InlineData("en-US", "t/in³", DensityUnit.TonnePerCubicInch)] + [InlineData("en-US", "t/m³", DensityUnit.TonnePerCubicMeter)] + [InlineData("en-US", "t/mm³", DensityUnit.TonnePerCubicMillimeter)] + [InlineData("ru-RU", "г/м³", DensityUnit.GramPerCubicMeter)] + [InlineData("ru-RU", "кг/м³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("ru-RU", "мкг/м³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("ru-RU", "мг/м³", DensityUnit.MilligramPerCubicMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, DensityUnit expectedUnit) + { + Assert.True(Density.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out DensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs index 322bb54505..716698ce5b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs @@ -1090,685 +1090,246 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Duration.ParseUnit("d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Day, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Day, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("days", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Day, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("сут", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Day, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("д", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Day, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("hr", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("hrs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("hour", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("hours", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("час", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("jyr", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.JulianYear, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("jyear", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.JulianYear, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("jyears", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.JulianYear, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("µs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("µsec", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("µsecs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("µsecond", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("µseconds", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("мксек", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("мкс", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("ms", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("msec", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("msecs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("msecond", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("mseconds", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("мсек", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("мс", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Minute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Minute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("minute", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Minute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("minutes", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Minute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Minute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("mo", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Month30, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("month", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Month30, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("months", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Month30, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("месяц", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Month30, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("ns", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("nsec", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("nsecs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("nsecond", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("nseconds", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("нсек", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("нс", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Second, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("sec", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Second, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("secs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Second, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("second", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Second, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("seconds", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Second, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("сек", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Second, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Second, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("sol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Sol, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("wk", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Week, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("week", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Week, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("weeks", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Week, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("нед", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Week, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("yr", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Year365, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("year", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Year365, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("years", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DurationUnit.Year365, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Duration.ParseUnit("год", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(DurationUnit.Year365, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("d", DurationUnit.Day)] + [InlineData("day", DurationUnit.Day)] + [InlineData("days", DurationUnit.Day)] + [InlineData("h", DurationUnit.Hour)] + [InlineData("hr", DurationUnit.Hour)] + [InlineData("hrs", DurationUnit.Hour)] + [InlineData("hour", DurationUnit.Hour)] + [InlineData("hours", DurationUnit.Hour)] + [InlineData("jyr", DurationUnit.JulianYear)] + [InlineData("jyear", DurationUnit.JulianYear)] + [InlineData("jyears", DurationUnit.JulianYear)] + [InlineData("µs", DurationUnit.Microsecond)] + [InlineData("µsec", DurationUnit.Microsecond)] + [InlineData("µsecs", DurationUnit.Microsecond)] + [InlineData("µsecond", DurationUnit.Microsecond)] + [InlineData("µseconds", DurationUnit.Microsecond)] + [InlineData("ms", DurationUnit.Millisecond)] + [InlineData("msec", DurationUnit.Millisecond)] + [InlineData("msecs", DurationUnit.Millisecond)] + [InlineData("msecond", DurationUnit.Millisecond)] + [InlineData("mseconds", DurationUnit.Millisecond)] + [InlineData("m", DurationUnit.Minute)] + [InlineData("min", DurationUnit.Minute)] + [InlineData("minute", DurationUnit.Minute)] + [InlineData("minutes", DurationUnit.Minute)] + [InlineData("mo", DurationUnit.Month30)] + [InlineData("month", DurationUnit.Month30)] + [InlineData("months", DurationUnit.Month30)] + [InlineData("ns", DurationUnit.Nanosecond)] + [InlineData("nsec", DurationUnit.Nanosecond)] + [InlineData("nsecs", DurationUnit.Nanosecond)] + [InlineData("nsecond", DurationUnit.Nanosecond)] + [InlineData("nseconds", DurationUnit.Nanosecond)] + [InlineData("s", DurationUnit.Second)] + [InlineData("sec", DurationUnit.Second)] + [InlineData("secs", DurationUnit.Second)] + [InlineData("second", DurationUnit.Second)] + [InlineData("seconds", DurationUnit.Second)] + [InlineData("sol", DurationUnit.Sol)] + [InlineData("wk", DurationUnit.Week)] + [InlineData("week", DurationUnit.Week)] + [InlineData("weeks", DurationUnit.Week)] + [InlineData("yr", DurationUnit.Year365)] + [InlineData("year", DurationUnit.Year365)] + [InlineData("years", DurationUnit.Year365)] + public void ParseUnit(string abbreviation, DurationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + DurationUnit parsedUnit = Duration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Duration.TryParseUnit("d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Day, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("day", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Day, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("days", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Day, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("сут", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Day, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("д", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Day, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("hr", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("hrs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("hour", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("hours", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("час", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Hour, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("jyr", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.JulianYear, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("jyear", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.JulianYear, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("jyears", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.JulianYear, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("µs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("µsec", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("µsecs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("µsecond", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("µseconds", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("мксек", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("мкс", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Microsecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("ms", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("msec", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("msecs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("msecond", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("mseconds", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("мсек", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("мс", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Millisecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Minute, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Minute, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("minute", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Minute, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("minutes", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Minute, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Minute, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("mo", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Month30, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("month", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Month30, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("months", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Month30, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("месяц", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Month30, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("ns", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("nsec", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("nsecs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("nsecond", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("nseconds", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("нсек", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("нс", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Nanosecond, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Second, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("sec", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Second, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("secs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Second, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("second", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Second, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("seconds", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Second, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("сек", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Second, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Second, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("sol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Sol, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("wk", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Week, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("week", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Week, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("weeks", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Week, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("нед", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Week, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("yr", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Year365, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("year", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Year365, parsedUnit); - } - - { - Assert.True(Duration.TryParseUnit("years", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DurationUnit.Year365, parsedUnit); - } + [Theory] + [InlineData("en-US", "d", DurationUnit.Day)] + [InlineData("en-US", "day", DurationUnit.Day)] + [InlineData("en-US", "days", DurationUnit.Day)] + [InlineData("en-US", "h", DurationUnit.Hour)] + [InlineData("en-US", "hr", DurationUnit.Hour)] + [InlineData("en-US", "hrs", DurationUnit.Hour)] + [InlineData("en-US", "hour", DurationUnit.Hour)] + [InlineData("en-US", "hours", DurationUnit.Hour)] + [InlineData("en-US", "jyr", DurationUnit.JulianYear)] + [InlineData("en-US", "jyear", DurationUnit.JulianYear)] + [InlineData("en-US", "jyears", DurationUnit.JulianYear)] + [InlineData("en-US", "µs", DurationUnit.Microsecond)] + [InlineData("en-US", "µsec", DurationUnit.Microsecond)] + [InlineData("en-US", "µsecs", DurationUnit.Microsecond)] + [InlineData("en-US", "µsecond", DurationUnit.Microsecond)] + [InlineData("en-US", "µseconds", DurationUnit.Microsecond)] + [InlineData("en-US", "ms", DurationUnit.Millisecond)] + [InlineData("en-US", "msec", DurationUnit.Millisecond)] + [InlineData("en-US", "msecs", DurationUnit.Millisecond)] + [InlineData("en-US", "msecond", DurationUnit.Millisecond)] + [InlineData("en-US", "mseconds", DurationUnit.Millisecond)] + [InlineData("en-US", "m", DurationUnit.Minute)] + [InlineData("en-US", "min", DurationUnit.Minute)] + [InlineData("en-US", "minute", DurationUnit.Minute)] + [InlineData("en-US", "minutes", DurationUnit.Minute)] + [InlineData("en-US", "mo", DurationUnit.Month30)] + [InlineData("en-US", "month", DurationUnit.Month30)] + [InlineData("en-US", "months", DurationUnit.Month30)] + [InlineData("en-US", "ns", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsec", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsecs", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsecond", DurationUnit.Nanosecond)] + [InlineData("en-US", "nseconds", DurationUnit.Nanosecond)] + [InlineData("en-US", "s", DurationUnit.Second)] + [InlineData("en-US", "sec", DurationUnit.Second)] + [InlineData("en-US", "secs", DurationUnit.Second)] + [InlineData("en-US", "second", DurationUnit.Second)] + [InlineData("en-US", "seconds", DurationUnit.Second)] + [InlineData("en-US", "sol", DurationUnit.Sol)] + [InlineData("en-US", "wk", DurationUnit.Week)] + [InlineData("en-US", "week", DurationUnit.Week)] + [InlineData("en-US", "weeks", DurationUnit.Week)] + [InlineData("en-US", "yr", DurationUnit.Year365)] + [InlineData("en-US", "year", DurationUnit.Year365)] + [InlineData("en-US", "years", DurationUnit.Year365)] + [InlineData("ru-RU", "сут", DurationUnit.Day)] + [InlineData("ru-RU", "д", DurationUnit.Day)] + [InlineData("ru-RU", "ч", DurationUnit.Hour)] + [InlineData("ru-RU", "час", DurationUnit.Hour)] + [InlineData("ru-RU", "мксек", DurationUnit.Microsecond)] + [InlineData("ru-RU", "мкс", DurationUnit.Microsecond)] + [InlineData("ru-RU", "мсек", DurationUnit.Millisecond)] + [InlineData("ru-RU", "мс", DurationUnit.Millisecond)] + [InlineData("ru-RU", "мин", DurationUnit.Minute)] + [InlineData("ru-RU", "месяц", DurationUnit.Month30)] + [InlineData("ru-RU", "нсек", DurationUnit.Nanosecond)] + [InlineData("ru-RU", "нс", DurationUnit.Nanosecond)] + [InlineData("ru-RU", "сек", DurationUnit.Second)] + [InlineData("ru-RU", "с", DurationUnit.Second)] + [InlineData("ru-RU", "нед", DurationUnit.Week)] + [InlineData("ru-RU", "год", DurationUnit.Year365)] + public void ParseUnitWithCulture(string culture, string abbreviation, DurationUnit expectedUnit) + { + DurationUnit parsedUnit = Duration.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Duration.TryParseUnit("год", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(DurationUnit.Year365, parsedUnit); - } + [Theory] + [InlineData("d", DurationUnit.Day)] + [InlineData("day", DurationUnit.Day)] + [InlineData("days", DurationUnit.Day)] + [InlineData("h", DurationUnit.Hour)] + [InlineData("hr", DurationUnit.Hour)] + [InlineData("hrs", DurationUnit.Hour)] + [InlineData("hour", DurationUnit.Hour)] + [InlineData("hours", DurationUnit.Hour)] + [InlineData("jyr", DurationUnit.JulianYear)] + [InlineData("jyear", DurationUnit.JulianYear)] + [InlineData("jyears", DurationUnit.JulianYear)] + [InlineData("µs", DurationUnit.Microsecond)] + [InlineData("µsec", DurationUnit.Microsecond)] + [InlineData("µsecs", DurationUnit.Microsecond)] + [InlineData("µsecond", DurationUnit.Microsecond)] + [InlineData("µseconds", DurationUnit.Microsecond)] + [InlineData("ms", DurationUnit.Millisecond)] + [InlineData("msec", DurationUnit.Millisecond)] + [InlineData("msecs", DurationUnit.Millisecond)] + [InlineData("msecond", DurationUnit.Millisecond)] + [InlineData("mseconds", DurationUnit.Millisecond)] + [InlineData("m", DurationUnit.Minute)] + [InlineData("min", DurationUnit.Minute)] + [InlineData("minute", DurationUnit.Minute)] + [InlineData("minutes", DurationUnit.Minute)] + [InlineData("mo", DurationUnit.Month30)] + [InlineData("month", DurationUnit.Month30)] + [InlineData("months", DurationUnit.Month30)] + [InlineData("ns", DurationUnit.Nanosecond)] + [InlineData("nsec", DurationUnit.Nanosecond)] + [InlineData("nsecs", DurationUnit.Nanosecond)] + [InlineData("nsecond", DurationUnit.Nanosecond)] + [InlineData("nseconds", DurationUnit.Nanosecond)] + [InlineData("s", DurationUnit.Second)] + [InlineData("sec", DurationUnit.Second)] + [InlineData("secs", DurationUnit.Second)] + [InlineData("second", DurationUnit.Second)] + [InlineData("seconds", DurationUnit.Second)] + [InlineData("sol", DurationUnit.Sol)] + [InlineData("wk", DurationUnit.Week)] + [InlineData("week", DurationUnit.Week)] + [InlineData("weeks", DurationUnit.Week)] + [InlineData("yr", DurationUnit.Year365)] + [InlineData("year", DurationUnit.Year365)] + [InlineData("years", DurationUnit.Year365)] + public void TryParseUnit(string abbreviation, DurationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Duration.TryParseUnit(abbreviation, out DurationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "d", DurationUnit.Day)] + [InlineData("en-US", "day", DurationUnit.Day)] + [InlineData("en-US", "days", DurationUnit.Day)] + [InlineData("en-US", "h", DurationUnit.Hour)] + [InlineData("en-US", "hr", DurationUnit.Hour)] + [InlineData("en-US", "hrs", DurationUnit.Hour)] + [InlineData("en-US", "hour", DurationUnit.Hour)] + [InlineData("en-US", "hours", DurationUnit.Hour)] + [InlineData("en-US", "jyr", DurationUnit.JulianYear)] + [InlineData("en-US", "jyear", DurationUnit.JulianYear)] + [InlineData("en-US", "jyears", DurationUnit.JulianYear)] + [InlineData("en-US", "µs", DurationUnit.Microsecond)] + [InlineData("en-US", "µsec", DurationUnit.Microsecond)] + [InlineData("en-US", "µsecs", DurationUnit.Microsecond)] + [InlineData("en-US", "µsecond", DurationUnit.Microsecond)] + [InlineData("en-US", "µseconds", DurationUnit.Microsecond)] + [InlineData("en-US", "ms", DurationUnit.Millisecond)] + [InlineData("en-US", "msec", DurationUnit.Millisecond)] + [InlineData("en-US", "msecs", DurationUnit.Millisecond)] + [InlineData("en-US", "msecond", DurationUnit.Millisecond)] + [InlineData("en-US", "mseconds", DurationUnit.Millisecond)] + [InlineData("en-US", "m", DurationUnit.Minute)] + [InlineData("en-US", "min", DurationUnit.Minute)] + [InlineData("en-US", "minute", DurationUnit.Minute)] + [InlineData("en-US", "minutes", DurationUnit.Minute)] + [InlineData("en-US", "mo", DurationUnit.Month30)] + [InlineData("en-US", "month", DurationUnit.Month30)] + [InlineData("en-US", "months", DurationUnit.Month30)] + [InlineData("en-US", "ns", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsec", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsecs", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsecond", DurationUnit.Nanosecond)] + [InlineData("en-US", "nseconds", DurationUnit.Nanosecond)] + [InlineData("en-US", "s", DurationUnit.Second)] + [InlineData("en-US", "sec", DurationUnit.Second)] + [InlineData("en-US", "secs", DurationUnit.Second)] + [InlineData("en-US", "second", DurationUnit.Second)] + [InlineData("en-US", "seconds", DurationUnit.Second)] + [InlineData("en-US", "sol", DurationUnit.Sol)] + [InlineData("en-US", "wk", DurationUnit.Week)] + [InlineData("en-US", "week", DurationUnit.Week)] + [InlineData("en-US", "weeks", DurationUnit.Week)] + [InlineData("en-US", "yr", DurationUnit.Year365)] + [InlineData("en-US", "year", DurationUnit.Year365)] + [InlineData("en-US", "years", DurationUnit.Year365)] + [InlineData("ru-RU", "сут", DurationUnit.Day)] + [InlineData("ru-RU", "д", DurationUnit.Day)] + [InlineData("ru-RU", "ч", DurationUnit.Hour)] + [InlineData("ru-RU", "час", DurationUnit.Hour)] + [InlineData("ru-RU", "мксек", DurationUnit.Microsecond)] + [InlineData("ru-RU", "мкс", DurationUnit.Microsecond)] + [InlineData("ru-RU", "мсек", DurationUnit.Millisecond)] + [InlineData("ru-RU", "мс", DurationUnit.Millisecond)] + [InlineData("ru-RU", "мин", DurationUnit.Minute)] + [InlineData("ru-RU", "месяц", DurationUnit.Month30)] + [InlineData("ru-RU", "нсек", DurationUnit.Nanosecond)] + [InlineData("ru-RU", "нс", DurationUnit.Nanosecond)] + [InlineData("ru-RU", "сек", DurationUnit.Second)] + [InlineData("ru-RU", "с", DurationUnit.Second)] + [InlineData("ru-RU", "нед", DurationUnit.Week)] + [InlineData("ru-RU", "год", DurationUnit.Year365)] + public void TryParseUnitWithCulture(string culture, string abbreviation, DurationUnit expectedUnit) + { + Assert.True(Duration.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out DurationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs index 48906046a1..25dc2dd620 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs @@ -446,157 +446,86 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = DynamicViscosity.ParseUnit("cP", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.Centipoise, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("µPa·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.MicropascalSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("µPaS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.MicropascalSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("mPa·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.MillipascalSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("mPaS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.MillipascalSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("Ns/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.NewtonSecondPerMeterSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("Pa·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.PascalSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("PaS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.PascalSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("P", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.Poise, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("lbf·s/ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.PoundForceSecondPerSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("lbf·s/in²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.PoundForceSecondPerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("lb/(ft·s)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.PoundPerFootSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = DynamicViscosity.ParseUnit("reyn", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(DynamicViscosityUnit.Reyn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cP", DynamicViscosityUnit.Centipoise)] + [InlineData("µPa·s", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("µPaS", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("mPa·s", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("mPaS", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("Ns/m²", DynamicViscosityUnit.NewtonSecondPerMeterSquared)] + [InlineData("Pa·s", DynamicViscosityUnit.PascalSecond)] + [InlineData("PaS", DynamicViscosityUnit.PascalSecond)] + [InlineData("P", DynamicViscosityUnit.Poise)] + [InlineData("lbf·s/ft²", DynamicViscosityUnit.PoundForceSecondPerSquareFoot)] + [InlineData("lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] + [InlineData("lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] + [InlineData("reyn", DynamicViscosityUnit.Reyn)] + public void ParseUnit(string abbreviation, DynamicViscosityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + DynamicViscosityUnit parsedUnit = DynamicViscosity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(DynamicViscosity.TryParseUnit("cP", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.Centipoise, parsedUnit); - } - - { - Assert.True(DynamicViscosity.TryParseUnit("µPa·s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.MicropascalSecond, parsedUnit); - } - - { - Assert.True(DynamicViscosity.TryParseUnit("µPaS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.MicropascalSecond, parsedUnit); - } - - { - Assert.True(DynamicViscosity.TryParseUnit("mPa·s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.MillipascalSecond, parsedUnit); - } - - { - Assert.True(DynamicViscosity.TryParseUnit("mPaS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.MillipascalSecond, parsedUnit); - } - - { - Assert.True(DynamicViscosity.TryParseUnit("Ns/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.NewtonSecondPerMeterSquared, parsedUnit); - } - - { - Assert.True(DynamicViscosity.TryParseUnit("Pa·s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.PascalSecond, parsedUnit); - } - - { - Assert.True(DynamicViscosity.TryParseUnit("PaS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.PascalSecond, parsedUnit); - } - - { - Assert.True(DynamicViscosity.TryParseUnit("P", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.Poise, parsedUnit); - } - - { - Assert.True(DynamicViscosity.TryParseUnit("lbf·s/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.PoundForceSecondPerSquareFoot, parsedUnit); - } - - { - Assert.True(DynamicViscosity.TryParseUnit("lbf·s/in²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.PoundForceSecondPerSquareInch, parsedUnit); - } - - { - Assert.True(DynamicViscosity.TryParseUnit("lb/(ft·s)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.PoundPerFootSecond, parsedUnit); - } + [Theory] + [InlineData("en-US", "cP", DynamicViscosityUnit.Centipoise)] + [InlineData("en-US", "µPa·s", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("en-US", "µPaS", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("en-US", "mPa·s", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("en-US", "mPaS", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("en-US", "Ns/m²", DynamicViscosityUnit.NewtonSecondPerMeterSquared)] + [InlineData("en-US", "Pa·s", DynamicViscosityUnit.PascalSecond)] + [InlineData("en-US", "PaS", DynamicViscosityUnit.PascalSecond)] + [InlineData("en-US", "P", DynamicViscosityUnit.Poise)] + [InlineData("en-US", "lbf·s/ft²", DynamicViscosityUnit.PoundForceSecondPerSquareFoot)] + [InlineData("en-US", "lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] + [InlineData("en-US", "lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] + [InlineData("en-US", "reyn", DynamicViscosityUnit.Reyn)] + public void ParseUnitWithCulture(string culture, string abbreviation, DynamicViscosityUnit expectedUnit) + { + DynamicViscosityUnit parsedUnit = DynamicViscosity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(DynamicViscosity.TryParseUnit("reyn", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(DynamicViscosityUnit.Reyn, parsedUnit); - } + [Theory] + [InlineData("cP", DynamicViscosityUnit.Centipoise)] + [InlineData("µPa·s", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("µPaS", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("mPa·s", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("mPaS", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("Ns/m²", DynamicViscosityUnit.NewtonSecondPerMeterSquared)] + [InlineData("Pa·s", DynamicViscosityUnit.PascalSecond)] + [InlineData("PaS", DynamicViscosityUnit.PascalSecond)] + [InlineData("P", DynamicViscosityUnit.Poise)] + [InlineData("lbf·s/ft²", DynamicViscosityUnit.PoundForceSecondPerSquareFoot)] + [InlineData("lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] + [InlineData("lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] + [InlineData("reyn", DynamicViscosityUnit.Reyn)] + public void TryParseUnit(string abbreviation, DynamicViscosityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(DynamicViscosity.TryParseUnit(abbreviation, out DynamicViscosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cP", DynamicViscosityUnit.Centipoise)] + [InlineData("en-US", "µPa·s", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("en-US", "µPaS", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("en-US", "mPa·s", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("en-US", "mPaS", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("en-US", "Ns/m²", DynamicViscosityUnit.NewtonSecondPerMeterSquared)] + [InlineData("en-US", "Pa·s", DynamicViscosityUnit.PascalSecond)] + [InlineData("en-US", "PaS", DynamicViscosityUnit.PascalSecond)] + [InlineData("en-US", "P", DynamicViscosityUnit.Poise)] + [InlineData("en-US", "lbf·s/ft²", DynamicViscosityUnit.PoundForceSecondPerSquareFoot)] + [InlineData("en-US", "lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] + [InlineData("en-US", "lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] + [InlineData("en-US", "reyn", DynamicViscosityUnit.Reyn)] + public void TryParseUnitWithCulture(string culture, string abbreviation, DynamicViscosityUnit expectedUnit) + { + Assert.True(DynamicViscosity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out DynamicViscosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs index f50a20dad0..f67851c508 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs @@ -269,58 +269,50 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("µS", ElectricAdmittanceUnit.Microsiemens)] + [InlineData("mS", ElectricAdmittanceUnit.Millisiemens)] + [InlineData("nS", ElectricAdmittanceUnit.Nanosiemens)] + [InlineData("S", ElectricAdmittanceUnit.Siemens)] + public void ParseUnit(string abbreviation, ElectricAdmittanceUnit expectedUnit) { - try - { - var parsedUnit = ElectricAdmittance.ParseUnit("µS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricAdmittanceUnit.Microsiemens, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricAdmittance.ParseUnit("mS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricAdmittanceUnit.Millisiemens, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricAdmittance.ParseUnit("nS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricAdmittanceUnit.Nanosiemens, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricAdmittance.ParseUnit("S", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricAdmittanceUnit.Siemens, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricAdmittanceUnit parsedUnit = ElectricAdmittance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "µS", ElectricAdmittanceUnit.Microsiemens)] + [InlineData("en-US", "mS", ElectricAdmittanceUnit.Millisiemens)] + [InlineData("en-US", "nS", ElectricAdmittanceUnit.Nanosiemens)] + [InlineData("en-US", "S", ElectricAdmittanceUnit.Siemens)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricAdmittanceUnit expectedUnit) { - { - Assert.True(ElectricAdmittance.TryParseUnit("µS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricAdmittanceUnit.Microsiemens, parsedUnit); - } - - { - Assert.True(ElectricAdmittance.TryParseUnit("mS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricAdmittanceUnit.Millisiemens, parsedUnit); - } - - { - Assert.True(ElectricAdmittance.TryParseUnit("nS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricAdmittanceUnit.Nanosiemens, parsedUnit); - } + ElectricAdmittanceUnit parsedUnit = ElectricAdmittance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricAdmittance.TryParseUnit("S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricAdmittanceUnit.Siemens, parsedUnit); - } + [Theory] + [InlineData("µS", ElectricAdmittanceUnit.Microsiemens)] + [InlineData("mS", ElectricAdmittanceUnit.Millisiemens)] + [InlineData("nS", ElectricAdmittanceUnit.Nanosiemens)] + [InlineData("S", ElectricAdmittanceUnit.Siemens)] + public void TryParseUnit(string abbreviation, ElectricAdmittanceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricAdmittance.TryParseUnit(abbreviation, out ElectricAdmittanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "µS", ElectricAdmittanceUnit.Microsiemens)] + [InlineData("en-US", "mS", ElectricAdmittanceUnit.Millisiemens)] + [InlineData("en-US", "nS", ElectricAdmittanceUnit.Nanosiemens)] + [InlineData("en-US", "S", ElectricAdmittanceUnit.Siemens)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricAdmittanceUnit expectedUnit) + { + Assert.True(ElectricAdmittance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricAdmittanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs index 6a81571346..f8fcf4d545 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] + public void ParseUnit(string abbreviation, ElectricChargeDensityUnit expectedUnit) { - try - { - var parsedUnit = ElectricChargeDensity.ParseUnit("C/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeDensityUnit.CoulombPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricChargeDensityUnit parsedUnit = ElectricChargeDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricChargeDensityUnit expectedUnit) + { + ElectricChargeDensityUnit parsedUnit = ElectricChargeDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] + public void TryParseUnit(string abbreviation, ElectricChargeDensityUnit expectedUnit) { - { - Assert.True(ElectricChargeDensity.TryParseUnit("C/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricChargeDensityUnit.CoulombPerCubicMeter, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricChargeDensity.TryParseUnit(abbreviation, out ElectricChargeDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricChargeDensityUnit expectedUnit) + { + Assert.True(ElectricChargeDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricChargeDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs index 5a10a078e5..ead7fe2bb6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs @@ -446,149 +446,94 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = ElectricCharge.ParseUnit("A-h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.AmpereHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("Ah", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.AmpereHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.Coulomb, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("kA-h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.KiloampereHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("kAh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.KiloampereHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("kC", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.Kilocoulomb, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("MA-h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.MegaampereHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("MAh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.MegaampereHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("MC", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.Megacoulomb, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("µC", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.Microcoulomb, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("mA-h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.MilliampereHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("mAh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.MilliampereHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("mC", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.Millicoulomb, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("nC", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.Nanocoulomb, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCharge.ParseUnit("pC", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricChargeUnit.Picocoulomb, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("A-h", ElectricChargeUnit.AmpereHour)] + [InlineData("Ah", ElectricChargeUnit.AmpereHour)] + [InlineData("C", ElectricChargeUnit.Coulomb)] + [InlineData("kA-h", ElectricChargeUnit.KiloampereHour)] + [InlineData("kAh", ElectricChargeUnit.KiloampereHour)] + [InlineData("kC", ElectricChargeUnit.Kilocoulomb)] + [InlineData("MA-h", ElectricChargeUnit.MegaampereHour)] + [InlineData("MAh", ElectricChargeUnit.MegaampereHour)] + [InlineData("MC", ElectricChargeUnit.Megacoulomb)] + [InlineData("µC", ElectricChargeUnit.Microcoulomb)] + [InlineData("mA-h", ElectricChargeUnit.MilliampereHour)] + [InlineData("mAh", ElectricChargeUnit.MilliampereHour)] + [InlineData("mC", ElectricChargeUnit.Millicoulomb)] + [InlineData("nC", ElectricChargeUnit.Nanocoulomb)] + [InlineData("pC", ElectricChargeUnit.Picocoulomb)] + public void ParseUnit(string abbreviation, ElectricChargeUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricChargeUnit parsedUnit = ElectricCharge.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(ElectricCharge.TryParseUnit("A-h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricChargeUnit.AmpereHour, parsedUnit); - } - - { - Assert.True(ElectricCharge.TryParseUnit("Ah", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricChargeUnit.AmpereHour, parsedUnit); - } - - { - Assert.True(ElectricCharge.TryParseUnit("C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricChargeUnit.Coulomb, parsedUnit); - } - - { - Assert.True(ElectricCharge.TryParseUnit("kA-h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricChargeUnit.KiloampereHour, parsedUnit); - } - - { - Assert.True(ElectricCharge.TryParseUnit("kAh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricChargeUnit.KiloampereHour, parsedUnit); - } - - { - Assert.True(ElectricCharge.TryParseUnit("kC", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricChargeUnit.Kilocoulomb, parsedUnit); - } - - { - Assert.True(ElectricCharge.TryParseUnit("µC", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricChargeUnit.Microcoulomb, parsedUnit); - } - - { - Assert.True(ElectricCharge.TryParseUnit("nC", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricChargeUnit.Nanocoulomb, parsedUnit); - } + [Theory] + [InlineData("en-US", "A-h", ElectricChargeUnit.AmpereHour)] + [InlineData("en-US", "Ah", ElectricChargeUnit.AmpereHour)] + [InlineData("en-US", "C", ElectricChargeUnit.Coulomb)] + [InlineData("en-US", "kA-h", ElectricChargeUnit.KiloampereHour)] + [InlineData("en-US", "kAh", ElectricChargeUnit.KiloampereHour)] + [InlineData("en-US", "kC", ElectricChargeUnit.Kilocoulomb)] + [InlineData("en-US", "MA-h", ElectricChargeUnit.MegaampereHour)] + [InlineData("en-US", "MAh", ElectricChargeUnit.MegaampereHour)] + [InlineData("en-US", "MC", ElectricChargeUnit.Megacoulomb)] + [InlineData("en-US", "µC", ElectricChargeUnit.Microcoulomb)] + [InlineData("en-US", "mA-h", ElectricChargeUnit.MilliampereHour)] + [InlineData("en-US", "mAh", ElectricChargeUnit.MilliampereHour)] + [InlineData("en-US", "mC", ElectricChargeUnit.Millicoulomb)] + [InlineData("en-US", "nC", ElectricChargeUnit.Nanocoulomb)] + [InlineData("en-US", "pC", ElectricChargeUnit.Picocoulomb)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricChargeUnit expectedUnit) + { + ElectricChargeUnit parsedUnit = ElectricCharge.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricCharge.TryParseUnit("pC", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricChargeUnit.Picocoulomb, parsedUnit); - } + [Theory] + [InlineData("A-h", ElectricChargeUnit.AmpereHour)] + [InlineData("Ah", ElectricChargeUnit.AmpereHour)] + [InlineData("C", ElectricChargeUnit.Coulomb)] + [InlineData("kA-h", ElectricChargeUnit.KiloampereHour)] + [InlineData("kAh", ElectricChargeUnit.KiloampereHour)] + [InlineData("kC", ElectricChargeUnit.Kilocoulomb)] + [InlineData("MA-h", ElectricChargeUnit.MegaampereHour)] + [InlineData("MAh", ElectricChargeUnit.MegaampereHour)] + [InlineData("MC", ElectricChargeUnit.Megacoulomb)] + [InlineData("µC", ElectricChargeUnit.Microcoulomb)] + [InlineData("mA-h", ElectricChargeUnit.MilliampereHour)] + [InlineData("mAh", ElectricChargeUnit.MilliampereHour)] + [InlineData("mC", ElectricChargeUnit.Millicoulomb)] + [InlineData("nC", ElectricChargeUnit.Nanocoulomb)] + [InlineData("pC", ElectricChargeUnit.Picocoulomb)] + public void TryParseUnit(string abbreviation, ElectricChargeUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricCharge.TryParseUnit(abbreviation, out ElectricChargeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "A-h", ElectricChargeUnit.AmpereHour)] + [InlineData("en-US", "Ah", ElectricChargeUnit.AmpereHour)] + [InlineData("en-US", "C", ElectricChargeUnit.Coulomb)] + [InlineData("en-US", "kA-h", ElectricChargeUnit.KiloampereHour)] + [InlineData("en-US", "kAh", ElectricChargeUnit.KiloampereHour)] + [InlineData("en-US", "kC", ElectricChargeUnit.Kilocoulomb)] + [InlineData("en-US", "MA-h", ElectricChargeUnit.MegaampereHour)] + [InlineData("en-US", "MAh", ElectricChargeUnit.MegaampereHour)] + [InlineData("en-US", "MC", ElectricChargeUnit.Megacoulomb)] + [InlineData("en-US", "µC", ElectricChargeUnit.Microcoulomb)] + [InlineData("en-US", "mA-h", ElectricChargeUnit.MilliampereHour)] + [InlineData("en-US", "mAh", ElectricChargeUnit.MilliampereHour)] + [InlineData("en-US", "mC", ElectricChargeUnit.Millicoulomb)] + [InlineData("en-US", "nC", ElectricChargeUnit.Nanocoulomb)] + [InlineData("en-US", "pC", ElectricChargeUnit.Picocoulomb)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricChargeUnit expectedUnit) + { + Assert.True(ElectricCharge.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricChargeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs index 4b2ff1f6b1..ab6a456dc7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs @@ -292,69 +292,54 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("kS", ElectricConductanceUnit.Kilosiemens)] + [InlineData("µS", ElectricConductanceUnit.Microsiemens)] + [InlineData("mS", ElectricConductanceUnit.Millisiemens)] + [InlineData("nS", ElectricConductanceUnit.Nanosiemens)] + [InlineData("S", ElectricConductanceUnit.Siemens)] + public void ParseUnit(string abbreviation, ElectricConductanceUnit expectedUnit) { - try - { - var parsedUnit = ElectricConductance.ParseUnit("kS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricConductanceUnit.Kilosiemens, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricConductance.ParseUnit("µS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricConductanceUnit.Microsiemens, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricConductance.ParseUnit("mS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricConductanceUnit.Millisiemens, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricConductance.ParseUnit("nS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricConductanceUnit.Nanosiemens, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricConductance.ParseUnit("S", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricConductanceUnit.Siemens, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricConductanceUnit parsedUnit = ElectricConductance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "kS", ElectricConductanceUnit.Kilosiemens)] + [InlineData("en-US", "µS", ElectricConductanceUnit.Microsiemens)] + [InlineData("en-US", "mS", ElectricConductanceUnit.Millisiemens)] + [InlineData("en-US", "nS", ElectricConductanceUnit.Nanosiemens)] + [InlineData("en-US", "S", ElectricConductanceUnit.Siemens)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricConductanceUnit expectedUnit) { - { - Assert.True(ElectricConductance.TryParseUnit("kS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductanceUnit.Kilosiemens, parsedUnit); - } - - { - Assert.True(ElectricConductance.TryParseUnit("µS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductanceUnit.Microsiemens, parsedUnit); - } - - { - Assert.True(ElectricConductance.TryParseUnit("mS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductanceUnit.Millisiemens, parsedUnit); - } - - { - Assert.True(ElectricConductance.TryParseUnit("nS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductanceUnit.Nanosiemens, parsedUnit); - } + ElectricConductanceUnit parsedUnit = ElectricConductance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricConductance.TryParseUnit("S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductanceUnit.Siemens, parsedUnit); - } + [Theory] + [InlineData("kS", ElectricConductanceUnit.Kilosiemens)] + [InlineData("µS", ElectricConductanceUnit.Microsiemens)] + [InlineData("mS", ElectricConductanceUnit.Millisiemens)] + [InlineData("nS", ElectricConductanceUnit.Nanosiemens)] + [InlineData("S", ElectricConductanceUnit.Siemens)] + public void TryParseUnit(string abbreviation, ElectricConductanceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricConductance.TryParseUnit(abbreviation, out ElectricConductanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kS", ElectricConductanceUnit.Kilosiemens)] + [InlineData("en-US", "µS", ElectricConductanceUnit.Microsiemens)] + [InlineData("en-US", "mS", ElectricConductanceUnit.Millisiemens)] + [InlineData("en-US", "nS", ElectricConductanceUnit.Nanosiemens)] + [InlineData("en-US", "S", ElectricConductanceUnit.Siemens)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricConductanceUnit expectedUnit) + { + Assert.True(ElectricConductance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricConductanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs index 2a6583079b..fa0876324a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs @@ -315,80 +315,58 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("µS/cm", ElectricConductivityUnit.MicrosiemensPerCentimeter)] + [InlineData("mS/cm", ElectricConductivityUnit.MillisiemensPerCentimeter)] + [InlineData("S/cm", ElectricConductivityUnit.SiemensPerCentimeter)] + [InlineData("S/ft", ElectricConductivityUnit.SiemensPerFoot)] + [InlineData("S/in", ElectricConductivityUnit.SiemensPerInch)] + [InlineData("S/m", ElectricConductivityUnit.SiemensPerMeter)] + public void ParseUnit(string abbreviation, ElectricConductivityUnit expectedUnit) { - try - { - var parsedUnit = ElectricConductivity.ParseUnit("µS/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricConductivityUnit.MicrosiemensPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricConductivity.ParseUnit("mS/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricConductivityUnit.MillisiemensPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricConductivity.ParseUnit("S/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricConductivityUnit.SiemensPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricConductivity.ParseUnit("S/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricConductivityUnit.SiemensPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricConductivity.ParseUnit("S/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricConductivityUnit.SiemensPerInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricConductivity.ParseUnit("S/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricConductivityUnit.SiemensPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricConductivityUnit parsedUnit = ElectricConductivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "µS/cm", ElectricConductivityUnit.MicrosiemensPerCentimeter)] + [InlineData("en-US", "mS/cm", ElectricConductivityUnit.MillisiemensPerCentimeter)] + [InlineData("en-US", "S/cm", ElectricConductivityUnit.SiemensPerCentimeter)] + [InlineData("en-US", "S/ft", ElectricConductivityUnit.SiemensPerFoot)] + [InlineData("en-US", "S/in", ElectricConductivityUnit.SiemensPerInch)] + [InlineData("en-US", "S/m", ElectricConductivityUnit.SiemensPerMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricConductivityUnit expectedUnit) { - { - Assert.True(ElectricConductivity.TryParseUnit("µS/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductivityUnit.MicrosiemensPerCentimeter, parsedUnit); - } - - { - Assert.True(ElectricConductivity.TryParseUnit("mS/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductivityUnit.MillisiemensPerCentimeter, parsedUnit); - } - - { - Assert.True(ElectricConductivity.TryParseUnit("S/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductivityUnit.SiemensPerCentimeter, parsedUnit); - } - - { - Assert.True(ElectricConductivity.TryParseUnit("S/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductivityUnit.SiemensPerFoot, parsedUnit); - } - - { - Assert.True(ElectricConductivity.TryParseUnit("S/in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductivityUnit.SiemensPerInch, parsedUnit); - } + ElectricConductivityUnit parsedUnit = ElectricConductivity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricConductivity.TryParseUnit("S/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricConductivityUnit.SiemensPerMeter, parsedUnit); - } + [Theory] + [InlineData("µS/cm", ElectricConductivityUnit.MicrosiemensPerCentimeter)] + [InlineData("mS/cm", ElectricConductivityUnit.MillisiemensPerCentimeter)] + [InlineData("S/cm", ElectricConductivityUnit.SiemensPerCentimeter)] + [InlineData("S/ft", ElectricConductivityUnit.SiemensPerFoot)] + [InlineData("S/in", ElectricConductivityUnit.SiemensPerInch)] + [InlineData("S/m", ElectricConductivityUnit.SiemensPerMeter)] + public void TryParseUnit(string abbreviation, ElectricConductivityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricConductivity.TryParseUnit(abbreviation, out ElectricConductivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "µS/cm", ElectricConductivityUnit.MicrosiemensPerCentimeter)] + [InlineData("en-US", "mS/cm", ElectricConductivityUnit.MillisiemensPerCentimeter)] + [InlineData("en-US", "S/cm", ElectricConductivityUnit.SiemensPerCentimeter)] + [InlineData("en-US", "S/ft", ElectricConductivityUnit.SiemensPerFoot)] + [InlineData("en-US", "S/in", ElectricConductivityUnit.SiemensPerInch)] + [InlineData("en-US", "S/m", ElectricConductivityUnit.SiemensPerMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricConductivityUnit expectedUnit) + { + Assert.True(ElectricConductivity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricConductivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs index 7d2187e0f9..87579b81fd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs @@ -246,47 +246,46 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] + [InlineData("A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] + [InlineData("A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] + public void ParseUnit(string abbreviation, ElectricCurrentDensityUnit expectedUnit) { - try - { - var parsedUnit = ElectricCurrentDensity.ParseUnit("A/ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrentDensity.ParseUnit("A/in²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrentDensity.ParseUnit("A/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricCurrentDensityUnit parsedUnit = ElectricCurrentDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] + [InlineData("en-US", "A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] + [InlineData("en-US", "A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentDensityUnit expectedUnit) { - { - Assert.True(ElectricCurrentDensity.TryParseUnit("A/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareFoot, parsedUnit); - } - - { - Assert.True(ElectricCurrentDensity.TryParseUnit("A/in²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareInch, parsedUnit); - } + ElectricCurrentDensityUnit parsedUnit = ElectricCurrentDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricCurrentDensity.TryParseUnit("A/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentDensityUnit.AmperePerSquareMeter, parsedUnit); - } + [Theory] + [InlineData("A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] + [InlineData("A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] + [InlineData("A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] + public void TryParseUnit(string abbreviation, ElectricCurrentDensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricCurrentDensity.TryParseUnit(abbreviation, out ElectricCurrentDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] + [InlineData("en-US", "A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] + [InlineData("en-US", "A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentDensityUnit expectedUnit) + { + Assert.True(ElectricCurrentDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricCurrentDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs index 5a83c9ca72..836aecb346 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs @@ -338,91 +338,62 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("A/μs", ElectricCurrentGradientUnit.AmperePerMicrosecond)] + [InlineData("A/ms", ElectricCurrentGradientUnit.AmperePerMillisecond)] + [InlineData("A/min", ElectricCurrentGradientUnit.AmperePerMinute)] + [InlineData("A/ns", ElectricCurrentGradientUnit.AmperePerNanosecond)] + [InlineData("A/s", ElectricCurrentGradientUnit.AmperePerSecond)] + [InlineData("mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] + [InlineData("mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] + public void ParseUnit(string abbreviation, ElectricCurrentGradientUnit expectedUnit) { - try - { - var parsedUnit = ElectricCurrentGradient.ParseUnit("A/μs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMicrosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrentGradient.ParseUnit("A/ms", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMillisecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrentGradient.ParseUnit("A/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrentGradient.ParseUnit("A/ns", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerNanosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrentGradient.ParseUnit("A/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrentGradient.ParseUnit("mA/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentGradientUnit.MilliamperePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrentGradient.ParseUnit("mA/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentGradientUnit.MilliamperePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricCurrentGradientUnit parsedUnit = ElectricCurrentGradient.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "A/μs", ElectricCurrentGradientUnit.AmperePerMicrosecond)] + [InlineData("en-US", "A/ms", ElectricCurrentGradientUnit.AmperePerMillisecond)] + [InlineData("en-US", "A/min", ElectricCurrentGradientUnit.AmperePerMinute)] + [InlineData("en-US", "A/ns", ElectricCurrentGradientUnit.AmperePerNanosecond)] + [InlineData("en-US", "A/s", ElectricCurrentGradientUnit.AmperePerSecond)] + [InlineData("en-US", "mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] + [InlineData("en-US", "mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentGradientUnit expectedUnit) { - { - Assert.True(ElectricCurrentGradient.TryParseUnit("A/μs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMicrosecond, parsedUnit); - } - - { - Assert.True(ElectricCurrentGradient.TryParseUnit("A/ms", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMillisecond, parsedUnit); - } - - { - Assert.True(ElectricCurrentGradient.TryParseUnit("A/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerMinute, parsedUnit); - } - - { - Assert.True(ElectricCurrentGradient.TryParseUnit("A/ns", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerNanosecond, parsedUnit); - } - - { - Assert.True(ElectricCurrentGradient.TryParseUnit("A/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentGradientUnit.AmperePerSecond, parsedUnit); - } - - { - Assert.True(ElectricCurrentGradient.TryParseUnit("mA/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentGradientUnit.MilliamperePerMinute, parsedUnit); - } + ElectricCurrentGradientUnit parsedUnit = ElectricCurrentGradient.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricCurrentGradient.TryParseUnit("mA/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentGradientUnit.MilliamperePerSecond, parsedUnit); - } + [Theory] + [InlineData("A/μs", ElectricCurrentGradientUnit.AmperePerMicrosecond)] + [InlineData("A/ms", ElectricCurrentGradientUnit.AmperePerMillisecond)] + [InlineData("A/min", ElectricCurrentGradientUnit.AmperePerMinute)] + [InlineData("A/ns", ElectricCurrentGradientUnit.AmperePerNanosecond)] + [InlineData("A/s", ElectricCurrentGradientUnit.AmperePerSecond)] + [InlineData("mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] + [InlineData("mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] + public void TryParseUnit(string abbreviation, ElectricCurrentGradientUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricCurrentGradient.TryParseUnit(abbreviation, out ElectricCurrentGradientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "A/μs", ElectricCurrentGradientUnit.AmperePerMicrosecond)] + [InlineData("en-US", "A/ms", ElectricCurrentGradientUnit.AmperePerMillisecond)] + [InlineData("en-US", "A/min", ElectricCurrentGradientUnit.AmperePerMinute)] + [InlineData("en-US", "A/ns", ElectricCurrentGradientUnit.AmperePerNanosecond)] + [InlineData("en-US", "A/s", ElectricCurrentGradientUnit.AmperePerSecond)] + [InlineData("en-US", "mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] + [InlineData("en-US", "mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentGradientUnit expectedUnit) + { + Assert.True(ElectricCurrentGradient.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricCurrentGradientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs index 0c6eeb9a58..418bddb157 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs @@ -372,103 +372,70 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = ElectricCurrent.ParseUnit("A", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentUnit.Ampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrent.ParseUnit("cA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentUnit.Centiampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrent.ParseUnit("fA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentUnit.Femtoampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrent.ParseUnit("kA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentUnit.Kiloampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrent.ParseUnit("MA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentUnit.Megaampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrent.ParseUnit("µA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentUnit.Microampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrent.ParseUnit("mA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentUnit.Milliampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrent.ParseUnit("nA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentUnit.Nanoampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricCurrent.ParseUnit("pA", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricCurrentUnit.Picoampere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("A", ElectricCurrentUnit.Ampere)] + [InlineData("cA", ElectricCurrentUnit.Centiampere)] + [InlineData("fA", ElectricCurrentUnit.Femtoampere)] + [InlineData("kA", ElectricCurrentUnit.Kiloampere)] + [InlineData("MA", ElectricCurrentUnit.Megaampere)] + [InlineData("µA", ElectricCurrentUnit.Microampere)] + [InlineData("mA", ElectricCurrentUnit.Milliampere)] + [InlineData("nA", ElectricCurrentUnit.Nanoampere)] + [InlineData("pA", ElectricCurrentUnit.Picoampere)] + public void ParseUnit(string abbreviation, ElectricCurrentUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricCurrentUnit parsedUnit = ElectricCurrent.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "A", ElectricCurrentUnit.Ampere)] + [InlineData("en-US", "cA", ElectricCurrentUnit.Centiampere)] + [InlineData("en-US", "fA", ElectricCurrentUnit.Femtoampere)] + [InlineData("en-US", "kA", ElectricCurrentUnit.Kiloampere)] + [InlineData("en-US", "MA", ElectricCurrentUnit.Megaampere)] + [InlineData("en-US", "µA", ElectricCurrentUnit.Microampere)] + [InlineData("en-US", "mA", ElectricCurrentUnit.Milliampere)] + [InlineData("en-US", "nA", ElectricCurrentUnit.Nanoampere)] + [InlineData("en-US", "pA", ElectricCurrentUnit.Picoampere)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentUnit expectedUnit) { - { - Assert.True(ElectricCurrent.TryParseUnit("A", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentUnit.Ampere, parsedUnit); - } - - { - Assert.True(ElectricCurrent.TryParseUnit("cA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentUnit.Centiampere, parsedUnit); - } - - { - Assert.True(ElectricCurrent.TryParseUnit("fA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentUnit.Femtoampere, parsedUnit); - } - - { - Assert.True(ElectricCurrent.TryParseUnit("kA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentUnit.Kiloampere, parsedUnit); - } - - { - Assert.True(ElectricCurrent.TryParseUnit("µA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentUnit.Microampere, parsedUnit); - } - - { - Assert.True(ElectricCurrent.TryParseUnit("nA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentUnit.Nanoampere, parsedUnit); - } + ElectricCurrentUnit parsedUnit = ElectricCurrent.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricCurrent.TryParseUnit("pA", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricCurrentUnit.Picoampere, parsedUnit); - } + [Theory] + [InlineData("A", ElectricCurrentUnit.Ampere)] + [InlineData("cA", ElectricCurrentUnit.Centiampere)] + [InlineData("fA", ElectricCurrentUnit.Femtoampere)] + [InlineData("kA", ElectricCurrentUnit.Kiloampere)] + [InlineData("MA", ElectricCurrentUnit.Megaampere)] + [InlineData("µA", ElectricCurrentUnit.Microampere)] + [InlineData("mA", ElectricCurrentUnit.Milliampere)] + [InlineData("nA", ElectricCurrentUnit.Nanoampere)] + [InlineData("pA", ElectricCurrentUnit.Picoampere)] + public void TryParseUnit(string abbreviation, ElectricCurrentUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricCurrent.TryParseUnit(abbreviation, out ElectricCurrentUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "A", ElectricCurrentUnit.Ampere)] + [InlineData("en-US", "cA", ElectricCurrentUnit.Centiampere)] + [InlineData("en-US", "fA", ElectricCurrentUnit.Femtoampere)] + [InlineData("en-US", "kA", ElectricCurrentUnit.Kiloampere)] + [InlineData("en-US", "MA", ElectricCurrentUnit.Megaampere)] + [InlineData("en-US", "µA", ElectricCurrentUnit.Microampere)] + [InlineData("en-US", "mA", ElectricCurrentUnit.Milliampere)] + [InlineData("en-US", "nA", ElectricCurrentUnit.Nanoampere)] + [InlineData("en-US", "pA", ElectricCurrentUnit.Picoampere)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentUnit expectedUnit) + { + Assert.True(ElectricCurrent.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricCurrentUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs index 690ea5b462..2ac12fd273 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("V/m", ElectricFieldUnit.VoltPerMeter)] + public void ParseUnit(string abbreviation, ElectricFieldUnit expectedUnit) { - try - { - var parsedUnit = ElectricField.ParseUnit("V/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricFieldUnit.VoltPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricFieldUnit parsedUnit = ElectricField.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "V/m", ElectricFieldUnit.VoltPerMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricFieldUnit expectedUnit) + { + ElectricFieldUnit parsedUnit = ElectricField.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("V/m", ElectricFieldUnit.VoltPerMeter)] + public void TryParseUnit(string abbreviation, ElectricFieldUnit expectedUnit) { - { - Assert.True(ElectricField.TryParseUnit("V/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricFieldUnit.VoltPerMeter, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricField.TryParseUnit(abbreviation, out ElectricFieldUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "V/m", ElectricFieldUnit.VoltPerMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricFieldUnit expectedUnit) + { + Assert.True(ElectricField.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricFieldUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs index 2d5b3725ff..a3b77ef90d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs @@ -292,69 +292,54 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("H", ElectricInductanceUnit.Henry)] + [InlineData("µH", ElectricInductanceUnit.Microhenry)] + [InlineData("mH", ElectricInductanceUnit.Millihenry)] + [InlineData("nH", ElectricInductanceUnit.Nanohenry)] + [InlineData("pH", ElectricInductanceUnit.Picohenry)] + public void ParseUnit(string abbreviation, ElectricInductanceUnit expectedUnit) { - try - { - var parsedUnit = ElectricInductance.ParseUnit("H", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricInductanceUnit.Henry, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricInductance.ParseUnit("µH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricInductanceUnit.Microhenry, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricInductance.ParseUnit("mH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricInductanceUnit.Millihenry, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricInductance.ParseUnit("nH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricInductanceUnit.Nanohenry, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricInductance.ParseUnit("pH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricInductanceUnit.Picohenry, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricInductanceUnit parsedUnit = ElectricInductance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "H", ElectricInductanceUnit.Henry)] + [InlineData("en-US", "µH", ElectricInductanceUnit.Microhenry)] + [InlineData("en-US", "mH", ElectricInductanceUnit.Millihenry)] + [InlineData("en-US", "nH", ElectricInductanceUnit.Nanohenry)] + [InlineData("en-US", "pH", ElectricInductanceUnit.Picohenry)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricInductanceUnit expectedUnit) { - { - Assert.True(ElectricInductance.TryParseUnit("H", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricInductanceUnit.Henry, parsedUnit); - } - - { - Assert.True(ElectricInductance.TryParseUnit("µH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricInductanceUnit.Microhenry, parsedUnit); - } - - { - Assert.True(ElectricInductance.TryParseUnit("mH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricInductanceUnit.Millihenry, parsedUnit); - } - - { - Assert.True(ElectricInductance.TryParseUnit("nH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricInductanceUnit.Nanohenry, parsedUnit); - } + ElectricInductanceUnit parsedUnit = ElectricInductance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricInductance.TryParseUnit("pH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricInductanceUnit.Picohenry, parsedUnit); - } + [Theory] + [InlineData("H", ElectricInductanceUnit.Henry)] + [InlineData("µH", ElectricInductanceUnit.Microhenry)] + [InlineData("mH", ElectricInductanceUnit.Millihenry)] + [InlineData("nH", ElectricInductanceUnit.Nanohenry)] + [InlineData("pH", ElectricInductanceUnit.Picohenry)] + public void TryParseUnit(string abbreviation, ElectricInductanceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricInductance.TryParseUnit(abbreviation, out ElectricInductanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "H", ElectricInductanceUnit.Henry)] + [InlineData("en-US", "µH", ElectricInductanceUnit.Microhenry)] + [InlineData("en-US", "mH", ElectricInductanceUnit.Millihenry)] + [InlineData("en-US", "nH", ElectricInductanceUnit.Nanohenry)] + [InlineData("en-US", "pH", ElectricInductanceUnit.Picohenry)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricInductanceUnit expectedUnit) + { + Assert.True(ElectricInductance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricInductanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs index 19742ba3d8..e9e2f855a0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs @@ -280,59 +280,54 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("kVac", ElectricPotentialAcUnit.KilovoltAc)] + [InlineData("MVac", ElectricPotentialAcUnit.MegavoltAc)] + [InlineData("µVac", ElectricPotentialAcUnit.MicrovoltAc)] + [InlineData("mVac", ElectricPotentialAcUnit.MillivoltAc)] + [InlineData("Vac", ElectricPotentialAcUnit.VoltAc)] + public void ParseUnit(string abbreviation, ElectricPotentialAcUnit expectedUnit) { - try - { - var parsedUnit = ElectricPotentialAc.ParseUnit("kVac", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialAcUnit.KilovoltAc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialAc.ParseUnit("MVac", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialAcUnit.MegavoltAc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialAc.ParseUnit("µVac", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialAcUnit.MicrovoltAc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialAc.ParseUnit("mVac", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialAcUnit.MillivoltAc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialAc.ParseUnit("Vac", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialAcUnit.VoltAc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricPotentialAcUnit parsedUnit = ElectricPotentialAc.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "kVac", ElectricPotentialAcUnit.KilovoltAc)] + [InlineData("en-US", "MVac", ElectricPotentialAcUnit.MegavoltAc)] + [InlineData("en-US", "µVac", ElectricPotentialAcUnit.MicrovoltAc)] + [InlineData("en-US", "mVac", ElectricPotentialAcUnit.MillivoltAc)] + [InlineData("en-US", "Vac", ElectricPotentialAcUnit.VoltAc)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) { - { - Assert.True(ElectricPotentialAc.TryParseUnit("kVac", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialAcUnit.KilovoltAc, parsedUnit); - } - - { - Assert.True(ElectricPotentialAc.TryParseUnit("µVac", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialAcUnit.MicrovoltAc, parsedUnit); - } + ElectricPotentialAcUnit parsedUnit = ElectricPotentialAc.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricPotentialAc.TryParseUnit("Vac", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialAcUnit.VoltAc, parsedUnit); - } + [Theory] + [InlineData("kVac", ElectricPotentialAcUnit.KilovoltAc)] + [InlineData("MVac", ElectricPotentialAcUnit.MegavoltAc)] + [InlineData("µVac", ElectricPotentialAcUnit.MicrovoltAc)] + [InlineData("mVac", ElectricPotentialAcUnit.MillivoltAc)] + [InlineData("Vac", ElectricPotentialAcUnit.VoltAc)] + public void TryParseUnit(string abbreviation, ElectricPotentialAcUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricPotentialAc.TryParseUnit(abbreviation, out ElectricPotentialAcUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kVac", ElectricPotentialAcUnit.KilovoltAc)] + [InlineData("en-US", "MVac", ElectricPotentialAcUnit.MegavoltAc)] + [InlineData("en-US", "µVac", ElectricPotentialAcUnit.MicrovoltAc)] + [InlineData("en-US", "mVac", ElectricPotentialAcUnit.MillivoltAc)] + [InlineData("en-US", "Vac", ElectricPotentialAcUnit.VoltAc)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) + { + Assert.True(ElectricPotentialAc.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricPotentialAcUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs index 2fcead6561..7a6e7c27b5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs @@ -589,194 +589,114 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("kV/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("kV/μs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("kV/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("kV/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("MV/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("MV/μs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("MV/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("MV/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MegavoltPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("µV/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("µV/μs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("µV/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("µV/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("mV/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("mV/μs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("mV/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("mV/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.MillivoltPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("V/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("V/μs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMicrosecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("V/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialChangeRate.ParseUnit("V/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("kV/h", ElectricPotentialChangeRateUnit.KilovoltPerHour)] + [InlineData("kV/μs", ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond)] + [InlineData("kV/min", ElectricPotentialChangeRateUnit.KilovoltPerMinute)] + [InlineData("kV/s", ElectricPotentialChangeRateUnit.KilovoltPerSecond)] + [InlineData("MV/h", ElectricPotentialChangeRateUnit.MegavoltPerHour)] + [InlineData("MV/μs", ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond)] + [InlineData("MV/min", ElectricPotentialChangeRateUnit.MegavoltPerMinute)] + [InlineData("MV/s", ElectricPotentialChangeRateUnit.MegavoltPerSecond)] + [InlineData("µV/h", ElectricPotentialChangeRateUnit.MicrovoltPerHour)] + [InlineData("µV/μs", ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond)] + [InlineData("µV/min", ElectricPotentialChangeRateUnit.MicrovoltPerMinute)] + [InlineData("µV/s", ElectricPotentialChangeRateUnit.MicrovoltPerSecond)] + [InlineData("mV/h", ElectricPotentialChangeRateUnit.MillivoltPerHour)] + [InlineData("mV/μs", ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond)] + [InlineData("mV/min", ElectricPotentialChangeRateUnit.MillivoltPerMinute)] + [InlineData("mV/s", ElectricPotentialChangeRateUnit.MillivoltPerSecond)] + [InlineData("V/h", ElectricPotentialChangeRateUnit.VoltPerHour)] + [InlineData("V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] + [InlineData("V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] + [InlineData("V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] + public void ParseUnit(string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricPotentialChangeRateUnit parsedUnit = ElectricPotentialChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("kV/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerHour, parsedUnit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("kV/μs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond, parsedUnit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("kV/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerMinute, parsedUnit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("kV/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.KilovoltPerSecond, parsedUnit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("µV/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerHour, parsedUnit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("µV/μs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond, parsedUnit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("µV/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerMinute, parsedUnit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("µV/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.MicrovoltPerSecond, parsedUnit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("V/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerHour, parsedUnit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("V/μs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMicrosecond, parsedUnit); - } - - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("V/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerMinute, parsedUnit); - } + [Theory] + [InlineData("en-US", "kV/h", ElectricPotentialChangeRateUnit.KilovoltPerHour)] + [InlineData("en-US", "kV/μs", ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond)] + [InlineData("en-US", "kV/min", ElectricPotentialChangeRateUnit.KilovoltPerMinute)] + [InlineData("en-US", "kV/s", ElectricPotentialChangeRateUnit.KilovoltPerSecond)] + [InlineData("en-US", "MV/h", ElectricPotentialChangeRateUnit.MegavoltPerHour)] + [InlineData("en-US", "MV/μs", ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond)] + [InlineData("en-US", "MV/min", ElectricPotentialChangeRateUnit.MegavoltPerMinute)] + [InlineData("en-US", "MV/s", ElectricPotentialChangeRateUnit.MegavoltPerSecond)] + [InlineData("en-US", "µV/h", ElectricPotentialChangeRateUnit.MicrovoltPerHour)] + [InlineData("en-US", "µV/μs", ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond)] + [InlineData("en-US", "µV/min", ElectricPotentialChangeRateUnit.MicrovoltPerMinute)] + [InlineData("en-US", "µV/s", ElectricPotentialChangeRateUnit.MicrovoltPerSecond)] + [InlineData("en-US", "mV/h", ElectricPotentialChangeRateUnit.MillivoltPerHour)] + [InlineData("en-US", "mV/μs", ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond)] + [InlineData("en-US", "mV/min", ElectricPotentialChangeRateUnit.MillivoltPerMinute)] + [InlineData("en-US", "mV/s", ElectricPotentialChangeRateUnit.MillivoltPerSecond)] + [InlineData("en-US", "V/h", ElectricPotentialChangeRateUnit.VoltPerHour)] + [InlineData("en-US", "V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] + [InlineData("en-US", "V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] + [InlineData("en-US", "V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + { + ElectricPotentialChangeRateUnit parsedUnit = ElectricPotentialChangeRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricPotentialChangeRate.TryParseUnit("V/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialChangeRateUnit.VoltPerSecond, parsedUnit); - } + [Theory] + [InlineData("kV/h", ElectricPotentialChangeRateUnit.KilovoltPerHour)] + [InlineData("kV/μs", ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond)] + [InlineData("kV/min", ElectricPotentialChangeRateUnit.KilovoltPerMinute)] + [InlineData("kV/s", ElectricPotentialChangeRateUnit.KilovoltPerSecond)] + [InlineData("MV/h", ElectricPotentialChangeRateUnit.MegavoltPerHour)] + [InlineData("MV/μs", ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond)] + [InlineData("MV/min", ElectricPotentialChangeRateUnit.MegavoltPerMinute)] + [InlineData("MV/s", ElectricPotentialChangeRateUnit.MegavoltPerSecond)] + [InlineData("µV/h", ElectricPotentialChangeRateUnit.MicrovoltPerHour)] + [InlineData("µV/μs", ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond)] + [InlineData("µV/min", ElectricPotentialChangeRateUnit.MicrovoltPerMinute)] + [InlineData("µV/s", ElectricPotentialChangeRateUnit.MicrovoltPerSecond)] + [InlineData("mV/h", ElectricPotentialChangeRateUnit.MillivoltPerHour)] + [InlineData("mV/μs", ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond)] + [InlineData("mV/min", ElectricPotentialChangeRateUnit.MillivoltPerMinute)] + [InlineData("mV/s", ElectricPotentialChangeRateUnit.MillivoltPerSecond)] + [InlineData("V/h", ElectricPotentialChangeRateUnit.VoltPerHour)] + [InlineData("V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] + [InlineData("V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] + [InlineData("V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] + public void TryParseUnit(string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricPotentialChangeRate.TryParseUnit(abbreviation, out ElectricPotentialChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kV/h", ElectricPotentialChangeRateUnit.KilovoltPerHour)] + [InlineData("en-US", "kV/μs", ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond)] + [InlineData("en-US", "kV/min", ElectricPotentialChangeRateUnit.KilovoltPerMinute)] + [InlineData("en-US", "kV/s", ElectricPotentialChangeRateUnit.KilovoltPerSecond)] + [InlineData("en-US", "MV/h", ElectricPotentialChangeRateUnit.MegavoltPerHour)] + [InlineData("en-US", "MV/μs", ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond)] + [InlineData("en-US", "MV/min", ElectricPotentialChangeRateUnit.MegavoltPerMinute)] + [InlineData("en-US", "MV/s", ElectricPotentialChangeRateUnit.MegavoltPerSecond)] + [InlineData("en-US", "µV/h", ElectricPotentialChangeRateUnit.MicrovoltPerHour)] + [InlineData("en-US", "µV/μs", ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond)] + [InlineData("en-US", "µV/min", ElectricPotentialChangeRateUnit.MicrovoltPerMinute)] + [InlineData("en-US", "µV/s", ElectricPotentialChangeRateUnit.MicrovoltPerSecond)] + [InlineData("en-US", "mV/h", ElectricPotentialChangeRateUnit.MillivoltPerHour)] + [InlineData("en-US", "mV/μs", ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond)] + [InlineData("en-US", "mV/min", ElectricPotentialChangeRateUnit.MillivoltPerMinute)] + [InlineData("en-US", "mV/s", ElectricPotentialChangeRateUnit.MillivoltPerSecond)] + [InlineData("en-US", "V/h", ElectricPotentialChangeRateUnit.VoltPerHour)] + [InlineData("en-US", "V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] + [InlineData("en-US", "V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] + [InlineData("en-US", "V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + { + Assert.True(ElectricPotentialChangeRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricPotentialChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs index 78d0e1936d..4095b47e21 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs @@ -280,59 +280,54 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("kVdc", ElectricPotentialDcUnit.KilovoltDc)] + [InlineData("MVdc", ElectricPotentialDcUnit.MegavoltDc)] + [InlineData("µVdc", ElectricPotentialDcUnit.MicrovoltDc)] + [InlineData("mVdc", ElectricPotentialDcUnit.MillivoltDc)] + [InlineData("Vdc", ElectricPotentialDcUnit.VoltDc)] + public void ParseUnit(string abbreviation, ElectricPotentialDcUnit expectedUnit) { - try - { - var parsedUnit = ElectricPotentialDc.ParseUnit("kVdc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialDcUnit.KilovoltDc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialDc.ParseUnit("MVdc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialDcUnit.MegavoltDc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialDc.ParseUnit("µVdc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialDcUnit.MicrovoltDc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialDc.ParseUnit("mVdc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialDcUnit.MillivoltDc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotentialDc.ParseUnit("Vdc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialDcUnit.VoltDc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricPotentialDcUnit parsedUnit = ElectricPotentialDc.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "kVdc", ElectricPotentialDcUnit.KilovoltDc)] + [InlineData("en-US", "MVdc", ElectricPotentialDcUnit.MegavoltDc)] + [InlineData("en-US", "µVdc", ElectricPotentialDcUnit.MicrovoltDc)] + [InlineData("en-US", "mVdc", ElectricPotentialDcUnit.MillivoltDc)] + [InlineData("en-US", "Vdc", ElectricPotentialDcUnit.VoltDc)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) { - { - Assert.True(ElectricPotentialDc.TryParseUnit("kVdc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialDcUnit.KilovoltDc, parsedUnit); - } - - { - Assert.True(ElectricPotentialDc.TryParseUnit("µVdc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialDcUnit.MicrovoltDc, parsedUnit); - } + ElectricPotentialDcUnit parsedUnit = ElectricPotentialDc.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricPotentialDc.TryParseUnit("Vdc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialDcUnit.VoltDc, parsedUnit); - } + [Theory] + [InlineData("kVdc", ElectricPotentialDcUnit.KilovoltDc)] + [InlineData("MVdc", ElectricPotentialDcUnit.MegavoltDc)] + [InlineData("µVdc", ElectricPotentialDcUnit.MicrovoltDc)] + [InlineData("mVdc", ElectricPotentialDcUnit.MillivoltDc)] + [InlineData("Vdc", ElectricPotentialDcUnit.VoltDc)] + public void TryParseUnit(string abbreviation, ElectricPotentialDcUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricPotentialDc.TryParseUnit(abbreviation, out ElectricPotentialDcUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kVdc", ElectricPotentialDcUnit.KilovoltDc)] + [InlineData("en-US", "MVdc", ElectricPotentialDcUnit.MegavoltDc)] + [InlineData("en-US", "µVdc", ElectricPotentialDcUnit.MicrovoltDc)] + [InlineData("en-US", "mVdc", ElectricPotentialDcUnit.MillivoltDc)] + [InlineData("en-US", "Vdc", ElectricPotentialDcUnit.VoltDc)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) + { + Assert.True(ElectricPotentialDc.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricPotentialDcUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs index 2daa81517b..fc80b707d9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs @@ -369,126 +369,70 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("kV", ElectricPotentialUnit.Kilovolt)] + [InlineData("MV", ElectricPotentialUnit.Megavolt)] + [InlineData("µV", ElectricPotentialUnit.Microvolt)] + [InlineData("mV", ElectricPotentialUnit.Millivolt)] + [InlineData("nV", ElectricPotentialUnit.Nanovolt)] + [InlineData("V", ElectricPotentialUnit.Volt)] + public void ParseUnit(string abbreviation, ElectricPotentialUnit expectedUnit) { - try - { - var parsedUnit = ElectricPotential.ParseUnit("kV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialUnit.Kilovolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotential.ParseUnit("кВ", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ElectricPotentialUnit.Kilovolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotential.ParseUnit("MV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialUnit.Megavolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotential.ParseUnit("МВ", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ElectricPotentialUnit.Megavolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotential.ParseUnit("µV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialUnit.Microvolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotential.ParseUnit("мкВ", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ElectricPotentialUnit.Microvolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotential.ParseUnit("mV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialUnit.Millivolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotential.ParseUnit("мВ", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ElectricPotentialUnit.Millivolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotential.ParseUnit("nV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialUnit.Nanovolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotential.ParseUnit("нВ", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ElectricPotentialUnit.Nanovolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotential.ParseUnit("V", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricPotentialUnit.Volt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricPotential.ParseUnit("В", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ElectricPotentialUnit.Volt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricPotentialUnit parsedUnit = ElectricPotential.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kV", ElectricPotentialUnit.Kilovolt)] + [InlineData("en-US", "MV", ElectricPotentialUnit.Megavolt)] + [InlineData("en-US", "µV", ElectricPotentialUnit.Microvolt)] + [InlineData("en-US", "mV", ElectricPotentialUnit.Millivolt)] + [InlineData("en-US", "nV", ElectricPotentialUnit.Nanovolt)] + [InlineData("en-US", "V", ElectricPotentialUnit.Volt)] + [InlineData("ru-RU", "кВ", ElectricPotentialUnit.Kilovolt)] + [InlineData("ru-RU", "МВ", ElectricPotentialUnit.Megavolt)] + [InlineData("ru-RU", "мкВ", ElectricPotentialUnit.Microvolt)] + [InlineData("ru-RU", "мВ", ElectricPotentialUnit.Millivolt)] + [InlineData("ru-RU", "нВ", ElectricPotentialUnit.Nanovolt)] + [InlineData("ru-RU", "В", ElectricPotentialUnit.Volt)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialUnit expectedUnit) + { + ElectricPotentialUnit parsedUnit = ElectricPotential.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("kV", ElectricPotentialUnit.Kilovolt)] + [InlineData("MV", ElectricPotentialUnit.Megavolt)] + [InlineData("µV", ElectricPotentialUnit.Microvolt)] + [InlineData("mV", ElectricPotentialUnit.Millivolt)] + [InlineData("nV", ElectricPotentialUnit.Nanovolt)] + [InlineData("V", ElectricPotentialUnit.Volt)] + public void TryParseUnit(string abbreviation, ElectricPotentialUnit expectedUnit) { - { - Assert.True(ElectricPotential.TryParseUnit("kV", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialUnit.Kilovolt, parsedUnit); - } - - { - Assert.True(ElectricPotential.TryParseUnit("кВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ElectricPotentialUnit.Kilovolt, parsedUnit); - } - - { - Assert.True(ElectricPotential.TryParseUnit("µV", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialUnit.Microvolt, parsedUnit); - } - - { - Assert.True(ElectricPotential.TryParseUnit("мкВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ElectricPotentialUnit.Microvolt, parsedUnit); - } - - { - Assert.True(ElectricPotential.TryParseUnit("nV", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialUnit.Nanovolt, parsedUnit); - } - - { - Assert.True(ElectricPotential.TryParseUnit("нВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ElectricPotentialUnit.Nanovolt, parsedUnit); - } - - { - Assert.True(ElectricPotential.TryParseUnit("V", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricPotentialUnit.Volt, parsedUnit); - } - - { - Assert.True(ElectricPotential.TryParseUnit("В", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ElectricPotentialUnit.Volt, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricPotential.TryParseUnit(abbreviation, out ElectricPotentialUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kV", ElectricPotentialUnit.Kilovolt)] + [InlineData("en-US", "MV", ElectricPotentialUnit.Megavolt)] + [InlineData("en-US", "µV", ElectricPotentialUnit.Microvolt)] + [InlineData("en-US", "mV", ElectricPotentialUnit.Millivolt)] + [InlineData("en-US", "nV", ElectricPotentialUnit.Nanovolt)] + [InlineData("en-US", "V", ElectricPotentialUnit.Volt)] + [InlineData("ru-RU", "кВ", ElectricPotentialUnit.Kilovolt)] + [InlineData("ru-RU", "МВ", ElectricPotentialUnit.Megavolt)] + [InlineData("ru-RU", "мкВ", ElectricPotentialUnit.Microvolt)] + [InlineData("ru-RU", "мВ", ElectricPotentialUnit.Millivolt)] + [InlineData("ru-RU", "нВ", ElectricPotentialUnit.Nanovolt)] + [InlineData("ru-RU", "В", ElectricPotentialUnit.Volt)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialUnit expectedUnit) + { + Assert.True(ElectricPotential.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricPotentialUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs index b3991642f0..2604e0d10e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs @@ -326,81 +326,62 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("GΩ", ElectricResistanceUnit.Gigaohm)] + [InlineData("kΩ", ElectricResistanceUnit.Kiloohm)] + [InlineData("MΩ", ElectricResistanceUnit.Megaohm)] + [InlineData("µΩ", ElectricResistanceUnit.Microohm)] + [InlineData("mΩ", ElectricResistanceUnit.Milliohm)] + [InlineData("Ω", ElectricResistanceUnit.Ohm)] + [InlineData("TΩ", ElectricResistanceUnit.Teraohm)] + public void ParseUnit(string abbreviation, ElectricResistanceUnit expectedUnit) { - try - { - var parsedUnit = ElectricResistance.ParseUnit("GΩ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistanceUnit.Gigaohm, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistance.ParseUnit("kΩ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistanceUnit.Kiloohm, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistance.ParseUnit("MΩ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistanceUnit.Megaohm, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistance.ParseUnit("µΩ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistanceUnit.Microohm, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistance.ParseUnit("mΩ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistanceUnit.Milliohm, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistance.ParseUnit("Ω", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistanceUnit.Ohm, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistance.ParseUnit("TΩ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistanceUnit.Teraohm, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricResistanceUnit parsedUnit = ElectricResistance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "GΩ", ElectricResistanceUnit.Gigaohm)] + [InlineData("en-US", "kΩ", ElectricResistanceUnit.Kiloohm)] + [InlineData("en-US", "MΩ", ElectricResistanceUnit.Megaohm)] + [InlineData("en-US", "µΩ", ElectricResistanceUnit.Microohm)] + [InlineData("en-US", "mΩ", ElectricResistanceUnit.Milliohm)] + [InlineData("en-US", "Ω", ElectricResistanceUnit.Ohm)] + [InlineData("en-US", "TΩ", ElectricResistanceUnit.Teraohm)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricResistanceUnit expectedUnit) { - { - Assert.True(ElectricResistance.TryParseUnit("GΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistanceUnit.Gigaohm, parsedUnit); - } - - { - Assert.True(ElectricResistance.TryParseUnit("kΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistanceUnit.Kiloohm, parsedUnit); - } - - { - Assert.True(ElectricResistance.TryParseUnit("µΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistanceUnit.Microohm, parsedUnit); - } - - { - Assert.True(ElectricResistance.TryParseUnit("Ω", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistanceUnit.Ohm, parsedUnit); - } + ElectricResistanceUnit parsedUnit = ElectricResistance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricResistance.TryParseUnit("TΩ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistanceUnit.Teraohm, parsedUnit); - } + [Theory] + [InlineData("GΩ", ElectricResistanceUnit.Gigaohm)] + [InlineData("kΩ", ElectricResistanceUnit.Kiloohm)] + [InlineData("MΩ", ElectricResistanceUnit.Megaohm)] + [InlineData("µΩ", ElectricResistanceUnit.Microohm)] + [InlineData("mΩ", ElectricResistanceUnit.Milliohm)] + [InlineData("Ω", ElectricResistanceUnit.Ohm)] + [InlineData("TΩ", ElectricResistanceUnit.Teraohm)] + public void TryParseUnit(string abbreviation, ElectricResistanceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricResistance.TryParseUnit(abbreviation, out ElectricResistanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "GΩ", ElectricResistanceUnit.Gigaohm)] + [InlineData("en-US", "kΩ", ElectricResistanceUnit.Kiloohm)] + [InlineData("en-US", "MΩ", ElectricResistanceUnit.Megaohm)] + [InlineData("en-US", "µΩ", ElectricResistanceUnit.Microohm)] + [InlineData("en-US", "mΩ", ElectricResistanceUnit.Milliohm)] + [InlineData("en-US", "Ω", ElectricResistanceUnit.Ohm)] + [InlineData("en-US", "TΩ", ElectricResistanceUnit.Teraohm)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricResistanceUnit expectedUnit) + { + Assert.True(ElectricResistance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricResistanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs index 10352509e2..1e5d211855 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs @@ -475,148 +475,90 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = ElectricResistivity.ParseUnit("kΩ·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.KiloohmCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("kΩ·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.KiloohmMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("MΩ·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.MegaohmCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("MΩ·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.MegaohmMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("µΩ·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.MicroohmCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("µΩ·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.MicroohmMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("mΩ·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.MilliohmCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("mΩ·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.MilliohmMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("nΩ·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.NanoohmCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("nΩ·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.NanoohmMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("Ω·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.OhmCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("Ω·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.OhmMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("pΩ·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.PicoohmCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricResistivity.ParseUnit("pΩ·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricResistivityUnit.PicoohmMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("kΩ·cm", ElectricResistivityUnit.KiloohmCentimeter)] + [InlineData("kΩ·m", ElectricResistivityUnit.KiloohmMeter)] + [InlineData("MΩ·cm", ElectricResistivityUnit.MegaohmCentimeter)] + [InlineData("MΩ·m", ElectricResistivityUnit.MegaohmMeter)] + [InlineData("µΩ·cm", ElectricResistivityUnit.MicroohmCentimeter)] + [InlineData("µΩ·m", ElectricResistivityUnit.MicroohmMeter)] + [InlineData("mΩ·cm", ElectricResistivityUnit.MilliohmCentimeter)] + [InlineData("mΩ·m", ElectricResistivityUnit.MilliohmMeter)] + [InlineData("nΩ·cm", ElectricResistivityUnit.NanoohmCentimeter)] + [InlineData("nΩ·m", ElectricResistivityUnit.NanoohmMeter)] + [InlineData("Ω·cm", ElectricResistivityUnit.OhmCentimeter)] + [InlineData("Ω·m", ElectricResistivityUnit.OhmMeter)] + [InlineData("pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] + [InlineData("pΩ·m", ElectricResistivityUnit.PicoohmMeter)] + public void ParseUnit(string abbreviation, ElectricResistivityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricResistivityUnit parsedUnit = ElectricResistivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(ElectricResistivity.TryParseUnit("kΩ·cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistivityUnit.KiloohmCentimeter, parsedUnit); - } - - { - Assert.True(ElectricResistivity.TryParseUnit("kΩ·m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistivityUnit.KiloohmMeter, parsedUnit); - } - - { - Assert.True(ElectricResistivity.TryParseUnit("µΩ·cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistivityUnit.MicroohmCentimeter, parsedUnit); - } - - { - Assert.True(ElectricResistivity.TryParseUnit("µΩ·m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistivityUnit.MicroohmMeter, parsedUnit); - } - - { - Assert.True(ElectricResistivity.TryParseUnit("nΩ·cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistivityUnit.NanoohmCentimeter, parsedUnit); - } - - { - Assert.True(ElectricResistivity.TryParseUnit("nΩ·m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistivityUnit.NanoohmMeter, parsedUnit); - } - - { - Assert.True(ElectricResistivity.TryParseUnit("Ω·cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistivityUnit.OhmCentimeter, parsedUnit); - } - - { - Assert.True(ElectricResistivity.TryParseUnit("Ω·m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistivityUnit.OhmMeter, parsedUnit); - } - - { - Assert.True(ElectricResistivity.TryParseUnit("pΩ·cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistivityUnit.PicoohmCentimeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "kΩ·cm", ElectricResistivityUnit.KiloohmCentimeter)] + [InlineData("en-US", "kΩ·m", ElectricResistivityUnit.KiloohmMeter)] + [InlineData("en-US", "MΩ·cm", ElectricResistivityUnit.MegaohmCentimeter)] + [InlineData("en-US", "MΩ·m", ElectricResistivityUnit.MegaohmMeter)] + [InlineData("en-US", "µΩ·cm", ElectricResistivityUnit.MicroohmCentimeter)] + [InlineData("en-US", "µΩ·m", ElectricResistivityUnit.MicroohmMeter)] + [InlineData("en-US", "mΩ·cm", ElectricResistivityUnit.MilliohmCentimeter)] + [InlineData("en-US", "mΩ·m", ElectricResistivityUnit.MilliohmMeter)] + [InlineData("en-US", "nΩ·cm", ElectricResistivityUnit.NanoohmCentimeter)] + [InlineData("en-US", "nΩ·m", ElectricResistivityUnit.NanoohmMeter)] + [InlineData("en-US", "Ω·cm", ElectricResistivityUnit.OhmCentimeter)] + [InlineData("en-US", "Ω·m", ElectricResistivityUnit.OhmMeter)] + [InlineData("en-US", "pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] + [InlineData("en-US", "pΩ·m", ElectricResistivityUnit.PicoohmMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricResistivityUnit expectedUnit) + { + ElectricResistivityUnit parsedUnit = ElectricResistivity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricResistivity.TryParseUnit("pΩ·m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricResistivityUnit.PicoohmMeter, parsedUnit); - } + [Theory] + [InlineData("kΩ·cm", ElectricResistivityUnit.KiloohmCentimeter)] + [InlineData("kΩ·m", ElectricResistivityUnit.KiloohmMeter)] + [InlineData("MΩ·cm", ElectricResistivityUnit.MegaohmCentimeter)] + [InlineData("MΩ·m", ElectricResistivityUnit.MegaohmMeter)] + [InlineData("µΩ·cm", ElectricResistivityUnit.MicroohmCentimeter)] + [InlineData("µΩ·m", ElectricResistivityUnit.MicroohmMeter)] + [InlineData("mΩ·cm", ElectricResistivityUnit.MilliohmCentimeter)] + [InlineData("mΩ·m", ElectricResistivityUnit.MilliohmMeter)] + [InlineData("nΩ·cm", ElectricResistivityUnit.NanoohmCentimeter)] + [InlineData("nΩ·m", ElectricResistivityUnit.NanoohmMeter)] + [InlineData("Ω·cm", ElectricResistivityUnit.OhmCentimeter)] + [InlineData("Ω·m", ElectricResistivityUnit.OhmMeter)] + [InlineData("pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] + [InlineData("pΩ·m", ElectricResistivityUnit.PicoohmMeter)] + public void TryParseUnit(string abbreviation, ElectricResistivityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricResistivity.TryParseUnit(abbreviation, out ElectricResistivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kΩ·cm", ElectricResistivityUnit.KiloohmCentimeter)] + [InlineData("en-US", "kΩ·m", ElectricResistivityUnit.KiloohmMeter)] + [InlineData("en-US", "MΩ·cm", ElectricResistivityUnit.MegaohmCentimeter)] + [InlineData("en-US", "MΩ·m", ElectricResistivityUnit.MegaohmMeter)] + [InlineData("en-US", "µΩ·cm", ElectricResistivityUnit.MicroohmCentimeter)] + [InlineData("en-US", "µΩ·m", ElectricResistivityUnit.MicroohmMeter)] + [InlineData("en-US", "mΩ·cm", ElectricResistivityUnit.MilliohmCentimeter)] + [InlineData("en-US", "mΩ·m", ElectricResistivityUnit.MilliohmMeter)] + [InlineData("en-US", "nΩ·cm", ElectricResistivityUnit.NanoohmCentimeter)] + [InlineData("en-US", "nΩ·m", ElectricResistivityUnit.NanoohmMeter)] + [InlineData("en-US", "Ω·cm", ElectricResistivityUnit.OhmCentimeter)] + [InlineData("en-US", "Ω·m", ElectricResistivityUnit.OhmMeter)] + [InlineData("en-US", "pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] + [InlineData("en-US", "pΩ·m", ElectricResistivityUnit.PicoohmMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricResistivityUnit expectedUnit) + { + Assert.True(ElectricResistivity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricResistivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs index 54a386e7d6..9b58daf88c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs @@ -246,47 +246,46 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] + [InlineData("C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] + [InlineData("C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] + public void ParseUnit(string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) { - try - { - var parsedUnit = ElectricSurfaceChargeDensity.ParseUnit("C/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricSurfaceChargeDensity.ParseUnit("C/in²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ElectricSurfaceChargeDensity.ParseUnit("C/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ElectricSurfaceChargeDensityUnit parsedUnit = ElectricSurfaceChargeDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] + [InlineData("en-US", "C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] + [InlineData("en-US", "C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) { - { - Assert.True(ElectricSurfaceChargeDensity.TryParseUnit("C/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(ElectricSurfaceChargeDensity.TryParseUnit("C/in²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch, parsedUnit); - } + ElectricSurfaceChargeDensityUnit parsedUnit = ElectricSurfaceChargeDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ElectricSurfaceChargeDensity.TryParseUnit("C/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter, parsedUnit); - } + [Theory] + [InlineData("C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] + [InlineData("C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] + [InlineData("C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] + public void TryParseUnit(string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ElectricSurfaceChargeDensity.TryParseUnit(abbreviation, out ElectricSurfaceChargeDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] + [InlineData("en-US", "C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] + [InlineData("en-US", "C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) + { + Assert.True(ElectricSurfaceChargeDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricSurfaceChargeDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs index 0bcf088a12..3c5c8f6b48 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs @@ -453,146 +453,82 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = EnergyDensity.ParseUnit("GJ/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.GigajoulePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyDensity.ParseUnit("GWh/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.GigawattHourPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyDensity.ParseUnit("J/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.JoulePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyDensity.ParseUnit("kJ/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.KilojoulePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyDensity.ParseUnit("kWh/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.KilowattHourPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyDensity.ParseUnit("MJ/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.MegajoulePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyDensity.ParseUnit("MWh/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.MegawattHourPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyDensity.ParseUnit("PJ/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.PetajoulePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyDensity.ParseUnit("PWh/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.PetawattHourPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyDensity.ParseUnit("TJ/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.TerajoulePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyDensity.ParseUnit("TWh/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.TerawattHourPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = EnergyDensity.ParseUnit("Wh/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyDensityUnit.WattHourPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("GJ/m³", EnergyDensityUnit.GigajoulePerCubicMeter)] + [InlineData("GWh/m³", EnergyDensityUnit.GigawattHourPerCubicMeter)] + [InlineData("J/m³", EnergyDensityUnit.JoulePerCubicMeter)] + [InlineData("kJ/m³", EnergyDensityUnit.KilojoulePerCubicMeter)] + [InlineData("kWh/m³", EnergyDensityUnit.KilowattHourPerCubicMeter)] + [InlineData("MJ/m³", EnergyDensityUnit.MegajoulePerCubicMeter)] + [InlineData("MWh/m³", EnergyDensityUnit.MegawattHourPerCubicMeter)] + [InlineData("PJ/m³", EnergyDensityUnit.PetajoulePerCubicMeter)] + [InlineData("PWh/m³", EnergyDensityUnit.PetawattHourPerCubicMeter)] + [InlineData("TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] + [InlineData("TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] + [InlineData("Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] + public void ParseUnit(string abbreviation, EnergyDensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + EnergyDensityUnit parsedUnit = EnergyDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(EnergyDensity.TryParseUnit("GJ/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.GigajoulePerCubicMeter, parsedUnit); - } - - { - Assert.True(EnergyDensity.TryParseUnit("GWh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.GigawattHourPerCubicMeter, parsedUnit); - } - - { - Assert.True(EnergyDensity.TryParseUnit("J/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.JoulePerCubicMeter, parsedUnit); - } - - { - Assert.True(EnergyDensity.TryParseUnit("kJ/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.KilojoulePerCubicMeter, parsedUnit); - } - - { - Assert.True(EnergyDensity.TryParseUnit("kWh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.KilowattHourPerCubicMeter, parsedUnit); - } - - { - Assert.True(EnergyDensity.TryParseUnit("MJ/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.MegajoulePerCubicMeter, parsedUnit); - } - - { - Assert.True(EnergyDensity.TryParseUnit("MWh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.MegawattHourPerCubicMeter, parsedUnit); - } - - { - Assert.True(EnergyDensity.TryParseUnit("PJ/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.PetajoulePerCubicMeter, parsedUnit); - } - - { - Assert.True(EnergyDensity.TryParseUnit("PWh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.PetawattHourPerCubicMeter, parsedUnit); - } - - { - Assert.True(EnergyDensity.TryParseUnit("TJ/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.TerajoulePerCubicMeter, parsedUnit); - } - - { - Assert.True(EnergyDensity.TryParseUnit("TWh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.TerawattHourPerCubicMeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "GJ/m³", EnergyDensityUnit.GigajoulePerCubicMeter)] + [InlineData("en-US", "GWh/m³", EnergyDensityUnit.GigawattHourPerCubicMeter)] + [InlineData("en-US", "J/m³", EnergyDensityUnit.JoulePerCubicMeter)] + [InlineData("en-US", "kJ/m³", EnergyDensityUnit.KilojoulePerCubicMeter)] + [InlineData("en-US", "kWh/m³", EnergyDensityUnit.KilowattHourPerCubicMeter)] + [InlineData("en-US", "MJ/m³", EnergyDensityUnit.MegajoulePerCubicMeter)] + [InlineData("en-US", "MWh/m³", EnergyDensityUnit.MegawattHourPerCubicMeter)] + [InlineData("en-US", "PJ/m³", EnergyDensityUnit.PetajoulePerCubicMeter)] + [InlineData("en-US", "PWh/m³", EnergyDensityUnit.PetawattHourPerCubicMeter)] + [InlineData("en-US", "TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] + [InlineData("en-US", "TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] + [InlineData("en-US", "Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, EnergyDensityUnit expectedUnit) + { + EnergyDensityUnit parsedUnit = EnergyDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(EnergyDensity.TryParseUnit("Wh/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyDensityUnit.WattHourPerCubicMeter, parsedUnit); - } + [Theory] + [InlineData("GJ/m³", EnergyDensityUnit.GigajoulePerCubicMeter)] + [InlineData("GWh/m³", EnergyDensityUnit.GigawattHourPerCubicMeter)] + [InlineData("J/m³", EnergyDensityUnit.JoulePerCubicMeter)] + [InlineData("kJ/m³", EnergyDensityUnit.KilojoulePerCubicMeter)] + [InlineData("kWh/m³", EnergyDensityUnit.KilowattHourPerCubicMeter)] + [InlineData("MJ/m³", EnergyDensityUnit.MegajoulePerCubicMeter)] + [InlineData("MWh/m³", EnergyDensityUnit.MegawattHourPerCubicMeter)] + [InlineData("PJ/m³", EnergyDensityUnit.PetajoulePerCubicMeter)] + [InlineData("PWh/m³", EnergyDensityUnit.PetawattHourPerCubicMeter)] + [InlineData("TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] + [InlineData("TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] + [InlineData("Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] + public void TryParseUnit(string abbreviation, EnergyDensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(EnergyDensity.TryParseUnit(abbreviation, out EnergyDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "GJ/m³", EnergyDensityUnit.GigajoulePerCubicMeter)] + [InlineData("en-US", "GWh/m³", EnergyDensityUnit.GigawattHourPerCubicMeter)] + [InlineData("en-US", "J/m³", EnergyDensityUnit.JoulePerCubicMeter)] + [InlineData("en-US", "kJ/m³", EnergyDensityUnit.KilojoulePerCubicMeter)] + [InlineData("en-US", "kWh/m³", EnergyDensityUnit.KilowattHourPerCubicMeter)] + [InlineData("en-US", "MJ/m³", EnergyDensityUnit.MegajoulePerCubicMeter)] + [InlineData("en-US", "MWh/m³", EnergyDensityUnit.MegawattHourPerCubicMeter)] + [InlineData("en-US", "PJ/m³", EnergyDensityUnit.PetajoulePerCubicMeter)] + [InlineData("en-US", "PWh/m³", EnergyDensityUnit.PetawattHourPerCubicMeter)] + [InlineData("en-US", "TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] + [InlineData("en-US", "TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] + [InlineData("en-US", "Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, EnergyDensityUnit expectedUnit) + { + Assert.True(EnergyDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out EnergyDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs index 8af5cb4921..b05ca1f230 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs @@ -1358,675 +1358,236 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Energy.ParseUnit("BTU", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.BritishThermalUnit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("cal", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Calorie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Dth (E.C.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.DecathermEc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Европейский декатерм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.DecathermEc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Dth (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.DecathermImperial, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Английский декатерм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.DecathermImperial, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Dth (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.DecathermUs, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Американский декатерм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.DecathermUs, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("eV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.ElectronVolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("эВ", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.ElectronVolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("erg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Erg, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("ft·lb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.FootPound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("GBTU", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.GigabritishThermalUnit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("GeV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.GigaelectronVolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("ГэВ", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.GigaelectronVolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("GJ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Gigajoule, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("GWd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.GigawattDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("ГВт/д", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.GigawattDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("GWh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.GigawattHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("ГВт/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.GigawattHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("hp·h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.HorsepowerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("J", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Joule, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("kBTU", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.KilobritishThermalUnit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("kcal", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Kilocalorie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("keV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.KiloelectronVolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("кэВ", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.KiloelectronVolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("kJ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Kilojoule, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("kWd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.KilowattDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("кВт/д", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.KilowattDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("kWh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.KilowattHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("кВт/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.KilowattHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("MBTU", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.MegabritishThermalUnit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Mcal", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Megacalorie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("MeV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.MegaelectronVolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("МэВ", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.MegaelectronVolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("MJ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Megajoule, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("MWd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.MegawattDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("МВт/д", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.MegawattDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("MWh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.MegawattHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("МВт/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.MegawattHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("µJ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Microjoule, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("mJ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Millijoule, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("nJ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Nanojoule, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("PJ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Petajoule, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("TeV", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.TeraelectronVolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("ТэВ", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.TeraelectronVolt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("TJ", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.Terajoule, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("TWd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.TerawattDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("ТВт/д", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.TerawattDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("TWh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.TerawattHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("ТВт/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.TerawattHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("th (E.C.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.ThermEc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Европейский терм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.ThermEc, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("th (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.ThermImperial, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Английский терм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.ThermImperial, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("th (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.ThermUs, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Американский терм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.ThermUs, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Wd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.WattDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Вт/д", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.WattDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Wh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EnergyUnit.WattHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Energy.ParseUnit("Вт/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(EnergyUnit.WattHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("BTU", EnergyUnit.BritishThermalUnit)] + [InlineData("cal", EnergyUnit.Calorie)] + [InlineData("Dth (E.C.)", EnergyUnit.DecathermEc)] + [InlineData("Dth (imp.)", EnergyUnit.DecathermImperial)] + [InlineData("Dth (U.S.)", EnergyUnit.DecathermUs)] + [InlineData("eV", EnergyUnit.ElectronVolt)] + [InlineData("erg", EnergyUnit.Erg)] + [InlineData("ft·lb", EnergyUnit.FootPound)] + [InlineData("GBTU", EnergyUnit.GigabritishThermalUnit)] + [InlineData("GeV", EnergyUnit.GigaelectronVolt)] + [InlineData("GJ", EnergyUnit.Gigajoule)] + [InlineData("GWd", EnergyUnit.GigawattDay)] + [InlineData("GWh", EnergyUnit.GigawattHour)] + [InlineData("hp·h", EnergyUnit.HorsepowerHour)] + [InlineData("J", EnergyUnit.Joule)] + [InlineData("kBTU", EnergyUnit.KilobritishThermalUnit)] + [InlineData("kcal", EnergyUnit.Kilocalorie)] + [InlineData("keV", EnergyUnit.KiloelectronVolt)] + [InlineData("kJ", EnergyUnit.Kilojoule)] + [InlineData("kWd", EnergyUnit.KilowattDay)] + [InlineData("kWh", EnergyUnit.KilowattHour)] + [InlineData("MBTU", EnergyUnit.MegabritishThermalUnit)] + [InlineData("Mcal", EnergyUnit.Megacalorie)] + [InlineData("MeV", EnergyUnit.MegaelectronVolt)] + [InlineData("MJ", EnergyUnit.Megajoule)] + [InlineData("MWd", EnergyUnit.MegawattDay)] + [InlineData("MWh", EnergyUnit.MegawattHour)] + [InlineData("µJ", EnergyUnit.Microjoule)] + [InlineData("mJ", EnergyUnit.Millijoule)] + [InlineData("nJ", EnergyUnit.Nanojoule)] + [InlineData("PJ", EnergyUnit.Petajoule)] + [InlineData("TeV", EnergyUnit.TeraelectronVolt)] + [InlineData("TJ", EnergyUnit.Terajoule)] + [InlineData("TWd", EnergyUnit.TerawattDay)] + [InlineData("TWh", EnergyUnit.TerawattHour)] + [InlineData("th (E.C.)", EnergyUnit.ThermEc)] + [InlineData("th (imp.)", EnergyUnit.ThermImperial)] + [InlineData("th (U.S.)", EnergyUnit.ThermUs)] + [InlineData("Wd", EnergyUnit.WattDay)] + [InlineData("Wh", EnergyUnit.WattHour)] + public void ParseUnit(string abbreviation, EnergyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + EnergyUnit parsedUnit = Energy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Energy.TryParseUnit("BTU", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.BritishThermalUnit, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("cal", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.Calorie, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Dth (E.C.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.DecathermEc, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Европейский декатерм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.DecathermEc, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Dth (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.DecathermImperial, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Английский декатерм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.DecathermImperial, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Dth (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.DecathermUs, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Американский декатерм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.DecathermUs, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("eV", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.ElectronVolt, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("эВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.ElectronVolt, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("erg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.Erg, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("ft·lb", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.FootPound, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("GBTU", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.GigabritishThermalUnit, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("GeV", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.GigaelectronVolt, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("ГэВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.GigaelectronVolt, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("GJ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.Gigajoule, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("GWd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.GigawattDay, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("ГВт/д", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.GigawattDay, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("GWh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.GigawattHour, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("ГВт/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.GigawattHour, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("hp·h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.HorsepowerHour, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("J", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.Joule, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("kBTU", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.KilobritishThermalUnit, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("kcal", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.Kilocalorie, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("keV", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.KiloelectronVolt, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("кэВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.KiloelectronVolt, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("kJ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.Kilojoule, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("kWd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.KilowattDay, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("кВт/д", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.KilowattDay, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("kWh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.KilowattHour, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("кВт/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.KilowattHour, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("MBTU", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.MegabritishThermalUnit, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Mcal", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.Megacalorie, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("MeV", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.MegaelectronVolt, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("МэВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.MegaelectronVolt, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("MWd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.MegawattDay, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("МВт/д", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.MegawattDay, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("MWh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.MegawattHour, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("МВт/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.MegawattHour, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("µJ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.Microjoule, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("nJ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.Nanojoule, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("PJ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.Petajoule, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("TeV", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.TeraelectronVolt, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("ТэВ", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.TeraelectronVolt, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("TJ", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.Terajoule, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("TWd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.TerawattDay, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("ТВт/д", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.TerawattDay, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("TWh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.TerawattHour, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("ТВт/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.TerawattHour, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("th (E.C.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.ThermEc, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Европейский терм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.ThermEc, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("th (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.ThermImperial, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Английский терм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.ThermImperial, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("th (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.ThermUs, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Американский терм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.ThermUs, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Wd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.WattDay, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Вт/д", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.WattDay, parsedUnit); - } - - { - Assert.True(Energy.TryParseUnit("Wh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EnergyUnit.WattHour, parsedUnit); - } + [Theory] + [InlineData("en-US", "BTU", EnergyUnit.BritishThermalUnit)] + [InlineData("en-US", "cal", EnergyUnit.Calorie)] + [InlineData("en-US", "Dth (E.C.)", EnergyUnit.DecathermEc)] + [InlineData("en-US", "Dth (imp.)", EnergyUnit.DecathermImperial)] + [InlineData("en-US", "Dth (U.S.)", EnergyUnit.DecathermUs)] + [InlineData("en-US", "eV", EnergyUnit.ElectronVolt)] + [InlineData("en-US", "erg", EnergyUnit.Erg)] + [InlineData("en-US", "ft·lb", EnergyUnit.FootPound)] + [InlineData("en-US", "GBTU", EnergyUnit.GigabritishThermalUnit)] + [InlineData("en-US", "GeV", EnergyUnit.GigaelectronVolt)] + [InlineData("en-US", "GJ", EnergyUnit.Gigajoule)] + [InlineData("en-US", "GWd", EnergyUnit.GigawattDay)] + [InlineData("en-US", "GWh", EnergyUnit.GigawattHour)] + [InlineData("en-US", "hp·h", EnergyUnit.HorsepowerHour)] + [InlineData("en-US", "J", EnergyUnit.Joule)] + [InlineData("en-US", "kBTU", EnergyUnit.KilobritishThermalUnit)] + [InlineData("en-US", "kcal", EnergyUnit.Kilocalorie)] + [InlineData("en-US", "keV", EnergyUnit.KiloelectronVolt)] + [InlineData("en-US", "kJ", EnergyUnit.Kilojoule)] + [InlineData("en-US", "kWd", EnergyUnit.KilowattDay)] + [InlineData("en-US", "kWh", EnergyUnit.KilowattHour)] + [InlineData("en-US", "MBTU", EnergyUnit.MegabritishThermalUnit)] + [InlineData("en-US", "Mcal", EnergyUnit.Megacalorie)] + [InlineData("en-US", "MeV", EnergyUnit.MegaelectronVolt)] + [InlineData("en-US", "MJ", EnergyUnit.Megajoule)] + [InlineData("en-US", "MWd", EnergyUnit.MegawattDay)] + [InlineData("en-US", "MWh", EnergyUnit.MegawattHour)] + [InlineData("en-US", "µJ", EnergyUnit.Microjoule)] + [InlineData("en-US", "mJ", EnergyUnit.Millijoule)] + [InlineData("en-US", "nJ", EnergyUnit.Nanojoule)] + [InlineData("en-US", "PJ", EnergyUnit.Petajoule)] + [InlineData("en-US", "TeV", EnergyUnit.TeraelectronVolt)] + [InlineData("en-US", "TJ", EnergyUnit.Terajoule)] + [InlineData("en-US", "TWd", EnergyUnit.TerawattDay)] + [InlineData("en-US", "TWh", EnergyUnit.TerawattHour)] + [InlineData("en-US", "th (E.C.)", EnergyUnit.ThermEc)] + [InlineData("en-US", "th (imp.)", EnergyUnit.ThermImperial)] + [InlineData("en-US", "th (U.S.)", EnergyUnit.ThermUs)] + [InlineData("en-US", "Wd", EnergyUnit.WattDay)] + [InlineData("en-US", "Wh", EnergyUnit.WattHour)] + [InlineData("ru-RU", "Европейский декатерм", EnergyUnit.DecathermEc)] + [InlineData("ru-RU", "Английский декатерм", EnergyUnit.DecathermImperial)] + [InlineData("ru-RU", "Американский декатерм", EnergyUnit.DecathermUs)] + [InlineData("ru-RU", "эВ", EnergyUnit.ElectronVolt)] + [InlineData("ru-RU", "ГэВ", EnergyUnit.GigaelectronVolt)] + [InlineData("ru-RU", "ГВт/д", EnergyUnit.GigawattDay)] + [InlineData("ru-RU", "ГВт/ч", EnergyUnit.GigawattHour)] + [InlineData("ru-RU", "кэВ", EnergyUnit.KiloelectronVolt)] + [InlineData("ru-RU", "кВт/д", EnergyUnit.KilowattDay)] + [InlineData("ru-RU", "кВт/ч", EnergyUnit.KilowattHour)] + [InlineData("ru-RU", "МэВ", EnergyUnit.MegaelectronVolt)] + [InlineData("ru-RU", "МВт/д", EnergyUnit.MegawattDay)] + [InlineData("ru-RU", "МВт/ч", EnergyUnit.MegawattHour)] + [InlineData("ru-RU", "ТэВ", EnergyUnit.TeraelectronVolt)] + [InlineData("ru-RU", "ТВт/д", EnergyUnit.TerawattDay)] + [InlineData("ru-RU", "ТВт/ч", EnergyUnit.TerawattHour)] + [InlineData("ru-RU", "Европейский терм", EnergyUnit.ThermEc)] + [InlineData("ru-RU", "Английский терм", EnergyUnit.ThermImperial)] + [InlineData("ru-RU", "Американский терм", EnergyUnit.ThermUs)] + [InlineData("ru-RU", "Вт/д", EnergyUnit.WattDay)] + [InlineData("ru-RU", "Вт/ч", EnergyUnit.WattHour)] + public void ParseUnitWithCulture(string culture, string abbreviation, EnergyUnit expectedUnit) + { + EnergyUnit parsedUnit = Energy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Energy.TryParseUnit("Вт/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(EnergyUnit.WattHour, parsedUnit); - } + [Theory] + [InlineData("BTU", EnergyUnit.BritishThermalUnit)] + [InlineData("cal", EnergyUnit.Calorie)] + [InlineData("Dth (E.C.)", EnergyUnit.DecathermEc)] + [InlineData("Dth (imp.)", EnergyUnit.DecathermImperial)] + [InlineData("Dth (U.S.)", EnergyUnit.DecathermUs)] + [InlineData("eV", EnergyUnit.ElectronVolt)] + [InlineData("erg", EnergyUnit.Erg)] + [InlineData("ft·lb", EnergyUnit.FootPound)] + [InlineData("GBTU", EnergyUnit.GigabritishThermalUnit)] + [InlineData("GeV", EnergyUnit.GigaelectronVolt)] + [InlineData("GJ", EnergyUnit.Gigajoule)] + [InlineData("GWd", EnergyUnit.GigawattDay)] + [InlineData("GWh", EnergyUnit.GigawattHour)] + [InlineData("hp·h", EnergyUnit.HorsepowerHour)] + [InlineData("J", EnergyUnit.Joule)] + [InlineData("kBTU", EnergyUnit.KilobritishThermalUnit)] + [InlineData("kcal", EnergyUnit.Kilocalorie)] + [InlineData("keV", EnergyUnit.KiloelectronVolt)] + [InlineData("kJ", EnergyUnit.Kilojoule)] + [InlineData("kWd", EnergyUnit.KilowattDay)] + [InlineData("kWh", EnergyUnit.KilowattHour)] + [InlineData("MBTU", EnergyUnit.MegabritishThermalUnit)] + [InlineData("Mcal", EnergyUnit.Megacalorie)] + [InlineData("MeV", EnergyUnit.MegaelectronVolt)] + [InlineData("MJ", EnergyUnit.Megajoule)] + [InlineData("MWd", EnergyUnit.MegawattDay)] + [InlineData("MWh", EnergyUnit.MegawattHour)] + [InlineData("µJ", EnergyUnit.Microjoule)] + [InlineData("mJ", EnergyUnit.Millijoule)] + [InlineData("nJ", EnergyUnit.Nanojoule)] + [InlineData("PJ", EnergyUnit.Petajoule)] + [InlineData("TeV", EnergyUnit.TeraelectronVolt)] + [InlineData("TJ", EnergyUnit.Terajoule)] + [InlineData("TWd", EnergyUnit.TerawattDay)] + [InlineData("TWh", EnergyUnit.TerawattHour)] + [InlineData("th (E.C.)", EnergyUnit.ThermEc)] + [InlineData("th (imp.)", EnergyUnit.ThermImperial)] + [InlineData("th (U.S.)", EnergyUnit.ThermUs)] + [InlineData("Wd", EnergyUnit.WattDay)] + [InlineData("Wh", EnergyUnit.WattHour)] + public void TryParseUnit(string abbreviation, EnergyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Energy.TryParseUnit(abbreviation, out EnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "BTU", EnergyUnit.BritishThermalUnit)] + [InlineData("en-US", "cal", EnergyUnit.Calorie)] + [InlineData("en-US", "Dth (E.C.)", EnergyUnit.DecathermEc)] + [InlineData("en-US", "Dth (imp.)", EnergyUnit.DecathermImperial)] + [InlineData("en-US", "Dth (U.S.)", EnergyUnit.DecathermUs)] + [InlineData("en-US", "eV", EnergyUnit.ElectronVolt)] + [InlineData("en-US", "erg", EnergyUnit.Erg)] + [InlineData("en-US", "ft·lb", EnergyUnit.FootPound)] + [InlineData("en-US", "GBTU", EnergyUnit.GigabritishThermalUnit)] + [InlineData("en-US", "GeV", EnergyUnit.GigaelectronVolt)] + [InlineData("en-US", "GJ", EnergyUnit.Gigajoule)] + [InlineData("en-US", "GWd", EnergyUnit.GigawattDay)] + [InlineData("en-US", "GWh", EnergyUnit.GigawattHour)] + [InlineData("en-US", "hp·h", EnergyUnit.HorsepowerHour)] + [InlineData("en-US", "J", EnergyUnit.Joule)] + [InlineData("en-US", "kBTU", EnergyUnit.KilobritishThermalUnit)] + [InlineData("en-US", "kcal", EnergyUnit.Kilocalorie)] + [InlineData("en-US", "keV", EnergyUnit.KiloelectronVolt)] + [InlineData("en-US", "kJ", EnergyUnit.Kilojoule)] + [InlineData("en-US", "kWd", EnergyUnit.KilowattDay)] + [InlineData("en-US", "kWh", EnergyUnit.KilowattHour)] + [InlineData("en-US", "MBTU", EnergyUnit.MegabritishThermalUnit)] + [InlineData("en-US", "Mcal", EnergyUnit.Megacalorie)] + [InlineData("en-US", "MeV", EnergyUnit.MegaelectronVolt)] + [InlineData("en-US", "MJ", EnergyUnit.Megajoule)] + [InlineData("en-US", "MWd", EnergyUnit.MegawattDay)] + [InlineData("en-US", "MWh", EnergyUnit.MegawattHour)] + [InlineData("en-US", "µJ", EnergyUnit.Microjoule)] + [InlineData("en-US", "mJ", EnergyUnit.Millijoule)] + [InlineData("en-US", "nJ", EnergyUnit.Nanojoule)] + [InlineData("en-US", "PJ", EnergyUnit.Petajoule)] + [InlineData("en-US", "TeV", EnergyUnit.TeraelectronVolt)] + [InlineData("en-US", "TJ", EnergyUnit.Terajoule)] + [InlineData("en-US", "TWd", EnergyUnit.TerawattDay)] + [InlineData("en-US", "TWh", EnergyUnit.TerawattHour)] + [InlineData("en-US", "th (E.C.)", EnergyUnit.ThermEc)] + [InlineData("en-US", "th (imp.)", EnergyUnit.ThermImperial)] + [InlineData("en-US", "th (U.S.)", EnergyUnit.ThermUs)] + [InlineData("en-US", "Wd", EnergyUnit.WattDay)] + [InlineData("en-US", "Wh", EnergyUnit.WattHour)] + [InlineData("ru-RU", "Европейский декатерм", EnergyUnit.DecathermEc)] + [InlineData("ru-RU", "Английский декатерм", EnergyUnit.DecathermImperial)] + [InlineData("ru-RU", "Американский декатерм", EnergyUnit.DecathermUs)] + [InlineData("ru-RU", "эВ", EnergyUnit.ElectronVolt)] + [InlineData("ru-RU", "ГэВ", EnergyUnit.GigaelectronVolt)] + [InlineData("ru-RU", "ГВт/д", EnergyUnit.GigawattDay)] + [InlineData("ru-RU", "ГВт/ч", EnergyUnit.GigawattHour)] + [InlineData("ru-RU", "кэВ", EnergyUnit.KiloelectronVolt)] + [InlineData("ru-RU", "кВт/д", EnergyUnit.KilowattDay)] + [InlineData("ru-RU", "кВт/ч", EnergyUnit.KilowattHour)] + [InlineData("ru-RU", "МэВ", EnergyUnit.MegaelectronVolt)] + [InlineData("ru-RU", "МВт/д", EnergyUnit.MegawattDay)] + [InlineData("ru-RU", "МВт/ч", EnergyUnit.MegawattHour)] + [InlineData("ru-RU", "ТэВ", EnergyUnit.TeraelectronVolt)] + [InlineData("ru-RU", "ТВт/д", EnergyUnit.TerawattDay)] + [InlineData("ru-RU", "ТВт/ч", EnergyUnit.TerawattHour)] + [InlineData("ru-RU", "Европейский терм", EnergyUnit.ThermEc)] + [InlineData("ru-RU", "Английский терм", EnergyUnit.ThermImperial)] + [InlineData("ru-RU", "Американский терм", EnergyUnit.ThermUs)] + [InlineData("ru-RU", "Вт/д", EnergyUnit.WattDay)] + [InlineData("ru-RU", "Вт/ч", EnergyUnit.WattHour)] + public void TryParseUnitWithCulture(string culture, string abbreviation, EnergyUnit expectedUnit) + { + Assert.True(Energy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out EnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs index 13fa788561..a24bc97502 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs @@ -338,91 +338,62 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("cal/K", EntropyUnit.CaloriePerKelvin)] + [InlineData("J/C", EntropyUnit.JoulePerDegreeCelsius)] + [InlineData("J/K", EntropyUnit.JoulePerKelvin)] + [InlineData("kcal/K", EntropyUnit.KilocaloriePerKelvin)] + [InlineData("kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] + [InlineData("kJ/K", EntropyUnit.KilojoulePerKelvin)] + [InlineData("MJ/K", EntropyUnit.MegajoulePerKelvin)] + public void ParseUnit(string abbreviation, EntropyUnit expectedUnit) { - try - { - var parsedUnit = Entropy.ParseUnit("cal/K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EntropyUnit.CaloriePerKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Entropy.ParseUnit("J/C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EntropyUnit.JoulePerDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Entropy.ParseUnit("J/K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EntropyUnit.JoulePerKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Entropy.ParseUnit("kcal/K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EntropyUnit.KilocaloriePerKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Entropy.ParseUnit("kJ/C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EntropyUnit.KilojoulePerDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Entropy.ParseUnit("kJ/K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EntropyUnit.KilojoulePerKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Entropy.ParseUnit("MJ/K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(EntropyUnit.MegajoulePerKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + EntropyUnit parsedUnit = Entropy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "cal/K", EntropyUnit.CaloriePerKelvin)] + [InlineData("en-US", "J/C", EntropyUnit.JoulePerDegreeCelsius)] + [InlineData("en-US", "J/K", EntropyUnit.JoulePerKelvin)] + [InlineData("en-US", "kcal/K", EntropyUnit.KilocaloriePerKelvin)] + [InlineData("en-US", "kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] + [InlineData("en-US", "kJ/K", EntropyUnit.KilojoulePerKelvin)] + [InlineData("en-US", "MJ/K", EntropyUnit.MegajoulePerKelvin)] + public void ParseUnitWithCulture(string culture, string abbreviation, EntropyUnit expectedUnit) { - { - Assert.True(Entropy.TryParseUnit("cal/K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EntropyUnit.CaloriePerKelvin, parsedUnit); - } - - { - Assert.True(Entropy.TryParseUnit("J/C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EntropyUnit.JoulePerDegreeCelsius, parsedUnit); - } - - { - Assert.True(Entropy.TryParseUnit("J/K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EntropyUnit.JoulePerKelvin, parsedUnit); - } - - { - Assert.True(Entropy.TryParseUnit("kcal/K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EntropyUnit.KilocaloriePerKelvin, parsedUnit); - } - - { - Assert.True(Entropy.TryParseUnit("kJ/C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EntropyUnit.KilojoulePerDegreeCelsius, parsedUnit); - } - - { - Assert.True(Entropy.TryParseUnit("kJ/K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EntropyUnit.KilojoulePerKelvin, parsedUnit); - } + EntropyUnit parsedUnit = Entropy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Entropy.TryParseUnit("MJ/K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(EntropyUnit.MegajoulePerKelvin, parsedUnit); - } + [Theory] + [InlineData("cal/K", EntropyUnit.CaloriePerKelvin)] + [InlineData("J/C", EntropyUnit.JoulePerDegreeCelsius)] + [InlineData("J/K", EntropyUnit.JoulePerKelvin)] + [InlineData("kcal/K", EntropyUnit.KilocaloriePerKelvin)] + [InlineData("kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] + [InlineData("kJ/K", EntropyUnit.KilojoulePerKelvin)] + [InlineData("MJ/K", EntropyUnit.MegajoulePerKelvin)] + public void TryParseUnit(string abbreviation, EntropyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Entropy.TryParseUnit(abbreviation, out EntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cal/K", EntropyUnit.CaloriePerKelvin)] + [InlineData("en-US", "J/C", EntropyUnit.JoulePerDegreeCelsius)] + [InlineData("en-US", "J/K", EntropyUnit.JoulePerKelvin)] + [InlineData("en-US", "kcal/K", EntropyUnit.KilocaloriePerKelvin)] + [InlineData("en-US", "kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] + [InlineData("en-US", "kJ/K", EntropyUnit.KilojoulePerKelvin)] + [InlineData("en-US", "MJ/K", EntropyUnit.MegajoulePerKelvin)] + public void TryParseUnitWithCulture(string culture, string abbreviation, EntropyUnit expectedUnit) + { + Assert.True(Entropy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out EntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs index fa294e3025..b17de2439a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs @@ -574,223 +574,110 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = ForceChangeRate.ParseUnit("cN/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.CentinewtonPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("daN/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.DecanewtonPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("daN/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.DecanewtonPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("dN/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.DecinewtonPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("kN/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.KilonewtonPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("kN/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.KilonewtonPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("kipf/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("kip/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("k/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("kipf/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("kip/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("k/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("µN/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.MicronewtonPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("mN/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.MillinewtonPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("nN/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.NanonewtonPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("N/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.NewtonPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("N/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.NewtonPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("lbf/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.PoundForcePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForceChangeRate.ParseUnit("lbf/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceChangeRateUnit.PoundForcePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cN/s", ForceChangeRateUnit.CentinewtonPerSecond)] + [InlineData("daN/min", ForceChangeRateUnit.DecanewtonPerMinute)] + [InlineData("daN/s", ForceChangeRateUnit.DecanewtonPerSecond)] + [InlineData("dN/s", ForceChangeRateUnit.DecinewtonPerSecond)] + [InlineData("kN/min", ForceChangeRateUnit.KilonewtonPerMinute)] + [InlineData("kN/s", ForceChangeRateUnit.KilonewtonPerSecond)] + [InlineData("kipf/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("kip/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("k/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("kipf/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("kip/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("k/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("µN/s", ForceChangeRateUnit.MicronewtonPerSecond)] + [InlineData("mN/s", ForceChangeRateUnit.MillinewtonPerSecond)] + [InlineData("nN/s", ForceChangeRateUnit.NanonewtonPerSecond)] + [InlineData("N/min", ForceChangeRateUnit.NewtonPerMinute)] + [InlineData("N/s", ForceChangeRateUnit.NewtonPerSecond)] + [InlineData("lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] + [InlineData("lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] + public void ParseUnit(string abbreviation, ForceChangeRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ForceChangeRateUnit parsedUnit = ForceChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(ForceChangeRate.TryParseUnit("cN/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.CentinewtonPerSecond, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("daN/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.DecanewtonPerMinute, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("daN/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.DecanewtonPerSecond, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("dN/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.DecinewtonPerSecond, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("kN/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.KilonewtonPerMinute, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("kN/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.KilonewtonPerSecond, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("kipf/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("kip/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("k/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerMinute, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("kipf/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("kip/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("k/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.KilopoundForcePerSecond, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("µN/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.MicronewtonPerSecond, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("mN/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.MillinewtonPerSecond, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("nN/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.NanonewtonPerSecond, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("N/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.NewtonPerMinute, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("N/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.NewtonPerSecond, parsedUnit); - } - - { - Assert.True(ForceChangeRate.TryParseUnit("lbf/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.PoundForcePerMinute, parsedUnit); - } + [Theory] + [InlineData("en-US", "cN/s", ForceChangeRateUnit.CentinewtonPerSecond)] + [InlineData("en-US", "daN/min", ForceChangeRateUnit.DecanewtonPerMinute)] + [InlineData("en-US", "daN/s", ForceChangeRateUnit.DecanewtonPerSecond)] + [InlineData("en-US", "dN/s", ForceChangeRateUnit.DecinewtonPerSecond)] + [InlineData("en-US", "kN/min", ForceChangeRateUnit.KilonewtonPerMinute)] + [InlineData("en-US", "kN/s", ForceChangeRateUnit.KilonewtonPerSecond)] + [InlineData("en-US", "kipf/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "kip/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "k/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "kipf/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "kip/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "k/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "µN/s", ForceChangeRateUnit.MicronewtonPerSecond)] + [InlineData("en-US", "mN/s", ForceChangeRateUnit.MillinewtonPerSecond)] + [InlineData("en-US", "nN/s", ForceChangeRateUnit.NanonewtonPerSecond)] + [InlineData("en-US", "N/min", ForceChangeRateUnit.NewtonPerMinute)] + [InlineData("en-US", "N/s", ForceChangeRateUnit.NewtonPerSecond)] + [InlineData("en-US", "lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] + [InlineData("en-US", "lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, ForceChangeRateUnit expectedUnit) + { + ForceChangeRateUnit parsedUnit = ForceChangeRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ForceChangeRate.TryParseUnit("lbf/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceChangeRateUnit.PoundForcePerSecond, parsedUnit); - } + [Theory] + [InlineData("cN/s", ForceChangeRateUnit.CentinewtonPerSecond)] + [InlineData("daN/min", ForceChangeRateUnit.DecanewtonPerMinute)] + [InlineData("daN/s", ForceChangeRateUnit.DecanewtonPerSecond)] + [InlineData("dN/s", ForceChangeRateUnit.DecinewtonPerSecond)] + [InlineData("kN/min", ForceChangeRateUnit.KilonewtonPerMinute)] + [InlineData("kN/s", ForceChangeRateUnit.KilonewtonPerSecond)] + [InlineData("kipf/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("kip/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("k/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("kipf/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("kip/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("k/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("µN/s", ForceChangeRateUnit.MicronewtonPerSecond)] + [InlineData("mN/s", ForceChangeRateUnit.MillinewtonPerSecond)] + [InlineData("nN/s", ForceChangeRateUnit.NanonewtonPerSecond)] + [InlineData("N/min", ForceChangeRateUnit.NewtonPerMinute)] + [InlineData("N/s", ForceChangeRateUnit.NewtonPerSecond)] + [InlineData("lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] + [InlineData("lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] + public void TryParseUnit(string abbreviation, ForceChangeRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ForceChangeRate.TryParseUnit(abbreviation, out ForceChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cN/s", ForceChangeRateUnit.CentinewtonPerSecond)] + [InlineData("en-US", "daN/min", ForceChangeRateUnit.DecanewtonPerMinute)] + [InlineData("en-US", "daN/s", ForceChangeRateUnit.DecanewtonPerSecond)] + [InlineData("en-US", "dN/s", ForceChangeRateUnit.DecinewtonPerSecond)] + [InlineData("en-US", "kN/min", ForceChangeRateUnit.KilonewtonPerMinute)] + [InlineData("en-US", "kN/s", ForceChangeRateUnit.KilonewtonPerSecond)] + [InlineData("en-US", "kipf/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "kip/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "k/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "kipf/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "kip/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "k/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "µN/s", ForceChangeRateUnit.MicronewtonPerSecond)] + [InlineData("en-US", "mN/s", ForceChangeRateUnit.MillinewtonPerSecond)] + [InlineData("en-US", "nN/s", ForceChangeRateUnit.NanonewtonPerSecond)] + [InlineData("en-US", "N/min", ForceChangeRateUnit.NewtonPerMinute)] + [InlineData("en-US", "N/s", ForceChangeRateUnit.NewtonPerSecond)] + [InlineData("en-US", "lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] + [InlineData("en-US", "lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ForceChangeRateUnit expectedUnit) + { + Assert.True(ForceChangeRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ForceChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs index 836a6a1618..7f975cc294 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs @@ -1145,512 +1145,214 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = ForcePerLength.ParseUnit("cN/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("cN/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("cN/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("daN/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("daN/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("daN/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("dN/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("dN/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("dN/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("kgf/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("кгс/см", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("kgf/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("кгс/м", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("kgf/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("кгс/мм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("kN/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("kN/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("kN/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("kipf/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("kip/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("k/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("kipf/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("kip/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("k/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("MN/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.MeganewtonPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("MN/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.MeganewtonPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("MN/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.MeganewtonPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("µN/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("µN/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("µN/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("mN/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.MillinewtonPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("mN/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.MillinewtonPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("mN/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.MillinewtonPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("nN/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("nN/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("nN/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("N/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.NewtonPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("N/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.NewtonPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("N/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.NewtonPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("lbf/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.PoundForcePerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("lbf/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.PoundForcePerInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("lbf/yd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.PoundForcePerYard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("tf/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.TonneForcePerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("тс/см", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForcePerLengthUnit.TonneForcePerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("tf/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("тс/м", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("tf/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ForcePerLength.ParseUnit("тс/мм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cN/cm", ForcePerLengthUnit.CentinewtonPerCentimeter)] + [InlineData("cN/m", ForcePerLengthUnit.CentinewtonPerMeter)] + [InlineData("cN/mm", ForcePerLengthUnit.CentinewtonPerMillimeter)] + [InlineData("daN/cm", ForcePerLengthUnit.DecanewtonPerCentimeter)] + [InlineData("daN/m", ForcePerLengthUnit.DecanewtonPerMeter)] + [InlineData("daN/mm", ForcePerLengthUnit.DecanewtonPerMillimeter)] + [InlineData("dN/cm", ForcePerLengthUnit.DecinewtonPerCentimeter)] + [InlineData("dN/m", ForcePerLengthUnit.DecinewtonPerMeter)] + [InlineData("dN/mm", ForcePerLengthUnit.DecinewtonPerMillimeter)] + [InlineData("kgf/cm", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("kgf/m", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("kgf/mm", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("kN/cm", ForcePerLengthUnit.KilonewtonPerCentimeter)] + [InlineData("kN/m", ForcePerLengthUnit.KilonewtonPerMeter)] + [InlineData("kN/mm", ForcePerLengthUnit.KilonewtonPerMillimeter)] + [InlineData("kipf/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("kip/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("k/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("kipf/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("kip/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("k/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("MN/cm", ForcePerLengthUnit.MeganewtonPerCentimeter)] + [InlineData("MN/m", ForcePerLengthUnit.MeganewtonPerMeter)] + [InlineData("MN/mm", ForcePerLengthUnit.MeganewtonPerMillimeter)] + [InlineData("µN/cm", ForcePerLengthUnit.MicronewtonPerCentimeter)] + [InlineData("µN/m", ForcePerLengthUnit.MicronewtonPerMeter)] + [InlineData("µN/mm", ForcePerLengthUnit.MicronewtonPerMillimeter)] + [InlineData("mN/cm", ForcePerLengthUnit.MillinewtonPerCentimeter)] + [InlineData("mN/m", ForcePerLengthUnit.MillinewtonPerMeter)] + [InlineData("mN/mm", ForcePerLengthUnit.MillinewtonPerMillimeter)] + [InlineData("nN/cm", ForcePerLengthUnit.NanonewtonPerCentimeter)] + [InlineData("nN/m", ForcePerLengthUnit.NanonewtonPerMeter)] + [InlineData("nN/mm", ForcePerLengthUnit.NanonewtonPerMillimeter)] + [InlineData("N/cm", ForcePerLengthUnit.NewtonPerCentimeter)] + [InlineData("N/m", ForcePerLengthUnit.NewtonPerMeter)] + [InlineData("N/mm", ForcePerLengthUnit.NewtonPerMillimeter)] + [InlineData("lbf/ft", ForcePerLengthUnit.PoundForcePerFoot)] + [InlineData("lbf/in", ForcePerLengthUnit.PoundForcePerInch)] + [InlineData("lbf/yd", ForcePerLengthUnit.PoundForcePerYard)] + [InlineData("tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("tf/m", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter)] + public void ParseUnit(string abbreviation, ForcePerLengthUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ForcePerLengthUnit parsedUnit = ForcePerLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(ForcePerLength.TryParseUnit("cN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerCentimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("cN/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerMeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("cN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.CentinewtonPerMillimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("daN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerCentimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("daN/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerMeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("daN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.DecanewtonPerMillimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("dN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerCentimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("dN/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerMeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("dN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.DecinewtonPerMillimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("kgf/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerCentimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("кгс/см", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerCentimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("kgf/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("кгс/м", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("kgf/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMillimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("кгс/мм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilogramForcePerMillimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("kN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerCentimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("kN/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerMeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("kN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilonewtonPerMillimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("kipf/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("kip/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("k/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerFoot, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("kipf/in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("kip/in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("k/in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.KilopoundForcePerInch, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("µN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerCentimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("µN/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerMeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("µN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.MicronewtonPerMillimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("nN/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerCentimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("nN/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerMeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("nN/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.NanonewtonPerMillimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("N/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.NewtonPerCentimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("N/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.NewtonPerMeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("N/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.NewtonPerMillimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("lbf/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.PoundForcePerFoot, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("lbf/in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.PoundForcePerInch, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("lbf/yd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.PoundForcePerYard, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("tf/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.TonneForcePerCentimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("тс/см", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.TonneForcePerCentimeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("tf/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("тс/м", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMeter, parsedUnit); - } - - { - Assert.True(ForcePerLength.TryParseUnit("tf/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMillimeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "cN/cm", ForcePerLengthUnit.CentinewtonPerCentimeter)] + [InlineData("en-US", "cN/m", ForcePerLengthUnit.CentinewtonPerMeter)] + [InlineData("en-US", "cN/mm", ForcePerLengthUnit.CentinewtonPerMillimeter)] + [InlineData("en-US", "daN/cm", ForcePerLengthUnit.DecanewtonPerCentimeter)] + [InlineData("en-US", "daN/m", ForcePerLengthUnit.DecanewtonPerMeter)] + [InlineData("en-US", "daN/mm", ForcePerLengthUnit.DecanewtonPerMillimeter)] + [InlineData("en-US", "dN/cm", ForcePerLengthUnit.DecinewtonPerCentimeter)] + [InlineData("en-US", "dN/m", ForcePerLengthUnit.DecinewtonPerMeter)] + [InlineData("en-US", "dN/mm", ForcePerLengthUnit.DecinewtonPerMillimeter)] + [InlineData("en-US", "kgf/cm", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("en-US", "kgf/m", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("en-US", "kgf/mm", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("en-US", "kN/cm", ForcePerLengthUnit.KilonewtonPerCentimeter)] + [InlineData("en-US", "kN/m", ForcePerLengthUnit.KilonewtonPerMeter)] + [InlineData("en-US", "kN/mm", ForcePerLengthUnit.KilonewtonPerMillimeter)] + [InlineData("en-US", "kipf/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "kip/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "k/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "kipf/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "kip/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "k/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "MN/cm", ForcePerLengthUnit.MeganewtonPerCentimeter)] + [InlineData("en-US", "MN/m", ForcePerLengthUnit.MeganewtonPerMeter)] + [InlineData("en-US", "MN/mm", ForcePerLengthUnit.MeganewtonPerMillimeter)] + [InlineData("en-US", "µN/cm", ForcePerLengthUnit.MicronewtonPerCentimeter)] + [InlineData("en-US", "µN/m", ForcePerLengthUnit.MicronewtonPerMeter)] + [InlineData("en-US", "µN/mm", ForcePerLengthUnit.MicronewtonPerMillimeter)] + [InlineData("en-US", "mN/cm", ForcePerLengthUnit.MillinewtonPerCentimeter)] + [InlineData("en-US", "mN/m", ForcePerLengthUnit.MillinewtonPerMeter)] + [InlineData("en-US", "mN/mm", ForcePerLengthUnit.MillinewtonPerMillimeter)] + [InlineData("en-US", "nN/cm", ForcePerLengthUnit.NanonewtonPerCentimeter)] + [InlineData("en-US", "nN/m", ForcePerLengthUnit.NanonewtonPerMeter)] + [InlineData("en-US", "nN/mm", ForcePerLengthUnit.NanonewtonPerMillimeter)] + [InlineData("en-US", "N/cm", ForcePerLengthUnit.NewtonPerCentimeter)] + [InlineData("en-US", "N/m", ForcePerLengthUnit.NewtonPerMeter)] + [InlineData("en-US", "N/mm", ForcePerLengthUnit.NewtonPerMillimeter)] + [InlineData("en-US", "lbf/ft", ForcePerLengthUnit.PoundForcePerFoot)] + [InlineData("en-US", "lbf/in", ForcePerLengthUnit.PoundForcePerInch)] + [InlineData("en-US", "lbf/yd", ForcePerLengthUnit.PoundForcePerYard)] + [InlineData("en-US", "tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("en-US", "tf/m", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("en-US", "tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter)] + [InlineData("ru-RU", "кгс/см", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("ru-RU", "кгс/м", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("ru-RU", "кгс/мм", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("ru-RU", "тс/см", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("ru-RU", "тс/м", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("ru-RU", "тс/мм", ForcePerLengthUnit.TonneForcePerMillimeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, ForcePerLengthUnit expectedUnit) + { + ForcePerLengthUnit parsedUnit = ForcePerLength.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ForcePerLength.TryParseUnit("тс/мм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForcePerLengthUnit.TonneForcePerMillimeter, parsedUnit); - } + [Theory] + [InlineData("cN/cm", ForcePerLengthUnit.CentinewtonPerCentimeter)] + [InlineData("cN/m", ForcePerLengthUnit.CentinewtonPerMeter)] + [InlineData("cN/mm", ForcePerLengthUnit.CentinewtonPerMillimeter)] + [InlineData("daN/cm", ForcePerLengthUnit.DecanewtonPerCentimeter)] + [InlineData("daN/m", ForcePerLengthUnit.DecanewtonPerMeter)] + [InlineData("daN/mm", ForcePerLengthUnit.DecanewtonPerMillimeter)] + [InlineData("dN/cm", ForcePerLengthUnit.DecinewtonPerCentimeter)] + [InlineData("dN/m", ForcePerLengthUnit.DecinewtonPerMeter)] + [InlineData("dN/mm", ForcePerLengthUnit.DecinewtonPerMillimeter)] + [InlineData("kgf/cm", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("kgf/m", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("kgf/mm", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("kN/cm", ForcePerLengthUnit.KilonewtonPerCentimeter)] + [InlineData("kN/m", ForcePerLengthUnit.KilonewtonPerMeter)] + [InlineData("kN/mm", ForcePerLengthUnit.KilonewtonPerMillimeter)] + [InlineData("kipf/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("kip/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("k/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("kipf/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("kip/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("k/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("MN/cm", ForcePerLengthUnit.MeganewtonPerCentimeter)] + [InlineData("MN/m", ForcePerLengthUnit.MeganewtonPerMeter)] + [InlineData("MN/mm", ForcePerLengthUnit.MeganewtonPerMillimeter)] + [InlineData("µN/cm", ForcePerLengthUnit.MicronewtonPerCentimeter)] + [InlineData("µN/m", ForcePerLengthUnit.MicronewtonPerMeter)] + [InlineData("µN/mm", ForcePerLengthUnit.MicronewtonPerMillimeter)] + [InlineData("mN/cm", ForcePerLengthUnit.MillinewtonPerCentimeter)] + [InlineData("mN/m", ForcePerLengthUnit.MillinewtonPerMeter)] + [InlineData("mN/mm", ForcePerLengthUnit.MillinewtonPerMillimeter)] + [InlineData("nN/cm", ForcePerLengthUnit.NanonewtonPerCentimeter)] + [InlineData("nN/m", ForcePerLengthUnit.NanonewtonPerMeter)] + [InlineData("nN/mm", ForcePerLengthUnit.NanonewtonPerMillimeter)] + [InlineData("N/cm", ForcePerLengthUnit.NewtonPerCentimeter)] + [InlineData("N/m", ForcePerLengthUnit.NewtonPerMeter)] + [InlineData("N/mm", ForcePerLengthUnit.NewtonPerMillimeter)] + [InlineData("lbf/ft", ForcePerLengthUnit.PoundForcePerFoot)] + [InlineData("lbf/in", ForcePerLengthUnit.PoundForcePerInch)] + [InlineData("lbf/yd", ForcePerLengthUnit.PoundForcePerYard)] + [InlineData("tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("tf/m", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter)] + public void TryParseUnit(string abbreviation, ForcePerLengthUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ForcePerLength.TryParseUnit(abbreviation, out ForcePerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cN/cm", ForcePerLengthUnit.CentinewtonPerCentimeter)] + [InlineData("en-US", "cN/m", ForcePerLengthUnit.CentinewtonPerMeter)] + [InlineData("en-US", "cN/mm", ForcePerLengthUnit.CentinewtonPerMillimeter)] + [InlineData("en-US", "daN/cm", ForcePerLengthUnit.DecanewtonPerCentimeter)] + [InlineData("en-US", "daN/m", ForcePerLengthUnit.DecanewtonPerMeter)] + [InlineData("en-US", "daN/mm", ForcePerLengthUnit.DecanewtonPerMillimeter)] + [InlineData("en-US", "dN/cm", ForcePerLengthUnit.DecinewtonPerCentimeter)] + [InlineData("en-US", "dN/m", ForcePerLengthUnit.DecinewtonPerMeter)] + [InlineData("en-US", "dN/mm", ForcePerLengthUnit.DecinewtonPerMillimeter)] + [InlineData("en-US", "kgf/cm", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("en-US", "kgf/m", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("en-US", "kgf/mm", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("en-US", "kN/cm", ForcePerLengthUnit.KilonewtonPerCentimeter)] + [InlineData("en-US", "kN/m", ForcePerLengthUnit.KilonewtonPerMeter)] + [InlineData("en-US", "kN/mm", ForcePerLengthUnit.KilonewtonPerMillimeter)] + [InlineData("en-US", "kipf/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "kip/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "k/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "kipf/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "kip/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "k/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "MN/cm", ForcePerLengthUnit.MeganewtonPerCentimeter)] + [InlineData("en-US", "MN/m", ForcePerLengthUnit.MeganewtonPerMeter)] + [InlineData("en-US", "MN/mm", ForcePerLengthUnit.MeganewtonPerMillimeter)] + [InlineData("en-US", "µN/cm", ForcePerLengthUnit.MicronewtonPerCentimeter)] + [InlineData("en-US", "µN/m", ForcePerLengthUnit.MicronewtonPerMeter)] + [InlineData("en-US", "µN/mm", ForcePerLengthUnit.MicronewtonPerMillimeter)] + [InlineData("en-US", "mN/cm", ForcePerLengthUnit.MillinewtonPerCentimeter)] + [InlineData("en-US", "mN/m", ForcePerLengthUnit.MillinewtonPerMeter)] + [InlineData("en-US", "mN/mm", ForcePerLengthUnit.MillinewtonPerMillimeter)] + [InlineData("en-US", "nN/cm", ForcePerLengthUnit.NanonewtonPerCentimeter)] + [InlineData("en-US", "nN/m", ForcePerLengthUnit.NanonewtonPerMeter)] + [InlineData("en-US", "nN/mm", ForcePerLengthUnit.NanonewtonPerMillimeter)] + [InlineData("en-US", "N/cm", ForcePerLengthUnit.NewtonPerCentimeter)] + [InlineData("en-US", "N/m", ForcePerLengthUnit.NewtonPerMeter)] + [InlineData("en-US", "N/mm", ForcePerLengthUnit.NewtonPerMillimeter)] + [InlineData("en-US", "lbf/ft", ForcePerLengthUnit.PoundForcePerFoot)] + [InlineData("en-US", "lbf/in", ForcePerLengthUnit.PoundForcePerInch)] + [InlineData("en-US", "lbf/yd", ForcePerLengthUnit.PoundForcePerYard)] + [InlineData("en-US", "tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("en-US", "tf/m", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("en-US", "tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter)] + [InlineData("ru-RU", "кгс/см", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("ru-RU", "кгс/м", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("ru-RU", "кгс/мм", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("ru-RU", "тс/см", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("ru-RU", "тс/м", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("ru-RU", "тс/мм", ForcePerLengthUnit.TonneForcePerMillimeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ForcePerLengthUnit expectedUnit) + { + Assert.True(ForcePerLength.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ForcePerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs index 70caaca656..8a8fa1d653 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs @@ -746,369 +746,154 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Force.ParseUnit("daN", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.Decanewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("даН", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.Decanewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("dyn", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.Dyn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("дин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.Dyn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("kgf", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.KilogramForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("кгс", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.KilogramForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("kN", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.Kilonewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("кН", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.Kilonewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("kp", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.KiloPond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("кгс", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.KiloPond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("kipf", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("kip", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("k", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("кипф", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("койка", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("К", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("MN", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.Meganewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("МН", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.Meganewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("µN", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.Micronewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("мкН", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.Micronewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("mN", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.Millinewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("мН", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.Millinewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("N", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.Newton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("Н", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.Newton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("ozf", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.OunceForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("pdl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.Poundal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("паундаль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.Poundal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("lbf", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.PoundForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("фунт-сила", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.PoundForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("tf (short)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.ShortTonForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("t (US)f", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.ShortTonForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("short tons-force", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.ShortTonForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("tf", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.TonneForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("Ton", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ForceUnit.TonneForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Force.ParseUnit("тс", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(ForceUnit.TonneForce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + [Theory] + [InlineData("daN", ForceUnit.Decanewton)] + [InlineData("dyn", ForceUnit.Dyn)] + [InlineData("kgf", ForceUnit.KilogramForce)] + [InlineData("kN", ForceUnit.Kilonewton)] + [InlineData("kp", ForceUnit.KiloPond)] + [InlineData("kipf", ForceUnit.KilopoundForce)] + [InlineData("kip", ForceUnit.KilopoundForce)] + [InlineData("k", ForceUnit.KilopoundForce)] + [InlineData("MN", ForceUnit.Meganewton)] + [InlineData("µN", ForceUnit.Micronewton)] + [InlineData("mN", ForceUnit.Millinewton)] + [InlineData("N", ForceUnit.Newton)] + [InlineData("ozf", ForceUnit.OunceForce)] + [InlineData("pdl", ForceUnit.Poundal)] + [InlineData("lbf", ForceUnit.PoundForce)] + [InlineData("tf (short)", ForceUnit.ShortTonForce)] + [InlineData("t (US)f", ForceUnit.ShortTonForce)] + [InlineData("short tons-force", ForceUnit.ShortTonForce)] + [InlineData("tf", ForceUnit.TonneForce)] + [InlineData("Ton", ForceUnit.TonneForce)] + public void ParseUnit(string abbreviation, ForceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ForceUnit parsedUnit = Force.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "daN", ForceUnit.Decanewton)] + [InlineData("en-US", "dyn", ForceUnit.Dyn)] + [InlineData("en-US", "kgf", ForceUnit.KilogramForce)] + [InlineData("en-US", "kN", ForceUnit.Kilonewton)] + [InlineData("en-US", "kp", ForceUnit.KiloPond)] + [InlineData("en-US", "kipf", ForceUnit.KilopoundForce)] + [InlineData("en-US", "kip", ForceUnit.KilopoundForce)] + [InlineData("en-US", "k", ForceUnit.KilopoundForce)] + [InlineData("en-US", "MN", ForceUnit.Meganewton)] + [InlineData("en-US", "µN", ForceUnit.Micronewton)] + [InlineData("en-US", "mN", ForceUnit.Millinewton)] + [InlineData("en-US", "N", ForceUnit.Newton)] + [InlineData("en-US", "ozf", ForceUnit.OunceForce)] + [InlineData("en-US", "pdl", ForceUnit.Poundal)] + [InlineData("en-US", "lbf", ForceUnit.PoundForce)] + [InlineData("en-US", "tf (short)", ForceUnit.ShortTonForce)] + [InlineData("en-US", "t (US)f", ForceUnit.ShortTonForce)] + [InlineData("en-US", "short tons-force", ForceUnit.ShortTonForce)] + [InlineData("en-US", "tf", ForceUnit.TonneForce)] + [InlineData("en-US", "Ton", ForceUnit.TonneForce)] + [InlineData("ru-RU", "даН", ForceUnit.Decanewton)] + [InlineData("ru-RU", "дин", ForceUnit.Dyn)] + [InlineData("ru-RU", "кН", ForceUnit.Kilonewton)] + [InlineData("ru-RU", "кипф", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "койка", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "К", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "МН", ForceUnit.Meganewton)] + [InlineData("ru-RU", "мкН", ForceUnit.Micronewton)] + [InlineData("ru-RU", "мН", ForceUnit.Millinewton)] + [InlineData("ru-RU", "Н", ForceUnit.Newton)] + [InlineData("ru-RU", "паундаль", ForceUnit.Poundal)] + [InlineData("ru-RU", "фунт-сила", ForceUnit.PoundForce)] + [InlineData("ru-RU", "тс", ForceUnit.TonneForce)] + public void ParseUnitWithCulture(string culture, string abbreviation, ForceUnit expectedUnit) + { + ForceUnit parsedUnit = Force.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("ru-RU", "кгс")] // [KilogramForce, KiloPond] + public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) { - { - Assert.True(Force.TryParseUnit("daN", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.Decanewton, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("даН", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForceUnit.Decanewton, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("dyn", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.Dyn, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("дин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForceUnit.Dyn, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("kgf", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.KilogramForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("kN", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.Kilonewton, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("кН", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForceUnit.Kilonewton, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("kp", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.KiloPond, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("kipf", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("kip", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("k", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("кипф", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("койка", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("К", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForceUnit.KilopoundForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("µN", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.Micronewton, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("мкН", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForceUnit.Micronewton, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("N", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.Newton, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("Н", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForceUnit.Newton, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("ozf", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.OunceForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("pdl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.Poundal, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("паундаль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForceUnit.Poundal, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("lbf", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.PoundForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("фунт-сила", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForceUnit.PoundForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("tf (short)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.ShortTonForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("t (US)f", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.ShortTonForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("short tons-force", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.ShortTonForce, parsedUnit); - } - - { - Assert.True(Force.TryParseUnit("tf", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.TonneForce, parsedUnit); - } + Assert.Throws(() => Force.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture))); + } - { - Assert.True(Force.TryParseUnit("Ton", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ForceUnit.TonneForce, parsedUnit); - } + [Theory] + [InlineData("daN", ForceUnit.Decanewton)] + [InlineData("dyn", ForceUnit.Dyn)] + [InlineData("kgf", ForceUnit.KilogramForce)] + [InlineData("kN", ForceUnit.Kilonewton)] + [InlineData("kp", ForceUnit.KiloPond)] + [InlineData("kipf", ForceUnit.KilopoundForce)] + [InlineData("kip", ForceUnit.KilopoundForce)] + [InlineData("k", ForceUnit.KilopoundForce)] + [InlineData("MN", ForceUnit.Meganewton)] + [InlineData("µN", ForceUnit.Micronewton)] + [InlineData("mN", ForceUnit.Millinewton)] + [InlineData("N", ForceUnit.Newton)] + [InlineData("ozf", ForceUnit.OunceForce)] + [InlineData("pdl", ForceUnit.Poundal)] + [InlineData("lbf", ForceUnit.PoundForce)] + [InlineData("tf (short)", ForceUnit.ShortTonForce)] + [InlineData("t (US)f", ForceUnit.ShortTonForce)] + [InlineData("short tons-force", ForceUnit.ShortTonForce)] + [InlineData("tf", ForceUnit.TonneForce)] + [InlineData("Ton", ForceUnit.TonneForce)] + public void TryParseUnit(string abbreviation, ForceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Force.TryParseUnit(abbreviation, out ForceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Force.TryParseUnit("тс", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(ForceUnit.TonneForce, parsedUnit); - } + [Theory] + [InlineData("en-US", "daN", ForceUnit.Decanewton)] + [InlineData("en-US", "dyn", ForceUnit.Dyn)] + [InlineData("en-US", "kgf", ForceUnit.KilogramForce)] + [InlineData("en-US", "kN", ForceUnit.Kilonewton)] + [InlineData("en-US", "kp", ForceUnit.KiloPond)] + [InlineData("en-US", "kipf", ForceUnit.KilopoundForce)] + [InlineData("en-US", "kip", ForceUnit.KilopoundForce)] + [InlineData("en-US", "k", ForceUnit.KilopoundForce)] + [InlineData("en-US", "MN", ForceUnit.Meganewton)] + [InlineData("en-US", "µN", ForceUnit.Micronewton)] + [InlineData("en-US", "mN", ForceUnit.Millinewton)] + [InlineData("en-US", "N", ForceUnit.Newton)] + [InlineData("en-US", "ozf", ForceUnit.OunceForce)] + [InlineData("en-US", "pdl", ForceUnit.Poundal)] + [InlineData("en-US", "lbf", ForceUnit.PoundForce)] + [InlineData("en-US", "tf (short)", ForceUnit.ShortTonForce)] + [InlineData("en-US", "t (US)f", ForceUnit.ShortTonForce)] + [InlineData("en-US", "short tons-force", ForceUnit.ShortTonForce)] + [InlineData("en-US", "tf", ForceUnit.TonneForce)] + [InlineData("en-US", "Ton", ForceUnit.TonneForce)] + [InlineData("ru-RU", "даН", ForceUnit.Decanewton)] + [InlineData("ru-RU", "дин", ForceUnit.Dyn)] + [InlineData("ru-RU", "кН", ForceUnit.Kilonewton)] + [InlineData("ru-RU", "кипф", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "койка", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "К", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "МН", ForceUnit.Meganewton)] + [InlineData("ru-RU", "мкН", ForceUnit.Micronewton)] + [InlineData("ru-RU", "мН", ForceUnit.Millinewton)] + [InlineData("ru-RU", "Н", ForceUnit.Newton)] + [InlineData("ru-RU", "паундаль", ForceUnit.Poundal)] + [InlineData("ru-RU", "фунт-сила", ForceUnit.PoundForce)] + [InlineData("ru-RU", "тс", ForceUnit.TonneForce)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ForceUnit expectedUnit) + { + Assert.True(Force.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ForceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("ru-RU", "кгс")] // [KilogramForce, KiloPond] + public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) + { + Assert.False(Force.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out _)); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs index afafae555f..491d123e65 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs @@ -569,236 +569,104 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Frequency.ParseUnit("bpm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.BeatPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("B Units", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.BUnit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("cph", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.CyclePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("cpm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.CyclePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("GHz", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.Gigahertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("ГГц", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(FrequencyUnit.Gigahertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("Hz", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.Hertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("Гц", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(FrequencyUnit.Hertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("kHz", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.Kilohertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("кГц", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(FrequencyUnit.Kilohertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("MHz", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.Megahertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("МГц", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(FrequencyUnit.Megahertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("µHz", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.Microhertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("мкГц", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(FrequencyUnit.Microhertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("mHz", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.Millihertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("мГц", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(FrequencyUnit.Millihertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("s⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.PerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("с⁻¹", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(FrequencyUnit.PerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("rad/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.RadianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("рад/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(FrequencyUnit.RadianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("THz", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FrequencyUnit.Terahertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Frequency.ParseUnit("ТГц", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(FrequencyUnit.Terahertz, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("bpm", FrequencyUnit.BeatPerMinute)] + [InlineData("B Units", FrequencyUnit.BUnit)] + [InlineData("cph", FrequencyUnit.CyclePerHour)] + [InlineData("cpm", FrequencyUnit.CyclePerMinute)] + [InlineData("GHz", FrequencyUnit.Gigahertz)] + [InlineData("Hz", FrequencyUnit.Hertz)] + [InlineData("kHz", FrequencyUnit.Kilohertz)] + [InlineData("MHz", FrequencyUnit.Megahertz)] + [InlineData("µHz", FrequencyUnit.Microhertz)] + [InlineData("mHz", FrequencyUnit.Millihertz)] + [InlineData("s⁻¹", FrequencyUnit.PerSecond)] + [InlineData("rad/s", FrequencyUnit.RadianPerSecond)] + [InlineData("THz", FrequencyUnit.Terahertz)] + public void ParseUnit(string abbreviation, FrequencyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + FrequencyUnit parsedUnit = Frequency.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Frequency.TryParseUnit("bpm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.BeatPerMinute, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("B Units", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.BUnit, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("cph", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.CyclePerHour, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("cpm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.CyclePerMinute, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("GHz", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.Gigahertz, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("ГГц", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.Gigahertz, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("Hz", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.Hertz, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("Гц", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.Hertz, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("kHz", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.Kilohertz, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("кГц", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.Kilohertz, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("µHz", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.Microhertz, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("мкГц", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.Microhertz, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("s⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.PerSecond, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("с⁻¹", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.PerSecond, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("rad/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.RadianPerSecond, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("рад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.RadianPerSecond, parsedUnit); - } - - { - Assert.True(Frequency.TryParseUnit("THz", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.Terahertz, parsedUnit); - } + [Theory] + [InlineData("en-US", "bpm", FrequencyUnit.BeatPerMinute)] + [InlineData("en-US", "B Units", FrequencyUnit.BUnit)] + [InlineData("en-US", "cph", FrequencyUnit.CyclePerHour)] + [InlineData("en-US", "cpm", FrequencyUnit.CyclePerMinute)] + [InlineData("en-US", "GHz", FrequencyUnit.Gigahertz)] + [InlineData("en-US", "Hz", FrequencyUnit.Hertz)] + [InlineData("en-US", "kHz", FrequencyUnit.Kilohertz)] + [InlineData("en-US", "MHz", FrequencyUnit.Megahertz)] + [InlineData("en-US", "µHz", FrequencyUnit.Microhertz)] + [InlineData("en-US", "mHz", FrequencyUnit.Millihertz)] + [InlineData("en-US", "s⁻¹", FrequencyUnit.PerSecond)] + [InlineData("en-US", "rad/s", FrequencyUnit.RadianPerSecond)] + [InlineData("en-US", "THz", FrequencyUnit.Terahertz)] + [InlineData("ru-RU", "ГГц", FrequencyUnit.Gigahertz)] + [InlineData("ru-RU", "Гц", FrequencyUnit.Hertz)] + [InlineData("ru-RU", "кГц", FrequencyUnit.Kilohertz)] + [InlineData("ru-RU", "МГц", FrequencyUnit.Megahertz)] + [InlineData("ru-RU", "мкГц", FrequencyUnit.Microhertz)] + [InlineData("ru-RU", "мГц", FrequencyUnit.Millihertz)] + [InlineData("ru-RU", "с⁻¹", FrequencyUnit.PerSecond)] + [InlineData("ru-RU", "рад/с", FrequencyUnit.RadianPerSecond)] + [InlineData("ru-RU", "ТГц", FrequencyUnit.Terahertz)] + public void ParseUnitWithCulture(string culture, string abbreviation, FrequencyUnit expectedUnit) + { + FrequencyUnit parsedUnit = Frequency.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Frequency.TryParseUnit("ТГц", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(FrequencyUnit.Terahertz, parsedUnit); - } + [Theory] + [InlineData("bpm", FrequencyUnit.BeatPerMinute)] + [InlineData("B Units", FrequencyUnit.BUnit)] + [InlineData("cph", FrequencyUnit.CyclePerHour)] + [InlineData("cpm", FrequencyUnit.CyclePerMinute)] + [InlineData("GHz", FrequencyUnit.Gigahertz)] + [InlineData("Hz", FrequencyUnit.Hertz)] + [InlineData("kHz", FrequencyUnit.Kilohertz)] + [InlineData("MHz", FrequencyUnit.Megahertz)] + [InlineData("µHz", FrequencyUnit.Microhertz)] + [InlineData("mHz", FrequencyUnit.Millihertz)] + [InlineData("s⁻¹", FrequencyUnit.PerSecond)] + [InlineData("rad/s", FrequencyUnit.RadianPerSecond)] + [InlineData("THz", FrequencyUnit.Terahertz)] + public void TryParseUnit(string abbreviation, FrequencyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Frequency.TryParseUnit(abbreviation, out FrequencyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "bpm", FrequencyUnit.BeatPerMinute)] + [InlineData("en-US", "B Units", FrequencyUnit.BUnit)] + [InlineData("en-US", "cph", FrequencyUnit.CyclePerHour)] + [InlineData("en-US", "cpm", FrequencyUnit.CyclePerMinute)] + [InlineData("en-US", "GHz", FrequencyUnit.Gigahertz)] + [InlineData("en-US", "Hz", FrequencyUnit.Hertz)] + [InlineData("en-US", "kHz", FrequencyUnit.Kilohertz)] + [InlineData("en-US", "MHz", FrequencyUnit.Megahertz)] + [InlineData("en-US", "µHz", FrequencyUnit.Microhertz)] + [InlineData("en-US", "mHz", FrequencyUnit.Millihertz)] + [InlineData("en-US", "s⁻¹", FrequencyUnit.PerSecond)] + [InlineData("en-US", "rad/s", FrequencyUnit.RadianPerSecond)] + [InlineData("en-US", "THz", FrequencyUnit.Terahertz)] + [InlineData("ru-RU", "ГГц", FrequencyUnit.Gigahertz)] + [InlineData("ru-RU", "Гц", FrequencyUnit.Hertz)] + [InlineData("ru-RU", "кГц", FrequencyUnit.Kilohertz)] + [InlineData("ru-RU", "МГц", FrequencyUnit.Megahertz)] + [InlineData("ru-RU", "мкГц", FrequencyUnit.Microhertz)] + [InlineData("ru-RU", "мГц", FrequencyUnit.Millihertz)] + [InlineData("ru-RU", "с⁻¹", FrequencyUnit.PerSecond)] + [InlineData("ru-RU", "рад/с", FrequencyUnit.RadianPerSecond)] + [InlineData("ru-RU", "ТГц", FrequencyUnit.Terahertz)] + public void TryParseUnitWithCulture(string culture, string abbreviation, FrequencyUnit expectedUnit) + { + Assert.True(Frequency.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out FrequencyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs index 66725281c5..2d782f33b6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs @@ -269,58 +269,50 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("km/l", FuelEfficiencyUnit.KilometerPerLiter)] + [InlineData("l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] + [InlineData("mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] + [InlineData("mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] + public void ParseUnit(string abbreviation, FuelEfficiencyUnit expectedUnit) { - try - { - var parsedUnit = FuelEfficiency.ParseUnit("km/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FuelEfficiencyUnit.KilometerPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = FuelEfficiency.ParseUnit("l/100km", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FuelEfficiencyUnit.LiterPer100Kilometers, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = FuelEfficiency.ParseUnit("mpg (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FuelEfficiencyUnit.MilePerUkGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = FuelEfficiency.ParseUnit("mpg (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(FuelEfficiencyUnit.MilePerUsGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + FuelEfficiencyUnit parsedUnit = FuelEfficiency.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "km/l", FuelEfficiencyUnit.KilometerPerLiter)] + [InlineData("en-US", "l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] + [InlineData("en-US", "mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] + [InlineData("en-US", "mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] + public void ParseUnitWithCulture(string culture, string abbreviation, FuelEfficiencyUnit expectedUnit) { - { - Assert.True(FuelEfficiency.TryParseUnit("km/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FuelEfficiencyUnit.KilometerPerLiter, parsedUnit); - } - - { - Assert.True(FuelEfficiency.TryParseUnit("l/100km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FuelEfficiencyUnit.LiterPer100Kilometers, parsedUnit); - } - - { - Assert.True(FuelEfficiency.TryParseUnit("mpg (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FuelEfficiencyUnit.MilePerUkGallon, parsedUnit); - } + FuelEfficiencyUnit parsedUnit = FuelEfficiency.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(FuelEfficiency.TryParseUnit("mpg (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(FuelEfficiencyUnit.MilePerUsGallon, parsedUnit); - } + [Theory] + [InlineData("km/l", FuelEfficiencyUnit.KilometerPerLiter)] + [InlineData("l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] + [InlineData("mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] + [InlineData("mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] + public void TryParseUnit(string abbreviation, FuelEfficiencyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(FuelEfficiency.TryParseUnit(abbreviation, out FuelEfficiencyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "km/l", FuelEfficiencyUnit.KilometerPerLiter)] + [InlineData("en-US", "l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] + [InlineData("en-US", "mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] + [InlineData("en-US", "mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] + public void TryParseUnitWithCulture(string culture, string abbreviation, FuelEfficiencyUnit expectedUnit) + { + Assert.True(FuelEfficiency.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out FuelEfficiencyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs index 42dfbea53f..8271206842 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs @@ -604,223 +604,110 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = HeatFlux.ParseUnit("BTU/(h·ft²)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.BtuPerHourSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("BTU/(min·ft²)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.BtuPerMinuteSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("BTU/(s·ft²)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.BtuPerSecondSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("BTU/(s·in²)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.BtuPerSecondSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("cal/(s·cm²)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.CaloriePerSecondSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("cW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.CentiwattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("dW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.DeciwattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("kcal/(h·m²)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.KilocaloriePerHourSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("kcal/(s·cm²)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.KilocaloriePerSecondSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("kW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.KilowattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("µW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.MicrowattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("mW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.MilliwattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("nW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.NanowattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("lbf/(ft·s)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.PoundForcePerFootSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("lb/s³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.PoundPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("lbm/s³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.PoundPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("W/ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.WattPerSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("W/in²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.WattPerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatFlux.ParseUnit("W/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatFluxUnit.WattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("BTU/(h·ft²)", HeatFluxUnit.BtuPerHourSquareFoot)] + [InlineData("BTU/(min·ft²)", HeatFluxUnit.BtuPerMinuteSquareFoot)] + [InlineData("BTU/(s·ft²)", HeatFluxUnit.BtuPerSecondSquareFoot)] + [InlineData("BTU/(s·in²)", HeatFluxUnit.BtuPerSecondSquareInch)] + [InlineData("cal/(s·cm²)", HeatFluxUnit.CaloriePerSecondSquareCentimeter)] + [InlineData("cW/m²", HeatFluxUnit.CentiwattPerSquareMeter)] + [InlineData("dW/m²", HeatFluxUnit.DeciwattPerSquareMeter)] + [InlineData("kcal/(h·m²)", HeatFluxUnit.KilocaloriePerHourSquareMeter)] + [InlineData("kcal/(s·cm²)", HeatFluxUnit.KilocaloriePerSecondSquareCentimeter)] + [InlineData("kW/m²", HeatFluxUnit.KilowattPerSquareMeter)] + [InlineData("µW/m²", HeatFluxUnit.MicrowattPerSquareMeter)] + [InlineData("mW/m²", HeatFluxUnit.MilliwattPerSquareMeter)] + [InlineData("nW/m²", HeatFluxUnit.NanowattPerSquareMeter)] + [InlineData("lbf/(ft·s)", HeatFluxUnit.PoundForcePerFootSecond)] + [InlineData("lb/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("lbm/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("W/ft²", HeatFluxUnit.WattPerSquareFoot)] + [InlineData("W/in²", HeatFluxUnit.WattPerSquareInch)] + [InlineData("W/m²", HeatFluxUnit.WattPerSquareMeter)] + public void ParseUnit(string abbreviation, HeatFluxUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + HeatFluxUnit parsedUnit = HeatFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(HeatFlux.TryParseUnit("BTU/(h·ft²)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.BtuPerHourSquareFoot, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("BTU/(min·ft²)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.BtuPerMinuteSquareFoot, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("BTU/(s·ft²)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.BtuPerSecondSquareFoot, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("BTU/(s·in²)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.BtuPerSecondSquareInch, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("cal/(s·cm²)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.CaloriePerSecondSquareCentimeter, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("cW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.CentiwattPerSquareMeter, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("dW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.DeciwattPerSquareMeter, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("kcal/(h·m²)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.KilocaloriePerHourSquareMeter, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("kcal/(s·cm²)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.KilocaloriePerSecondSquareCentimeter, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("kW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.KilowattPerSquareMeter, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("µW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.MicrowattPerSquareMeter, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("mW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.MilliwattPerSquareMeter, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("nW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.NanowattPerSquareMeter, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("lbf/(ft·s)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.PoundForcePerFootSecond, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("lb/s³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.PoundPerSecondCubed, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("lbm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.PoundPerSecondCubed, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("W/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.WattPerSquareFoot, parsedUnit); - } - - { - Assert.True(HeatFlux.TryParseUnit("W/in²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.WattPerSquareInch, parsedUnit); - } + [Theory] + [InlineData("en-US", "BTU/(h·ft²)", HeatFluxUnit.BtuPerHourSquareFoot)] + [InlineData("en-US", "BTU/(min·ft²)", HeatFluxUnit.BtuPerMinuteSquareFoot)] + [InlineData("en-US", "BTU/(s·ft²)", HeatFluxUnit.BtuPerSecondSquareFoot)] + [InlineData("en-US", "BTU/(s·in²)", HeatFluxUnit.BtuPerSecondSquareInch)] + [InlineData("en-US", "cal/(s·cm²)", HeatFluxUnit.CaloriePerSecondSquareCentimeter)] + [InlineData("en-US", "cW/m²", HeatFluxUnit.CentiwattPerSquareMeter)] + [InlineData("en-US", "dW/m²", HeatFluxUnit.DeciwattPerSquareMeter)] + [InlineData("en-US", "kcal/(h·m²)", HeatFluxUnit.KilocaloriePerHourSquareMeter)] + [InlineData("en-US", "kcal/(s·cm²)", HeatFluxUnit.KilocaloriePerSecondSquareCentimeter)] + [InlineData("en-US", "kW/m²", HeatFluxUnit.KilowattPerSquareMeter)] + [InlineData("en-US", "µW/m²", HeatFluxUnit.MicrowattPerSquareMeter)] + [InlineData("en-US", "mW/m²", HeatFluxUnit.MilliwattPerSquareMeter)] + [InlineData("en-US", "nW/m²", HeatFluxUnit.NanowattPerSquareMeter)] + [InlineData("en-US", "lbf/(ft·s)", HeatFluxUnit.PoundForcePerFootSecond)] + [InlineData("en-US", "lb/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("en-US", "lbm/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("en-US", "W/ft²", HeatFluxUnit.WattPerSquareFoot)] + [InlineData("en-US", "W/in²", HeatFluxUnit.WattPerSquareInch)] + [InlineData("en-US", "W/m²", HeatFluxUnit.WattPerSquareMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, HeatFluxUnit expectedUnit) + { + HeatFluxUnit parsedUnit = HeatFlux.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(HeatFlux.TryParseUnit("W/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatFluxUnit.WattPerSquareMeter, parsedUnit); - } + [Theory] + [InlineData("BTU/(h·ft²)", HeatFluxUnit.BtuPerHourSquareFoot)] + [InlineData("BTU/(min·ft²)", HeatFluxUnit.BtuPerMinuteSquareFoot)] + [InlineData("BTU/(s·ft²)", HeatFluxUnit.BtuPerSecondSquareFoot)] + [InlineData("BTU/(s·in²)", HeatFluxUnit.BtuPerSecondSquareInch)] + [InlineData("cal/(s·cm²)", HeatFluxUnit.CaloriePerSecondSquareCentimeter)] + [InlineData("cW/m²", HeatFluxUnit.CentiwattPerSquareMeter)] + [InlineData("dW/m²", HeatFluxUnit.DeciwattPerSquareMeter)] + [InlineData("kcal/(h·m²)", HeatFluxUnit.KilocaloriePerHourSquareMeter)] + [InlineData("kcal/(s·cm²)", HeatFluxUnit.KilocaloriePerSecondSquareCentimeter)] + [InlineData("kW/m²", HeatFluxUnit.KilowattPerSquareMeter)] + [InlineData("µW/m²", HeatFluxUnit.MicrowattPerSquareMeter)] + [InlineData("mW/m²", HeatFluxUnit.MilliwattPerSquareMeter)] + [InlineData("nW/m²", HeatFluxUnit.NanowattPerSquareMeter)] + [InlineData("lbf/(ft·s)", HeatFluxUnit.PoundForcePerFootSecond)] + [InlineData("lb/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("lbm/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("W/ft²", HeatFluxUnit.WattPerSquareFoot)] + [InlineData("W/in²", HeatFluxUnit.WattPerSquareInch)] + [InlineData("W/m²", HeatFluxUnit.WattPerSquareMeter)] + public void TryParseUnit(string abbreviation, HeatFluxUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(HeatFlux.TryParseUnit(abbreviation, out HeatFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "BTU/(h·ft²)", HeatFluxUnit.BtuPerHourSquareFoot)] + [InlineData("en-US", "BTU/(min·ft²)", HeatFluxUnit.BtuPerMinuteSquareFoot)] + [InlineData("en-US", "BTU/(s·ft²)", HeatFluxUnit.BtuPerSecondSquareFoot)] + [InlineData("en-US", "BTU/(s·in²)", HeatFluxUnit.BtuPerSecondSquareInch)] + [InlineData("en-US", "cal/(s·cm²)", HeatFluxUnit.CaloriePerSecondSquareCentimeter)] + [InlineData("en-US", "cW/m²", HeatFluxUnit.CentiwattPerSquareMeter)] + [InlineData("en-US", "dW/m²", HeatFluxUnit.DeciwattPerSquareMeter)] + [InlineData("en-US", "kcal/(h·m²)", HeatFluxUnit.KilocaloriePerHourSquareMeter)] + [InlineData("en-US", "kcal/(s·cm²)", HeatFluxUnit.KilocaloriePerSecondSquareCentimeter)] + [InlineData("en-US", "kW/m²", HeatFluxUnit.KilowattPerSquareMeter)] + [InlineData("en-US", "µW/m²", HeatFluxUnit.MicrowattPerSquareMeter)] + [InlineData("en-US", "mW/m²", HeatFluxUnit.MilliwattPerSquareMeter)] + [InlineData("en-US", "nW/m²", HeatFluxUnit.NanowattPerSquareMeter)] + [InlineData("en-US", "lbf/(ft·s)", HeatFluxUnit.PoundForcePerFootSecond)] + [InlineData("en-US", "lb/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("en-US", "lbm/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("en-US", "W/ft²", HeatFluxUnit.WattPerSquareFoot)] + [InlineData("en-US", "W/in²", HeatFluxUnit.WattPerSquareInch)] + [InlineData("en-US", "W/m²", HeatFluxUnit.WattPerSquareMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, HeatFluxUnit expectedUnit) + { + Assert.True(HeatFlux.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out HeatFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs index f579a9bfa2..2096f31c94 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs @@ -409,168 +409,90 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("Btu/(h·ft²·°F)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("Btu/(ft²·h·°F)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("Btu/(hr·ft²·°F)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("Btu/(ft²·hr·°F)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/(h·m²·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/(m²·h·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/(hr·m²·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("kcal/(m²·hr·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("kkcal/(h·m²·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("kkcal/(m²·h·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("kkcal/(hr·m²·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("kkcal/(m²·hr·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("W/(m²·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = HeatTransferCoefficient.ParseUnit("W/(m²·K)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("Btu/(h·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(ft²·h·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(hr·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(ft²·hr·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("kcal/(h·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(m²·h·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(hr·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(m²·hr·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(h·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(m²·h·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(hr·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] + [InlineData("W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] + public void ParseUnit(string abbreviation, HeatTransferCoefficientUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + HeatTransferCoefficientUnit parsedUnit = HeatTransferCoefficient.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(HeatTransferCoefficient.TryParseUnit("Btu/(h·ft²·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("Btu/(ft²·h·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("Btu/(hr·ft²·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("Btu/(ft²·hr·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/(h·m²·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/(m²·h·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/(hr·m²·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("kcal/(m²·hr·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("kkcal/(h·m²·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("kkcal/(m²·h·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("kkcal/(hr·m²·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("kkcal/(m²·hr·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(HeatTransferCoefficient.TryParseUnit("W/(m²·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterCelsius, parsedUnit); - } + [Theory] + [InlineData("en-US", "Btu/(h·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(ft²·h·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(hr·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(ft²·hr·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "kcal/(h·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(m²·h·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(hr·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(m²·hr·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(h·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(m²·h·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(hr·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] + [InlineData("en-US", "W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] + public void ParseUnitWithCulture(string culture, string abbreviation, HeatTransferCoefficientUnit expectedUnit) + { + HeatTransferCoefficientUnit parsedUnit = HeatTransferCoefficient.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(HeatTransferCoefficient.TryParseUnit("W/(m²·K)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(HeatTransferCoefficientUnit.WattPerSquareMeterKelvin, parsedUnit); - } + [Theory] + [InlineData("Btu/(h·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(ft²·h·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(hr·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(ft²·hr·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("kcal/(h·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(m²·h·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(hr·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(m²·hr·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(h·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(m²·h·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(hr·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] + [InlineData("W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] + public void TryParseUnit(string abbreviation, HeatTransferCoefficientUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(HeatTransferCoefficient.TryParseUnit(abbreviation, out HeatTransferCoefficientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "Btu/(h·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(ft²·h·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(hr·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(ft²·hr·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "kcal/(h·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(m²·h·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(hr·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(m²·hr·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(h·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(m²·h·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(hr·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] + [InlineData("en-US", "W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] + public void TryParseUnitWithCulture(string culture, string abbreviation, HeatTransferCoefficientUnit expectedUnit) + { + Assert.True(HeatTransferCoefficient.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out HeatTransferCoefficientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs index c9a75b1ab0..2fab45a263 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs @@ -257,48 +257,50 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("klx", IlluminanceUnit.Kilolux)] + [InlineData("lx", IlluminanceUnit.Lux)] + [InlineData("Mlx", IlluminanceUnit.Megalux)] + [InlineData("mlx", IlluminanceUnit.Millilux)] + public void ParseUnit(string abbreviation, IlluminanceUnit expectedUnit) { - try - { - var parsedUnit = Illuminance.ParseUnit("klx", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IlluminanceUnit.Kilolux, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Illuminance.ParseUnit("lx", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IlluminanceUnit.Lux, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Illuminance.ParseUnit("Mlx", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IlluminanceUnit.Megalux, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Illuminance.ParseUnit("mlx", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IlluminanceUnit.Millilux, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + IlluminanceUnit parsedUnit = Illuminance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "klx", IlluminanceUnit.Kilolux)] + [InlineData("en-US", "lx", IlluminanceUnit.Lux)] + [InlineData("en-US", "Mlx", IlluminanceUnit.Megalux)] + [InlineData("en-US", "mlx", IlluminanceUnit.Millilux)] + public void ParseUnitWithCulture(string culture, string abbreviation, IlluminanceUnit expectedUnit) { - { - Assert.True(Illuminance.TryParseUnit("klx", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IlluminanceUnit.Kilolux, parsedUnit); - } + IlluminanceUnit parsedUnit = Illuminance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Illuminance.TryParseUnit("lx", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IlluminanceUnit.Lux, parsedUnit); - } + [Theory] + [InlineData("klx", IlluminanceUnit.Kilolux)] + [InlineData("lx", IlluminanceUnit.Lux)] + [InlineData("Mlx", IlluminanceUnit.Megalux)] + [InlineData("mlx", IlluminanceUnit.Millilux)] + public void TryParseUnit(string abbreviation, IlluminanceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Illuminance.TryParseUnit(abbreviation, out IlluminanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "klx", IlluminanceUnit.Kilolux)] + [InlineData("en-US", "lx", IlluminanceUnit.Lux)] + [InlineData("en-US", "Mlx", IlluminanceUnit.Megalux)] + [InlineData("en-US", "mlx", IlluminanceUnit.Millilux)] + public void TryParseUnitWithCulture(string culture, string abbreviation, IlluminanceUnit expectedUnit) + { + Assert.True(Illuminance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out IlluminanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs index 6615c7a233..3227ff5ba6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs @@ -464,147 +464,86 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Impulse.ParseUnit("cN·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.CentinewtonSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("daN·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.DecanewtonSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("dN·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.DecinewtonSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("kg·m/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.KilogramMeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("kN·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.KilonewtonSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("MN·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.MeganewtonSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("µN·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.MicronewtonSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("mN·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.MillinewtonSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("nN·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.NanonewtonSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("N·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.NewtonSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("lb·ft/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.PoundFootPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("lbf·s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.PoundForceSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Impulse.ParseUnit("slug·ft/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ImpulseUnit.SlugFootPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cN·s", ImpulseUnit.CentinewtonSecond)] + [InlineData("daN·s", ImpulseUnit.DecanewtonSecond)] + [InlineData("dN·s", ImpulseUnit.DecinewtonSecond)] + [InlineData("kg·m/s", ImpulseUnit.KilogramMeterPerSecond)] + [InlineData("kN·s", ImpulseUnit.KilonewtonSecond)] + [InlineData("MN·s", ImpulseUnit.MeganewtonSecond)] + [InlineData("µN·s", ImpulseUnit.MicronewtonSecond)] + [InlineData("mN·s", ImpulseUnit.MillinewtonSecond)] + [InlineData("nN·s", ImpulseUnit.NanonewtonSecond)] + [InlineData("N·s", ImpulseUnit.NewtonSecond)] + [InlineData("lb·ft/s", ImpulseUnit.PoundFootPerSecond)] + [InlineData("lbf·s", ImpulseUnit.PoundForceSecond)] + [InlineData("slug·ft/s", ImpulseUnit.SlugFootPerSecond)] + public void ParseUnit(string abbreviation, ImpulseUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ImpulseUnit parsedUnit = Impulse.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Impulse.TryParseUnit("cN·s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ImpulseUnit.CentinewtonSecond, parsedUnit); - } - - { - Assert.True(Impulse.TryParseUnit("daN·s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ImpulseUnit.DecanewtonSecond, parsedUnit); - } - - { - Assert.True(Impulse.TryParseUnit("dN·s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ImpulseUnit.DecinewtonSecond, parsedUnit); - } - - { - Assert.True(Impulse.TryParseUnit("kg·m/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ImpulseUnit.KilogramMeterPerSecond, parsedUnit); - } - - { - Assert.True(Impulse.TryParseUnit("kN·s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ImpulseUnit.KilonewtonSecond, parsedUnit); - } - - { - Assert.True(Impulse.TryParseUnit("µN·s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ImpulseUnit.MicronewtonSecond, parsedUnit); - } - - { - Assert.True(Impulse.TryParseUnit("nN·s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ImpulseUnit.NanonewtonSecond, parsedUnit); - } - - { - Assert.True(Impulse.TryParseUnit("N·s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ImpulseUnit.NewtonSecond, parsedUnit); - } - - { - Assert.True(Impulse.TryParseUnit("lb·ft/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ImpulseUnit.PoundFootPerSecond, parsedUnit); - } - - { - Assert.True(Impulse.TryParseUnit("lbf·s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ImpulseUnit.PoundForceSecond, parsedUnit); - } + [Theory] + [InlineData("en-US", "cN·s", ImpulseUnit.CentinewtonSecond)] + [InlineData("en-US", "daN·s", ImpulseUnit.DecanewtonSecond)] + [InlineData("en-US", "dN·s", ImpulseUnit.DecinewtonSecond)] + [InlineData("en-US", "kg·m/s", ImpulseUnit.KilogramMeterPerSecond)] + [InlineData("en-US", "kN·s", ImpulseUnit.KilonewtonSecond)] + [InlineData("en-US", "MN·s", ImpulseUnit.MeganewtonSecond)] + [InlineData("en-US", "µN·s", ImpulseUnit.MicronewtonSecond)] + [InlineData("en-US", "mN·s", ImpulseUnit.MillinewtonSecond)] + [InlineData("en-US", "nN·s", ImpulseUnit.NanonewtonSecond)] + [InlineData("en-US", "N·s", ImpulseUnit.NewtonSecond)] + [InlineData("en-US", "lb·ft/s", ImpulseUnit.PoundFootPerSecond)] + [InlineData("en-US", "lbf·s", ImpulseUnit.PoundForceSecond)] + [InlineData("en-US", "slug·ft/s", ImpulseUnit.SlugFootPerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, ImpulseUnit expectedUnit) + { + ImpulseUnit parsedUnit = Impulse.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Impulse.TryParseUnit("slug·ft/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ImpulseUnit.SlugFootPerSecond, parsedUnit); - } + [Theory] + [InlineData("cN·s", ImpulseUnit.CentinewtonSecond)] + [InlineData("daN·s", ImpulseUnit.DecanewtonSecond)] + [InlineData("dN·s", ImpulseUnit.DecinewtonSecond)] + [InlineData("kg·m/s", ImpulseUnit.KilogramMeterPerSecond)] + [InlineData("kN·s", ImpulseUnit.KilonewtonSecond)] + [InlineData("MN·s", ImpulseUnit.MeganewtonSecond)] + [InlineData("µN·s", ImpulseUnit.MicronewtonSecond)] + [InlineData("mN·s", ImpulseUnit.MillinewtonSecond)] + [InlineData("nN·s", ImpulseUnit.NanonewtonSecond)] + [InlineData("N·s", ImpulseUnit.NewtonSecond)] + [InlineData("lb·ft/s", ImpulseUnit.PoundFootPerSecond)] + [InlineData("lbf·s", ImpulseUnit.PoundForceSecond)] + [InlineData("slug·ft/s", ImpulseUnit.SlugFootPerSecond)] + public void TryParseUnit(string abbreviation, ImpulseUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Impulse.TryParseUnit(abbreviation, out ImpulseUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cN·s", ImpulseUnit.CentinewtonSecond)] + [InlineData("en-US", "daN·s", ImpulseUnit.DecanewtonSecond)] + [InlineData("en-US", "dN·s", ImpulseUnit.DecinewtonSecond)] + [InlineData("en-US", "kg·m/s", ImpulseUnit.KilogramMeterPerSecond)] + [InlineData("en-US", "kN·s", ImpulseUnit.KilonewtonSecond)] + [InlineData("en-US", "MN·s", ImpulseUnit.MeganewtonSecond)] + [InlineData("en-US", "µN·s", ImpulseUnit.MicronewtonSecond)] + [InlineData("en-US", "mN·s", ImpulseUnit.MillinewtonSecond)] + [InlineData("en-US", "nN·s", ImpulseUnit.NanonewtonSecond)] + [InlineData("en-US", "N·s", ImpulseUnit.NewtonSecond)] + [InlineData("en-US", "lb·ft/s", ImpulseUnit.PoundFootPerSecond)] + [InlineData("en-US", "lbf·s", ImpulseUnit.PoundForceSecond)] + [InlineData("en-US", "slug·ft/s", ImpulseUnit.SlugFootPerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ImpulseUnit expectedUnit) + { + Assert.True(Impulse.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ImpulseUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs index f955deed1b..ce50c14d79 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs @@ -619,170 +619,138 @@ public void TryParse() { } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Information.ParseUnit("b", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Bit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("B", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Byte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("Eb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Exabit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("EB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Exabyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("Eib", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Exbibit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("EiB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Exbibyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("Gib", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Gibibit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("GiB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Gibibyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("Gb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Gigabit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("GB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Gigabyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("Kib", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Kibibit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("KiB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Kibibyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("kb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Kilobit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("kB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Kilobyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("Mib", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Mebibit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("MiB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Mebibyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("Mb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Megabit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("MB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Megabyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("Pib", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Pebibit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("PiB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Pebibyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("Pb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Petabit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("PB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Petabyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("Tib", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Tebibit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("TiB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Tebibyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Information.ParseUnit("Tb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Terabit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + [Theory] + [InlineData("b", InformationUnit.Bit)] + [InlineData("B", InformationUnit.Byte)] + [InlineData("Eb", InformationUnit.Exabit)] + [InlineData("EB", InformationUnit.Exabyte)] + [InlineData("Eib", InformationUnit.Exbibit)] + [InlineData("EiB", InformationUnit.Exbibyte)] + [InlineData("Gib", InformationUnit.Gibibit)] + [InlineData("GiB", InformationUnit.Gibibyte)] + [InlineData("Gb", InformationUnit.Gigabit)] + [InlineData("GB", InformationUnit.Gigabyte)] + [InlineData("Kib", InformationUnit.Kibibit)] + [InlineData("KiB", InformationUnit.Kibibyte)] + [InlineData("kb", InformationUnit.Kilobit)] + [InlineData("kB", InformationUnit.Kilobyte)] + [InlineData("Mib", InformationUnit.Mebibit)] + [InlineData("MiB", InformationUnit.Mebibyte)] + [InlineData("Mb", InformationUnit.Megabit)] + [InlineData("MB", InformationUnit.Megabyte)] + [InlineData("Pib", InformationUnit.Pebibit)] + [InlineData("PiB", InformationUnit.Pebibyte)] + [InlineData("Pb", InformationUnit.Petabit)] + [InlineData("PB", InformationUnit.Petabyte)] + [InlineData("Tib", InformationUnit.Tebibit)] + [InlineData("TiB", InformationUnit.Tebibyte)] + [InlineData("Tb", InformationUnit.Terabit)] + [InlineData("TB", InformationUnit.Terabyte)] + public void ParseUnit(string abbreviation, InformationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + InformationUnit parsedUnit = Information.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } - try - { - var parsedUnit = Information.ParseUnit("TB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(InformationUnit.Terabyte, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + [Theory] + [InlineData("en-US", "b", InformationUnit.Bit)] + [InlineData("en-US", "B", InformationUnit.Byte)] + [InlineData("en-US", "Eb", InformationUnit.Exabit)] + [InlineData("en-US", "EB", InformationUnit.Exabyte)] + [InlineData("en-US", "Eib", InformationUnit.Exbibit)] + [InlineData("en-US", "EiB", InformationUnit.Exbibyte)] + [InlineData("en-US", "Gib", InformationUnit.Gibibit)] + [InlineData("en-US", "GiB", InformationUnit.Gibibyte)] + [InlineData("en-US", "Gb", InformationUnit.Gigabit)] + [InlineData("en-US", "GB", InformationUnit.Gigabyte)] + [InlineData("en-US", "Kib", InformationUnit.Kibibit)] + [InlineData("en-US", "KiB", InformationUnit.Kibibyte)] + [InlineData("en-US", "kb", InformationUnit.Kilobit)] + [InlineData("en-US", "kB", InformationUnit.Kilobyte)] + [InlineData("en-US", "Mib", InformationUnit.Mebibit)] + [InlineData("en-US", "MiB", InformationUnit.Mebibyte)] + [InlineData("en-US", "Mb", InformationUnit.Megabit)] + [InlineData("en-US", "MB", InformationUnit.Megabyte)] + [InlineData("en-US", "Pib", InformationUnit.Pebibit)] + [InlineData("en-US", "PiB", InformationUnit.Pebibyte)] + [InlineData("en-US", "Pb", InformationUnit.Petabit)] + [InlineData("en-US", "PB", InformationUnit.Petabyte)] + [InlineData("en-US", "Tib", InformationUnit.Tebibit)] + [InlineData("en-US", "TiB", InformationUnit.Tebibyte)] + [InlineData("en-US", "Tb", InformationUnit.Terabit)] + [InlineData("en-US", "TB", InformationUnit.Terabyte)] + public void ParseUnitWithCulture(string culture, string abbreviation, InformationUnit expectedUnit) + { + InformationUnit parsedUnit = Information.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("b", InformationUnit.Bit)] + [InlineData("B", InformationUnit.Byte)] + [InlineData("Eb", InformationUnit.Exabit)] + [InlineData("EB", InformationUnit.Exabyte)] + [InlineData("Eib", InformationUnit.Exbibit)] + [InlineData("EiB", InformationUnit.Exbibyte)] + [InlineData("Gib", InformationUnit.Gibibit)] + [InlineData("GiB", InformationUnit.Gibibyte)] + [InlineData("Gb", InformationUnit.Gigabit)] + [InlineData("GB", InformationUnit.Gigabyte)] + [InlineData("Kib", InformationUnit.Kibibit)] + [InlineData("KiB", InformationUnit.Kibibyte)] + [InlineData("kb", InformationUnit.Kilobit)] + [InlineData("kB", InformationUnit.Kilobyte)] + [InlineData("Mib", InformationUnit.Mebibit)] + [InlineData("MiB", InformationUnit.Mebibyte)] + [InlineData("Mb", InformationUnit.Megabit)] + [InlineData("MB", InformationUnit.Megabyte)] + [InlineData("Pib", InformationUnit.Pebibit)] + [InlineData("PiB", InformationUnit.Pebibyte)] + [InlineData("Pb", InformationUnit.Petabit)] + [InlineData("PB", InformationUnit.Petabyte)] + [InlineData("Tib", InformationUnit.Tebibit)] + [InlineData("TiB", InformationUnit.Tebibyte)] + [InlineData("Tb", InformationUnit.Terabit)] + [InlineData("TB", InformationUnit.Terabyte)] + public void TryParseUnit(string abbreviation, InformationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Information.TryParseUnit(abbreviation, out InformationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { + [Theory] + [InlineData("en-US", "b", InformationUnit.Bit)] + [InlineData("en-US", "B", InformationUnit.Byte)] + [InlineData("en-US", "Eb", InformationUnit.Exabit)] + [InlineData("en-US", "EB", InformationUnit.Exabyte)] + [InlineData("en-US", "Eib", InformationUnit.Exbibit)] + [InlineData("en-US", "EiB", InformationUnit.Exbibyte)] + [InlineData("en-US", "Gib", InformationUnit.Gibibit)] + [InlineData("en-US", "GiB", InformationUnit.Gibibyte)] + [InlineData("en-US", "Gb", InformationUnit.Gigabit)] + [InlineData("en-US", "GB", InformationUnit.Gigabyte)] + [InlineData("en-US", "Kib", InformationUnit.Kibibit)] + [InlineData("en-US", "KiB", InformationUnit.Kibibyte)] + [InlineData("en-US", "kb", InformationUnit.Kilobit)] + [InlineData("en-US", "kB", InformationUnit.Kilobyte)] + [InlineData("en-US", "Mib", InformationUnit.Mebibit)] + [InlineData("en-US", "MiB", InformationUnit.Mebibyte)] + [InlineData("en-US", "Mb", InformationUnit.Megabit)] + [InlineData("en-US", "MB", InformationUnit.Megabyte)] + [InlineData("en-US", "Pib", InformationUnit.Pebibit)] + [InlineData("en-US", "PiB", InformationUnit.Pebibyte)] + [InlineData("en-US", "Pb", InformationUnit.Petabit)] + [InlineData("en-US", "PB", InformationUnit.Petabyte)] + [InlineData("en-US", "Tib", InformationUnit.Tebibit)] + [InlineData("en-US", "TiB", InformationUnit.Tebibyte)] + [InlineData("en-US", "Tb", InformationUnit.Terabit)] + [InlineData("en-US", "TB", InformationUnit.Terabyte)] + public void TryParseUnitWithCulture(string culture, string abbreviation, InformationUnit expectedUnit) + { + Assert.True(Information.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out InformationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs index 2912b6e3d5..06fb0ec8be 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs @@ -475,148 +475,90 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Irradiance.ParseUnit("kW/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.KilowattPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("kW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.KilowattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("MW/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.MegawattPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("MW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.MegawattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("µW/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.MicrowattPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("µW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.MicrowattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("mW/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.MilliwattPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("mW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.MilliwattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("nW/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.NanowattPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("nW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.NanowattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("pW/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.PicowattPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("pW/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.PicowattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("W/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.WattPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiance.ParseUnit("W/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradianceUnit.WattPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("kW/cm²", IrradianceUnit.KilowattPerSquareCentimeter)] + [InlineData("kW/m²", IrradianceUnit.KilowattPerSquareMeter)] + [InlineData("MW/cm²", IrradianceUnit.MegawattPerSquareCentimeter)] + [InlineData("MW/m²", IrradianceUnit.MegawattPerSquareMeter)] + [InlineData("µW/cm²", IrradianceUnit.MicrowattPerSquareCentimeter)] + [InlineData("µW/m²", IrradianceUnit.MicrowattPerSquareMeter)] + [InlineData("mW/cm²", IrradianceUnit.MilliwattPerSquareCentimeter)] + [InlineData("mW/m²", IrradianceUnit.MilliwattPerSquareMeter)] + [InlineData("nW/cm²", IrradianceUnit.NanowattPerSquareCentimeter)] + [InlineData("nW/m²", IrradianceUnit.NanowattPerSquareMeter)] + [InlineData("pW/cm²", IrradianceUnit.PicowattPerSquareCentimeter)] + [InlineData("pW/m²", IrradianceUnit.PicowattPerSquareMeter)] + [InlineData("W/cm²", IrradianceUnit.WattPerSquareCentimeter)] + [InlineData("W/m²", IrradianceUnit.WattPerSquareMeter)] + public void ParseUnit(string abbreviation, IrradianceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + IrradianceUnit parsedUnit = Irradiance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Irradiance.TryParseUnit("kW/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradianceUnit.KilowattPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Irradiance.TryParseUnit("kW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradianceUnit.KilowattPerSquareMeter, parsedUnit); - } - - { - Assert.True(Irradiance.TryParseUnit("µW/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradianceUnit.MicrowattPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Irradiance.TryParseUnit("µW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradianceUnit.MicrowattPerSquareMeter, parsedUnit); - } - - { - Assert.True(Irradiance.TryParseUnit("nW/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradianceUnit.NanowattPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Irradiance.TryParseUnit("nW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradianceUnit.NanowattPerSquareMeter, parsedUnit); - } - - { - Assert.True(Irradiance.TryParseUnit("pW/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradianceUnit.PicowattPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Irradiance.TryParseUnit("pW/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradianceUnit.PicowattPerSquareMeter, parsedUnit); - } - - { - Assert.True(Irradiance.TryParseUnit("W/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradianceUnit.WattPerSquareCentimeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "kW/cm²", IrradianceUnit.KilowattPerSquareCentimeter)] + [InlineData("en-US", "kW/m²", IrradianceUnit.KilowattPerSquareMeter)] + [InlineData("en-US", "MW/cm²", IrradianceUnit.MegawattPerSquareCentimeter)] + [InlineData("en-US", "MW/m²", IrradianceUnit.MegawattPerSquareMeter)] + [InlineData("en-US", "µW/cm²", IrradianceUnit.MicrowattPerSquareCentimeter)] + [InlineData("en-US", "µW/m²", IrradianceUnit.MicrowattPerSquareMeter)] + [InlineData("en-US", "mW/cm²", IrradianceUnit.MilliwattPerSquareCentimeter)] + [InlineData("en-US", "mW/m²", IrradianceUnit.MilliwattPerSquareMeter)] + [InlineData("en-US", "nW/cm²", IrradianceUnit.NanowattPerSquareCentimeter)] + [InlineData("en-US", "nW/m²", IrradianceUnit.NanowattPerSquareMeter)] + [InlineData("en-US", "pW/cm²", IrradianceUnit.PicowattPerSquareCentimeter)] + [InlineData("en-US", "pW/m²", IrradianceUnit.PicowattPerSquareMeter)] + [InlineData("en-US", "W/cm²", IrradianceUnit.WattPerSquareCentimeter)] + [InlineData("en-US", "W/m²", IrradianceUnit.WattPerSquareMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, IrradianceUnit expectedUnit) + { + IrradianceUnit parsedUnit = Irradiance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Irradiance.TryParseUnit("W/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradianceUnit.WattPerSquareMeter, parsedUnit); - } + [Theory] + [InlineData("kW/cm²", IrradianceUnit.KilowattPerSquareCentimeter)] + [InlineData("kW/m²", IrradianceUnit.KilowattPerSquareMeter)] + [InlineData("MW/cm²", IrradianceUnit.MegawattPerSquareCentimeter)] + [InlineData("MW/m²", IrradianceUnit.MegawattPerSquareMeter)] + [InlineData("µW/cm²", IrradianceUnit.MicrowattPerSquareCentimeter)] + [InlineData("µW/m²", IrradianceUnit.MicrowattPerSquareMeter)] + [InlineData("mW/cm²", IrradianceUnit.MilliwattPerSquareCentimeter)] + [InlineData("mW/m²", IrradianceUnit.MilliwattPerSquareMeter)] + [InlineData("nW/cm²", IrradianceUnit.NanowattPerSquareCentimeter)] + [InlineData("nW/m²", IrradianceUnit.NanowattPerSquareMeter)] + [InlineData("pW/cm²", IrradianceUnit.PicowattPerSquareCentimeter)] + [InlineData("pW/m²", IrradianceUnit.PicowattPerSquareMeter)] + [InlineData("W/cm²", IrradianceUnit.WattPerSquareCentimeter)] + [InlineData("W/m²", IrradianceUnit.WattPerSquareMeter)] + public void TryParseUnit(string abbreviation, IrradianceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Irradiance.TryParseUnit(abbreviation, out IrradianceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kW/cm²", IrradianceUnit.KilowattPerSquareCentimeter)] + [InlineData("en-US", "kW/m²", IrradianceUnit.KilowattPerSquareMeter)] + [InlineData("en-US", "MW/cm²", IrradianceUnit.MegawattPerSquareCentimeter)] + [InlineData("en-US", "MW/m²", IrradianceUnit.MegawattPerSquareMeter)] + [InlineData("en-US", "µW/cm²", IrradianceUnit.MicrowattPerSquareCentimeter)] + [InlineData("en-US", "µW/m²", IrradianceUnit.MicrowattPerSquareMeter)] + [InlineData("en-US", "mW/cm²", IrradianceUnit.MilliwattPerSquareCentimeter)] + [InlineData("en-US", "mW/m²", IrradianceUnit.MilliwattPerSquareMeter)] + [InlineData("en-US", "nW/cm²", IrradianceUnit.NanowattPerSquareCentimeter)] + [InlineData("en-US", "nW/m²", IrradianceUnit.NanowattPerSquareMeter)] + [InlineData("en-US", "pW/cm²", IrradianceUnit.PicowattPerSquareCentimeter)] + [InlineData("en-US", "pW/m²", IrradianceUnit.PicowattPerSquareMeter)] + [InlineData("en-US", "W/cm²", IrradianceUnit.WattPerSquareCentimeter)] + [InlineData("en-US", "W/m²", IrradianceUnit.WattPerSquareMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, IrradianceUnit expectedUnit) + { + Assert.True(Irradiance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out IrradianceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs index f7f6f25594..1f35081571 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs @@ -384,113 +384,70 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Irradiation.ParseUnit("Btu/ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradiationUnit.BtuPerSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiation.ParseUnit("J/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradiationUnit.JoulePerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiation.ParseUnit("J/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradiationUnit.JoulePerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiation.ParseUnit("J/mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradiationUnit.JoulePerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiation.ParseUnit("kBtu/ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradiationUnit.KilobtuPerSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiation.ParseUnit("kJ/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradiationUnit.KilojoulePerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiation.ParseUnit("kWh/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradiationUnit.KilowattHourPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiation.ParseUnit("mJ/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradiationUnit.MillijoulePerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Irradiation.ParseUnit("Wh/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(IrradiationUnit.WattHourPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("Btu/ft²", IrradiationUnit.BtuPerSquareFoot)] + [InlineData("J/cm²", IrradiationUnit.JoulePerSquareCentimeter)] + [InlineData("J/m²", IrradiationUnit.JoulePerSquareMeter)] + [InlineData("J/mm²", IrradiationUnit.JoulePerSquareMillimeter)] + [InlineData("kBtu/ft²", IrradiationUnit.KilobtuPerSquareFoot)] + [InlineData("kJ/m²", IrradiationUnit.KilojoulePerSquareMeter)] + [InlineData("kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] + [InlineData("mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] + [InlineData("Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] + public void ParseUnit(string abbreviation, IrradiationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + IrradiationUnit parsedUnit = Irradiation.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "Btu/ft²", IrradiationUnit.BtuPerSquareFoot)] + [InlineData("en-US", "J/cm²", IrradiationUnit.JoulePerSquareCentimeter)] + [InlineData("en-US", "J/m²", IrradiationUnit.JoulePerSquareMeter)] + [InlineData("en-US", "J/mm²", IrradiationUnit.JoulePerSquareMillimeter)] + [InlineData("en-US", "kBtu/ft²", IrradiationUnit.KilobtuPerSquareFoot)] + [InlineData("en-US", "kJ/m²", IrradiationUnit.KilojoulePerSquareMeter)] + [InlineData("en-US", "kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] + [InlineData("en-US", "mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] + [InlineData("en-US", "Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, IrradiationUnit expectedUnit) { - { - Assert.True(Irradiation.TryParseUnit("Btu/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradiationUnit.BtuPerSquareFoot, parsedUnit); - } - - { - Assert.True(Irradiation.TryParseUnit("J/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradiationUnit.JoulePerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Irradiation.TryParseUnit("J/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradiationUnit.JoulePerSquareMeter, parsedUnit); - } - - { - Assert.True(Irradiation.TryParseUnit("J/mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradiationUnit.JoulePerSquareMillimeter, parsedUnit); - } - - { - Assert.True(Irradiation.TryParseUnit("kBtu/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradiationUnit.KilobtuPerSquareFoot, parsedUnit); - } - - { - Assert.True(Irradiation.TryParseUnit("kJ/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradiationUnit.KilojoulePerSquareMeter, parsedUnit); - } - - { - Assert.True(Irradiation.TryParseUnit("kWh/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradiationUnit.KilowattHourPerSquareMeter, parsedUnit); - } - - { - Assert.True(Irradiation.TryParseUnit("mJ/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradiationUnit.MillijoulePerSquareCentimeter, parsedUnit); - } + IrradiationUnit parsedUnit = Irradiation.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Irradiation.TryParseUnit("Wh/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(IrradiationUnit.WattHourPerSquareMeter, parsedUnit); - } + [Theory] + [InlineData("Btu/ft²", IrradiationUnit.BtuPerSquareFoot)] + [InlineData("J/cm²", IrradiationUnit.JoulePerSquareCentimeter)] + [InlineData("J/m²", IrradiationUnit.JoulePerSquareMeter)] + [InlineData("J/mm²", IrradiationUnit.JoulePerSquareMillimeter)] + [InlineData("kBtu/ft²", IrradiationUnit.KilobtuPerSquareFoot)] + [InlineData("kJ/m²", IrradiationUnit.KilojoulePerSquareMeter)] + [InlineData("kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] + [InlineData("mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] + [InlineData("Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] + public void TryParseUnit(string abbreviation, IrradiationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Irradiation.TryParseUnit(abbreviation, out IrradiationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "Btu/ft²", IrradiationUnit.BtuPerSquareFoot)] + [InlineData("en-US", "J/cm²", IrradiationUnit.JoulePerSquareCentimeter)] + [InlineData("en-US", "J/m²", IrradiationUnit.JoulePerSquareMeter)] + [InlineData("en-US", "J/mm²", IrradiationUnit.JoulePerSquareMillimeter)] + [InlineData("en-US", "kBtu/ft²", IrradiationUnit.KilobtuPerSquareFoot)] + [InlineData("en-US", "kJ/m²", IrradiationUnit.KilojoulePerSquareMeter)] + [InlineData("en-US", "kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] + [InlineData("en-US", "mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] + [InlineData("en-US", "Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, IrradiationUnit expectedUnit) + { + Assert.True(Irradiation.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out IrradiationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs index aee273eb81..133edd0827 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs @@ -573,256 +573,100 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Jerk.ParseUnit("cm/s³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(JerkUnit.CentimeterPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("см/с³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(JerkUnit.CentimeterPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("dm/s³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(JerkUnit.DecimeterPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("дм/с³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(JerkUnit.DecimeterPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("ft/s³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(JerkUnit.FootPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("фут/с³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(JerkUnit.FootPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("in/s³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(JerkUnit.InchPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("дюйм/с³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(JerkUnit.InchPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("km/s³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(JerkUnit.KilometerPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("км/с³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(JerkUnit.KilometerPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("m/s³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(JerkUnit.MeterPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("м/с³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(JerkUnit.MeterPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("µm/s³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(JerkUnit.MicrometerPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("мкм/с³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(JerkUnit.MicrometerPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("mm/s³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(JerkUnit.MillimeterPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("мм/с³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(JerkUnit.MillimeterPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("mg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(JerkUnit.MillistandardGravitiesPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("мg/s", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(JerkUnit.MillistandardGravitiesPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("nm/s³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(JerkUnit.NanometerPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("нм/с³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(JerkUnit.NanometerPerSecondCubed, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("g/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(JerkUnit.StandardGravitiesPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Jerk.ParseUnit("g/s", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(JerkUnit.StandardGravitiesPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cm/s³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("dm/s³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("ft/s³", JerkUnit.FootPerSecondCubed)] + [InlineData("in/s³", JerkUnit.InchPerSecondCubed)] + [InlineData("km/s³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("m/s³", JerkUnit.MeterPerSecondCubed)] + [InlineData("µm/s³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("mm/s³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("mg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("nm/s³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("g/s", JerkUnit.StandardGravitiesPerSecond)] + public void ParseUnit(string abbreviation, JerkUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + JerkUnit parsedUnit = Jerk.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Jerk.TryParseUnit("cm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(JerkUnit.CentimeterPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("см/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(JerkUnit.CentimeterPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("dm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(JerkUnit.DecimeterPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("дм/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(JerkUnit.DecimeterPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("ft/s³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(JerkUnit.FootPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("фут/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(JerkUnit.FootPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("in/s³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(JerkUnit.InchPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("дюйм/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(JerkUnit.InchPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("km/s³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(JerkUnit.KilometerPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("км/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(JerkUnit.KilometerPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("m/s³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(JerkUnit.MeterPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("м/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(JerkUnit.MeterPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("µm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(JerkUnit.MicrometerPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("мкм/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(JerkUnit.MicrometerPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("mm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(JerkUnit.MillimeterPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("мм/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(JerkUnit.MillimeterPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("mg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(JerkUnit.MillistandardGravitiesPerSecond, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("мg/s", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(JerkUnit.MillistandardGravitiesPerSecond, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("nm/s³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(JerkUnit.NanometerPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("нм/с³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(JerkUnit.NanometerPerSecondCubed, parsedUnit); - } - - { - Assert.True(Jerk.TryParseUnit("g/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(JerkUnit.StandardGravitiesPerSecond, parsedUnit); - } + [Theory] + [InlineData("en-US", "cm/s³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("en-US", "dm/s³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("en-US", "ft/s³", JerkUnit.FootPerSecondCubed)] + [InlineData("en-US", "in/s³", JerkUnit.InchPerSecondCubed)] + [InlineData("en-US", "km/s³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("en-US", "m/s³", JerkUnit.MeterPerSecondCubed)] + [InlineData("en-US", "µm/s³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("en-US", "mm/s³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("en-US", "mg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("en-US", "nm/s³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("en-US", "g/s", JerkUnit.StandardGravitiesPerSecond)] + [InlineData("ru-RU", "см/с³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("ru-RU", "дм/с³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("ru-RU", "фут/с³", JerkUnit.FootPerSecondCubed)] + [InlineData("ru-RU", "дюйм/с³", JerkUnit.InchPerSecondCubed)] + [InlineData("ru-RU", "км/с³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("ru-RU", "м/с³", JerkUnit.MeterPerSecondCubed)] + [InlineData("ru-RU", "мкм/с³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("ru-RU", "мм/с³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("ru-RU", "мg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("ru-RU", "нм/с³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("ru-RU", "g/s", JerkUnit.StandardGravitiesPerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, JerkUnit expectedUnit) + { + JerkUnit parsedUnit = Jerk.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Jerk.TryParseUnit("g/s", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(JerkUnit.StandardGravitiesPerSecond, parsedUnit); - } + [Theory] + [InlineData("cm/s³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("dm/s³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("ft/s³", JerkUnit.FootPerSecondCubed)] + [InlineData("in/s³", JerkUnit.InchPerSecondCubed)] + [InlineData("km/s³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("m/s³", JerkUnit.MeterPerSecondCubed)] + [InlineData("µm/s³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("mm/s³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("mg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("nm/s³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("g/s", JerkUnit.StandardGravitiesPerSecond)] + public void TryParseUnit(string abbreviation, JerkUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Jerk.TryParseUnit(abbreviation, out JerkUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cm/s³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("en-US", "dm/s³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("en-US", "ft/s³", JerkUnit.FootPerSecondCubed)] + [InlineData("en-US", "in/s³", JerkUnit.InchPerSecondCubed)] + [InlineData("en-US", "km/s³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("en-US", "m/s³", JerkUnit.MeterPerSecondCubed)] + [InlineData("en-US", "µm/s³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("en-US", "mm/s³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("en-US", "mg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("en-US", "nm/s³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("en-US", "g/s", JerkUnit.StandardGravitiesPerSecond)] + [InlineData("ru-RU", "см/с³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("ru-RU", "дм/с³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("ru-RU", "фут/с³", JerkUnit.FootPerSecondCubed)] + [InlineData("ru-RU", "дюйм/с³", JerkUnit.InchPerSecondCubed)] + [InlineData("ru-RU", "км/с³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("ru-RU", "м/с³", JerkUnit.MeterPerSecondCubed)] + [InlineData("ru-RU", "мкм/с³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("ru-RU", "мм/с³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("ru-RU", "мg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("ru-RU", "нм/с³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("ru-RU", "g/s", JerkUnit.StandardGravitiesPerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, JerkUnit expectedUnit) + { + Assert.True(Jerk.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out JerkUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs index 79434dde3f..17ce47c442 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs @@ -488,201 +488,86 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = KinematicViscosity.ParseUnit("cSt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(KinematicViscosityUnit.Centistokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("сСт", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(KinematicViscosityUnit.Centistokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("dSt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(KinematicViscosityUnit.Decistokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("дСт", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(KinematicViscosityUnit.Decistokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("kSt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(KinematicViscosityUnit.Kilostokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("кСт", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(KinematicViscosityUnit.Kilostokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("µSt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(KinematicViscosityUnit.Microstokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("мкСт", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(KinematicViscosityUnit.Microstokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("mSt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(KinematicViscosityUnit.Millistokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("мСт", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(KinematicViscosityUnit.Millistokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("nSt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(KinematicViscosityUnit.Nanostokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("нСт", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(KinematicViscosityUnit.Nanostokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("ft²/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(KinematicViscosityUnit.SquareFootPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("m²/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(KinematicViscosityUnit.SquareMeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("м²/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(KinematicViscosityUnit.SquareMeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("St", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(KinematicViscosityUnit.Stokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = KinematicViscosity.ParseUnit("Ст", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(KinematicViscosityUnit.Stokes, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cSt", KinematicViscosityUnit.Centistokes)] + [InlineData("dSt", KinematicViscosityUnit.Decistokes)] + [InlineData("kSt", KinematicViscosityUnit.Kilostokes)] + [InlineData("µSt", KinematicViscosityUnit.Microstokes)] + [InlineData("mSt", KinematicViscosityUnit.Millistokes)] + [InlineData("nSt", KinematicViscosityUnit.Nanostokes)] + [InlineData("ft²/s", KinematicViscosityUnit.SquareFootPerSecond)] + [InlineData("m²/s", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("St", KinematicViscosityUnit.Stokes)] + public void ParseUnit(string abbreviation, KinematicViscosityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + KinematicViscosityUnit parsedUnit = KinematicViscosity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(KinematicViscosity.TryParseUnit("cSt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Centistokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("сСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Centistokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("dSt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Decistokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("дСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Decistokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("kSt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Kilostokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("кСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Kilostokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("µSt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Microstokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("мкСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Microstokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("mSt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Millistokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("мСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Millistokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("nSt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Nanostokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("нСт", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Nanostokes, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("ft²/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.SquareFootPerSecond, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("m²/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.SquareMeterPerSecond, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("м²/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.SquareMeterPerSecond, parsedUnit); - } - - { - Assert.True(KinematicViscosity.TryParseUnit("St", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Stokes, parsedUnit); - } + [Theory] + [InlineData("en-US", "cSt", KinematicViscosityUnit.Centistokes)] + [InlineData("en-US", "dSt", KinematicViscosityUnit.Decistokes)] + [InlineData("en-US", "kSt", KinematicViscosityUnit.Kilostokes)] + [InlineData("en-US", "µSt", KinematicViscosityUnit.Microstokes)] + [InlineData("en-US", "mSt", KinematicViscosityUnit.Millistokes)] + [InlineData("en-US", "nSt", KinematicViscosityUnit.Nanostokes)] + [InlineData("en-US", "ft²/s", KinematicViscosityUnit.SquareFootPerSecond)] + [InlineData("en-US", "m²/s", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("en-US", "St", KinematicViscosityUnit.Stokes)] + [InlineData("ru-RU", "сСт", KinematicViscosityUnit.Centistokes)] + [InlineData("ru-RU", "дСт", KinematicViscosityUnit.Decistokes)] + [InlineData("ru-RU", "кСт", KinematicViscosityUnit.Kilostokes)] + [InlineData("ru-RU", "мкСт", KinematicViscosityUnit.Microstokes)] + [InlineData("ru-RU", "мСт", KinematicViscosityUnit.Millistokes)] + [InlineData("ru-RU", "нСт", KinematicViscosityUnit.Nanostokes)] + [InlineData("ru-RU", "м²/с", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("ru-RU", "Ст", KinematicViscosityUnit.Stokes)] + public void ParseUnitWithCulture(string culture, string abbreviation, KinematicViscosityUnit expectedUnit) + { + KinematicViscosityUnit parsedUnit = KinematicViscosity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(KinematicViscosity.TryParseUnit("Ст", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(KinematicViscosityUnit.Stokes, parsedUnit); - } + [Theory] + [InlineData("cSt", KinematicViscosityUnit.Centistokes)] + [InlineData("dSt", KinematicViscosityUnit.Decistokes)] + [InlineData("kSt", KinematicViscosityUnit.Kilostokes)] + [InlineData("µSt", KinematicViscosityUnit.Microstokes)] + [InlineData("mSt", KinematicViscosityUnit.Millistokes)] + [InlineData("nSt", KinematicViscosityUnit.Nanostokes)] + [InlineData("ft²/s", KinematicViscosityUnit.SquareFootPerSecond)] + [InlineData("m²/s", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("St", KinematicViscosityUnit.Stokes)] + public void TryParseUnit(string abbreviation, KinematicViscosityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(KinematicViscosity.TryParseUnit(abbreviation, out KinematicViscosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cSt", KinematicViscosityUnit.Centistokes)] + [InlineData("en-US", "dSt", KinematicViscosityUnit.Decistokes)] + [InlineData("en-US", "kSt", KinematicViscosityUnit.Kilostokes)] + [InlineData("en-US", "µSt", KinematicViscosityUnit.Microstokes)] + [InlineData("en-US", "mSt", KinematicViscosityUnit.Millistokes)] + [InlineData("en-US", "nSt", KinematicViscosityUnit.Nanostokes)] + [InlineData("en-US", "ft²/s", KinematicViscosityUnit.SquareFootPerSecond)] + [InlineData("en-US", "m²/s", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("en-US", "St", KinematicViscosityUnit.Stokes)] + [InlineData("ru-RU", "сСт", KinematicViscosityUnit.Centistokes)] + [InlineData("ru-RU", "дСт", KinematicViscosityUnit.Decistokes)] + [InlineData("ru-RU", "кСт", KinematicViscosityUnit.Kilostokes)] + [InlineData("ru-RU", "мкСт", KinematicViscosityUnit.Microstokes)] + [InlineData("ru-RU", "мСт", KinematicViscosityUnit.Millistokes)] + [InlineData("ru-RU", "нСт", KinematicViscosityUnit.Nanostokes)] + [InlineData("ru-RU", "м²/с", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("ru-RU", "Ст", KinematicViscosityUnit.Stokes)] + public void TryParseUnitWithCulture(string culture, string abbreviation, KinematicViscosityUnit expectedUnit) + { + Assert.True(KinematicViscosity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out KinematicViscosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs index 6a0db2a2a4..7846d8d747 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs @@ -246,47 +246,46 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] + [InlineData("Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] + [InlineData("Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] + public void ParseUnit(string abbreviation, LeakRateUnit expectedUnit) { - try - { - var parsedUnit = LeakRate.ParseUnit("mbar·l/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LeakRateUnit.MillibarLiterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LeakRate.ParseUnit("Pa·m³/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LeakRateUnit.PascalCubicMeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LeakRate.ParseUnit("Torr·l/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LeakRateUnit.TorrLiterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + LeakRateUnit parsedUnit = LeakRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] + [InlineData("en-US", "Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] + [InlineData("en-US", "Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, LeakRateUnit expectedUnit) { - { - Assert.True(LeakRate.TryParseUnit("mbar·l/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LeakRateUnit.MillibarLiterPerSecond, parsedUnit); - } - - { - Assert.True(LeakRate.TryParseUnit("Pa·m³/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LeakRateUnit.PascalCubicMeterPerSecond, parsedUnit); - } + LeakRateUnit parsedUnit = LeakRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(LeakRate.TryParseUnit("Torr·l/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LeakRateUnit.TorrLiterPerSecond, parsedUnit); - } + [Theory] + [InlineData("mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] + [InlineData("Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] + [InlineData("Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] + public void TryParseUnit(string abbreviation, LeakRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(LeakRate.TryParseUnit(abbreviation, out LeakRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] + [InlineData("en-US", "Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] + [InlineData("en-US", "Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, LeakRateUnit expectedUnit) + { + Assert.True(LeakRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LeakRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs index 4709f14641..9a6e92a0df 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs @@ -1737,980 +1737,326 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Length.ParseUnit("Å", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Angstrom, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("A", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Angstrom, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("au", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.AstronomicalUnit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("ua", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.AstronomicalUnit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Centimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("см", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Centimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("厘米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Centimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("ch", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Chain, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("DM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.DataMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("dam", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Decameter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("дам", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Decameter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("十米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Decameter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("dm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Decimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("дм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Decimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("分米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Decimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("pica", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.DtpPica, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("pt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.DtpPoint, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("fathom", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Fathom, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("fm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Femtometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("фм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Femtometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("飞米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Femtometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Foot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("'", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Foot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("′", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Foot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("фут", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Foot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("英尺", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Foot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("Gm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Gigameter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("Гм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Gigameter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("吉米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Gigameter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Hand, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("hh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Hand, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("hm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Hectometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("гм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Hectometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("百米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Hectometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Inch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("\"", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Inch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("″", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Inch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("дюйм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Inch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("英寸", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Inch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("kft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Kilofoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("k'", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Kilofoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("k′", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Kilofoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("кфут", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Kilofoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("千英尺", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Kilofoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("kly", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.KilolightYear, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("km", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Kilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("км", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Kilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("千米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Kilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("kpc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Kiloparsec, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("kyd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Kiloyard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("кярд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Kiloyard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("千码", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Kiloyard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("ly", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.LightYear, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("Mly", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.MegalightYear, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("Mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Megameter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("Мм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Megameter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("兆米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Megameter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("Mpc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Megaparsec, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Meter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("м", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Meter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Meter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("µin", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Microinch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("микродюйм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Microinch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("微英寸", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Microinch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("µm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Micrometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("мкм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Micrometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("微米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Micrometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("mil", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Mil, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("мил", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Mil, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("密耳", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Mil, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("mi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Mile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("миля", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Mile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("英里", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Mile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Millimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("мм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Millimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("毫米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Millimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("nm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Nanometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("нм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Nanometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("纳米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Nanometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("NM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.NauticalMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("nmi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.NauticalMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("мил", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.NauticalMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("纳米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.NauticalMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("pc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Parsec, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("pm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Picometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("пм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Picometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("皮米", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Picometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("pica", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.PrinterPica, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("pt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.PrinterPoint, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("shackle", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Shackle, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("R⊙", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.SolarRadius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("twip", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Twip, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("ftUS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.UsSurveyFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("yd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LengthUnit.Yard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("ярд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(LengthUnit.Yard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Length.ParseUnit("码", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(LengthUnit.Yard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + [Theory] + [InlineData("Å", LengthUnit.Angstrom)] + [InlineData("A", LengthUnit.Angstrom)] + [InlineData("au", LengthUnit.AstronomicalUnit)] + [InlineData("ua", LengthUnit.AstronomicalUnit)] + [InlineData("cm", LengthUnit.Centimeter)] + [InlineData("ch", LengthUnit.Chain)] + [InlineData("DM", LengthUnit.DataMile)] + [InlineData("dam", LengthUnit.Decameter)] + [InlineData("dm", LengthUnit.Decimeter)] + [InlineData("fathom", LengthUnit.Fathom)] + [InlineData("fm", LengthUnit.Femtometer)] + [InlineData("ft", LengthUnit.Foot)] + [InlineData("'", LengthUnit.Foot)] + [InlineData("′", LengthUnit.Foot)] + [InlineData("Gm", LengthUnit.Gigameter)] + [InlineData("h", LengthUnit.Hand)] + [InlineData("hh", LengthUnit.Hand)] + [InlineData("hm", LengthUnit.Hectometer)] + [InlineData("in", LengthUnit.Inch)] + [InlineData("\"", LengthUnit.Inch)] + [InlineData("″", LengthUnit.Inch)] + [InlineData("kft", LengthUnit.Kilofoot)] + [InlineData("k'", LengthUnit.Kilofoot)] + [InlineData("k′", LengthUnit.Kilofoot)] + [InlineData("kly", LengthUnit.KilolightYear)] + [InlineData("km", LengthUnit.Kilometer)] + [InlineData("kpc", LengthUnit.Kiloparsec)] + [InlineData("kyd", LengthUnit.Kiloyard)] + [InlineData("ly", LengthUnit.LightYear)] + [InlineData("Mly", LengthUnit.MegalightYear)] + [InlineData("Mm", LengthUnit.Megameter)] + [InlineData("Mpc", LengthUnit.Megaparsec)] + [InlineData("m", LengthUnit.Meter)] + [InlineData("µin", LengthUnit.Microinch)] + [InlineData("µm", LengthUnit.Micrometer)] + [InlineData("mil", LengthUnit.Mil)] + [InlineData("mi", LengthUnit.Mile)] + [InlineData("mm", LengthUnit.Millimeter)] + [InlineData("nm", LengthUnit.Nanometer)] + [InlineData("NM", LengthUnit.NauticalMile)] + [InlineData("nmi", LengthUnit.NauticalMile)] + [InlineData("pc", LengthUnit.Parsec)] + [InlineData("pm", LengthUnit.Picometer)] + [InlineData("shackle", LengthUnit.Shackle)] + [InlineData("R⊙", LengthUnit.SolarRadius)] + [InlineData("twip", LengthUnit.Twip)] + [InlineData("ftUS", LengthUnit.UsSurveyFoot)] + [InlineData("yd", LengthUnit.Yard)] + public void ParseUnit(string abbreviation, LengthUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + LengthUnit parsedUnit = Length.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "Å", LengthUnit.Angstrom)] + [InlineData("en-US", "A", LengthUnit.Angstrom)] + [InlineData("en-US", "au", LengthUnit.AstronomicalUnit)] + [InlineData("en-US", "ua", LengthUnit.AstronomicalUnit)] + [InlineData("en-US", "cm", LengthUnit.Centimeter)] + [InlineData("en-US", "ch", LengthUnit.Chain)] + [InlineData("en-US", "DM", LengthUnit.DataMile)] + [InlineData("en-US", "dam", LengthUnit.Decameter)] + [InlineData("en-US", "dm", LengthUnit.Decimeter)] + [InlineData("en-US", "fathom", LengthUnit.Fathom)] + [InlineData("en-US", "fm", LengthUnit.Femtometer)] + [InlineData("en-US", "ft", LengthUnit.Foot)] + [InlineData("en-US", "'", LengthUnit.Foot)] + [InlineData("en-US", "′", LengthUnit.Foot)] + [InlineData("en-US", "Gm", LengthUnit.Gigameter)] + [InlineData("en-US", "h", LengthUnit.Hand)] + [InlineData("en-US", "hh", LengthUnit.Hand)] + [InlineData("en-US", "hm", LengthUnit.Hectometer)] + [InlineData("en-US", "in", LengthUnit.Inch)] + [InlineData("en-US", "\"", LengthUnit.Inch)] + [InlineData("en-US", "″", LengthUnit.Inch)] + [InlineData("en-US", "kft", LengthUnit.Kilofoot)] + [InlineData("en-US", "k'", LengthUnit.Kilofoot)] + [InlineData("en-US", "k′", LengthUnit.Kilofoot)] + [InlineData("en-US", "kly", LengthUnit.KilolightYear)] + [InlineData("en-US", "km", LengthUnit.Kilometer)] + [InlineData("en-US", "kpc", LengthUnit.Kiloparsec)] + [InlineData("en-US", "kyd", LengthUnit.Kiloyard)] + [InlineData("en-US", "ly", LengthUnit.LightYear)] + [InlineData("en-US", "Mly", LengthUnit.MegalightYear)] + [InlineData("en-US", "Mm", LengthUnit.Megameter)] + [InlineData("en-US", "Mpc", LengthUnit.Megaparsec)] + [InlineData("en-US", "m", LengthUnit.Meter)] + [InlineData("en-US", "µin", LengthUnit.Microinch)] + [InlineData("en-US", "µm", LengthUnit.Micrometer)] + [InlineData("en-US", "mil", LengthUnit.Mil)] + [InlineData("en-US", "mi", LengthUnit.Mile)] + [InlineData("en-US", "mm", LengthUnit.Millimeter)] + [InlineData("en-US", "nm", LengthUnit.Nanometer)] + [InlineData("en-US", "NM", LengthUnit.NauticalMile)] + [InlineData("en-US", "nmi", LengthUnit.NauticalMile)] + [InlineData("en-US", "pc", LengthUnit.Parsec)] + [InlineData("en-US", "pm", LengthUnit.Picometer)] + [InlineData("en-US", "shackle", LengthUnit.Shackle)] + [InlineData("en-US", "R⊙", LengthUnit.SolarRadius)] + [InlineData("en-US", "twip", LengthUnit.Twip)] + [InlineData("en-US", "ftUS", LengthUnit.UsSurveyFoot)] + [InlineData("en-US", "yd", LengthUnit.Yard)] + [InlineData("ru-RU", "см", LengthUnit.Centimeter)] + [InlineData("ru-RU", "дам", LengthUnit.Decameter)] + [InlineData("ru-RU", "дм", LengthUnit.Decimeter)] + [InlineData("ru-RU", "фм", LengthUnit.Femtometer)] + [InlineData("ru-RU", "фут", LengthUnit.Foot)] + [InlineData("ru-RU", "Гм", LengthUnit.Gigameter)] + [InlineData("ru-RU", "гм", LengthUnit.Hectometer)] + [InlineData("ru-RU", "дюйм", LengthUnit.Inch)] + [InlineData("ru-RU", "кфут", LengthUnit.Kilofoot)] + [InlineData("ru-RU", "км", LengthUnit.Kilometer)] + [InlineData("ru-RU", "кярд", LengthUnit.Kiloyard)] + [InlineData("ru-RU", "Мм", LengthUnit.Megameter)] + [InlineData("ru-RU", "м", LengthUnit.Meter)] + [InlineData("ru-RU", "микродюйм", LengthUnit.Microinch)] + [InlineData("ru-RU", "мкм", LengthUnit.Micrometer)] + [InlineData("ru-RU", "миля", LengthUnit.Mile)] + [InlineData("ru-RU", "мм", LengthUnit.Millimeter)] + [InlineData("ru-RU", "нм", LengthUnit.Nanometer)] + [InlineData("ru-RU", "пм", LengthUnit.Picometer)] + [InlineData("ru-RU", "ярд", LengthUnit.Yard)] + [InlineData("zh-CN", "厘米", LengthUnit.Centimeter)] + [InlineData("zh-CN", "十米", LengthUnit.Decameter)] + [InlineData("zh-CN", "分米", LengthUnit.Decimeter)] + [InlineData("zh-CN", "飞米", LengthUnit.Femtometer)] + [InlineData("zh-CN", "英尺", LengthUnit.Foot)] + [InlineData("zh-CN", "吉米", LengthUnit.Gigameter)] + [InlineData("zh-CN", "百米", LengthUnit.Hectometer)] + [InlineData("zh-CN", "英寸", LengthUnit.Inch)] + [InlineData("zh-CN", "千英尺", LengthUnit.Kilofoot)] + [InlineData("zh-CN", "千米", LengthUnit.Kilometer)] + [InlineData("zh-CN", "千码", LengthUnit.Kiloyard)] + [InlineData("zh-CN", "兆米", LengthUnit.Megameter)] + [InlineData("zh-CN", "米", LengthUnit.Meter)] + [InlineData("zh-CN", "微英寸", LengthUnit.Microinch)] + [InlineData("zh-CN", "微米", LengthUnit.Micrometer)] + [InlineData("zh-CN", "密耳", LengthUnit.Mil)] + [InlineData("zh-CN", "英里", LengthUnit.Mile)] + [InlineData("zh-CN", "毫米", LengthUnit.Millimeter)] + [InlineData("zh-CN", "皮米", LengthUnit.Picometer)] + [InlineData("zh-CN", "码", LengthUnit.Yard)] + public void ParseUnitWithCulture(string culture, string abbreviation, LengthUnit expectedUnit) + { + LengthUnit parsedUnit = Length.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "pica")] // [DtpPica, PrinterPica] + [InlineData("en-US", "pt")] // [DtpPoint, PrinterPoint] + [InlineData("ru-RU", "мил")] // [Mil, NauticalMile] + [InlineData("zh-CN", "纳米")] // [Nanometer, NauticalMile] + public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) { - { - Assert.True(Length.TryParseUnit("Å", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Angstrom, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("A", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Angstrom, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("au", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.AstronomicalUnit, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("ua", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.AstronomicalUnit, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Centimeter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("см", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Centimeter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("厘米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Centimeter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("ch", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Chain, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("dam", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Decameter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("дам", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Decameter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("十米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Decameter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("дм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Decimeter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("分米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Decimeter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("fathom", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Fathom, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("fm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Femtometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("фм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Femtometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("飞米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Femtometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Foot, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("'", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Foot, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("′", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Foot, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("фут", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Foot, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("英尺", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Foot, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("Gm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Gigameter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("吉米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Gigameter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Hand, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("hh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Hand, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("hm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Hectometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("百米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Hectometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Inch, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("\"", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Inch, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("″", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Inch, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("дюйм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Inch, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("英寸", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Inch, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("kft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kilofoot, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("k'", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kilofoot, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("k′", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kilofoot, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("кфут", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kilofoot, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("千英尺", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kilofoot, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("kly", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.KilolightYear, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kilometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("км", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kilometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("千米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kilometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("kpc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kiloparsec, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("kyd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kiloyard, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("кярд", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kiloyard, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("千码", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Kiloyard, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("ly", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.LightYear, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("Mly", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.MegalightYear, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("兆米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Megameter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("Mpc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Megaparsec, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Meter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("м", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Meter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Meter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("µin", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Microinch, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("микродюйм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Microinch, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("微英寸", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Microinch, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("µm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Micrometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("мкм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Micrometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("微米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Micrometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("mil", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Mil, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("密耳", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Mil, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("mi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Mile, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("миля", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Mile, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("英里", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Mile, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("毫米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Millimeter, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("нм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Nanometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("nmi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.NauticalMile, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("pc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Parsec, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("pm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Picometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("пм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Picometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("皮米", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Picometer, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("shackle", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Shackle, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("R⊙", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.SolarRadius, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("twip", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Twip, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("ftUS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.UsSurveyFoot, parsedUnit); - } - - { - Assert.True(Length.TryParseUnit("yd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LengthUnit.Yard, parsedUnit); - } + Assert.Throws(() => Length.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture))); + } - { - Assert.True(Length.TryParseUnit("ярд", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(LengthUnit.Yard, parsedUnit); - } + [Theory] + [InlineData("Å", LengthUnit.Angstrom)] + [InlineData("A", LengthUnit.Angstrom)] + [InlineData("au", LengthUnit.AstronomicalUnit)] + [InlineData("ua", LengthUnit.AstronomicalUnit)] + [InlineData("cm", LengthUnit.Centimeter)] + [InlineData("ch", LengthUnit.Chain)] + [InlineData("DM", LengthUnit.DataMile)] + [InlineData("dam", LengthUnit.Decameter)] + [InlineData("dm", LengthUnit.Decimeter)] + [InlineData("fathom", LengthUnit.Fathom)] + [InlineData("fm", LengthUnit.Femtometer)] + [InlineData("ft", LengthUnit.Foot)] + [InlineData("'", LengthUnit.Foot)] + [InlineData("′", LengthUnit.Foot)] + [InlineData("Gm", LengthUnit.Gigameter)] + [InlineData("h", LengthUnit.Hand)] + [InlineData("hh", LengthUnit.Hand)] + [InlineData("hm", LengthUnit.Hectometer)] + [InlineData("in", LengthUnit.Inch)] + [InlineData("\"", LengthUnit.Inch)] + [InlineData("″", LengthUnit.Inch)] + [InlineData("kft", LengthUnit.Kilofoot)] + [InlineData("k'", LengthUnit.Kilofoot)] + [InlineData("k′", LengthUnit.Kilofoot)] + [InlineData("kly", LengthUnit.KilolightYear)] + [InlineData("km", LengthUnit.Kilometer)] + [InlineData("kpc", LengthUnit.Kiloparsec)] + [InlineData("kyd", LengthUnit.Kiloyard)] + [InlineData("ly", LengthUnit.LightYear)] + [InlineData("Mly", LengthUnit.MegalightYear)] + [InlineData("Mm", LengthUnit.Megameter)] + [InlineData("Mpc", LengthUnit.Megaparsec)] + [InlineData("m", LengthUnit.Meter)] + [InlineData("µin", LengthUnit.Microinch)] + [InlineData("µm", LengthUnit.Micrometer)] + [InlineData("mil", LengthUnit.Mil)] + [InlineData("mi", LengthUnit.Mile)] + [InlineData("mm", LengthUnit.Millimeter)] + [InlineData("nm", LengthUnit.Nanometer)] + [InlineData("NM", LengthUnit.NauticalMile)] + [InlineData("nmi", LengthUnit.NauticalMile)] + [InlineData("pc", LengthUnit.Parsec)] + [InlineData("pm", LengthUnit.Picometer)] + [InlineData("shackle", LengthUnit.Shackle)] + [InlineData("R⊙", LengthUnit.SolarRadius)] + [InlineData("twip", LengthUnit.Twip)] + [InlineData("ftUS", LengthUnit.UsSurveyFoot)] + [InlineData("yd", LengthUnit.Yard)] + public void TryParseUnit(string abbreviation, LengthUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Length.TryParseUnit(abbreviation, out LengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Length.TryParseUnit("码", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(LengthUnit.Yard, parsedUnit); - } + [Theory] + [InlineData("en-US", "Å", LengthUnit.Angstrom)] + [InlineData("en-US", "A", LengthUnit.Angstrom)] + [InlineData("en-US", "au", LengthUnit.AstronomicalUnit)] + [InlineData("en-US", "ua", LengthUnit.AstronomicalUnit)] + [InlineData("en-US", "cm", LengthUnit.Centimeter)] + [InlineData("en-US", "ch", LengthUnit.Chain)] + [InlineData("en-US", "DM", LengthUnit.DataMile)] + [InlineData("en-US", "dam", LengthUnit.Decameter)] + [InlineData("en-US", "dm", LengthUnit.Decimeter)] + [InlineData("en-US", "fathom", LengthUnit.Fathom)] + [InlineData("en-US", "fm", LengthUnit.Femtometer)] + [InlineData("en-US", "ft", LengthUnit.Foot)] + [InlineData("en-US", "'", LengthUnit.Foot)] + [InlineData("en-US", "′", LengthUnit.Foot)] + [InlineData("en-US", "Gm", LengthUnit.Gigameter)] + [InlineData("en-US", "h", LengthUnit.Hand)] + [InlineData("en-US", "hh", LengthUnit.Hand)] + [InlineData("en-US", "hm", LengthUnit.Hectometer)] + [InlineData("en-US", "in", LengthUnit.Inch)] + [InlineData("en-US", "\"", LengthUnit.Inch)] + [InlineData("en-US", "″", LengthUnit.Inch)] + [InlineData("en-US", "kft", LengthUnit.Kilofoot)] + [InlineData("en-US", "k'", LengthUnit.Kilofoot)] + [InlineData("en-US", "k′", LengthUnit.Kilofoot)] + [InlineData("en-US", "kly", LengthUnit.KilolightYear)] + [InlineData("en-US", "km", LengthUnit.Kilometer)] + [InlineData("en-US", "kpc", LengthUnit.Kiloparsec)] + [InlineData("en-US", "kyd", LengthUnit.Kiloyard)] + [InlineData("en-US", "ly", LengthUnit.LightYear)] + [InlineData("en-US", "Mly", LengthUnit.MegalightYear)] + [InlineData("en-US", "Mm", LengthUnit.Megameter)] + [InlineData("en-US", "Mpc", LengthUnit.Megaparsec)] + [InlineData("en-US", "m", LengthUnit.Meter)] + [InlineData("en-US", "µin", LengthUnit.Microinch)] + [InlineData("en-US", "µm", LengthUnit.Micrometer)] + [InlineData("en-US", "mil", LengthUnit.Mil)] + [InlineData("en-US", "mi", LengthUnit.Mile)] + [InlineData("en-US", "mm", LengthUnit.Millimeter)] + [InlineData("en-US", "nm", LengthUnit.Nanometer)] + [InlineData("en-US", "NM", LengthUnit.NauticalMile)] + [InlineData("en-US", "nmi", LengthUnit.NauticalMile)] + [InlineData("en-US", "pc", LengthUnit.Parsec)] + [InlineData("en-US", "pm", LengthUnit.Picometer)] + [InlineData("en-US", "shackle", LengthUnit.Shackle)] + [InlineData("en-US", "R⊙", LengthUnit.SolarRadius)] + [InlineData("en-US", "twip", LengthUnit.Twip)] + [InlineData("en-US", "ftUS", LengthUnit.UsSurveyFoot)] + [InlineData("en-US", "yd", LengthUnit.Yard)] + [InlineData("ru-RU", "см", LengthUnit.Centimeter)] + [InlineData("ru-RU", "дам", LengthUnit.Decameter)] + [InlineData("ru-RU", "дм", LengthUnit.Decimeter)] + [InlineData("ru-RU", "фм", LengthUnit.Femtometer)] + [InlineData("ru-RU", "фут", LengthUnit.Foot)] + [InlineData("ru-RU", "Гм", LengthUnit.Gigameter)] + [InlineData("ru-RU", "гм", LengthUnit.Hectometer)] + [InlineData("ru-RU", "дюйм", LengthUnit.Inch)] + [InlineData("ru-RU", "кфут", LengthUnit.Kilofoot)] + [InlineData("ru-RU", "км", LengthUnit.Kilometer)] + [InlineData("ru-RU", "кярд", LengthUnit.Kiloyard)] + [InlineData("ru-RU", "Мм", LengthUnit.Megameter)] + [InlineData("ru-RU", "м", LengthUnit.Meter)] + [InlineData("ru-RU", "микродюйм", LengthUnit.Microinch)] + [InlineData("ru-RU", "мкм", LengthUnit.Micrometer)] + [InlineData("ru-RU", "миля", LengthUnit.Mile)] + [InlineData("ru-RU", "мм", LengthUnit.Millimeter)] + [InlineData("ru-RU", "нм", LengthUnit.Nanometer)] + [InlineData("ru-RU", "пм", LengthUnit.Picometer)] + [InlineData("ru-RU", "ярд", LengthUnit.Yard)] + [InlineData("zh-CN", "厘米", LengthUnit.Centimeter)] + [InlineData("zh-CN", "十米", LengthUnit.Decameter)] + [InlineData("zh-CN", "分米", LengthUnit.Decimeter)] + [InlineData("zh-CN", "飞米", LengthUnit.Femtometer)] + [InlineData("zh-CN", "英尺", LengthUnit.Foot)] + [InlineData("zh-CN", "吉米", LengthUnit.Gigameter)] + [InlineData("zh-CN", "百米", LengthUnit.Hectometer)] + [InlineData("zh-CN", "英寸", LengthUnit.Inch)] + [InlineData("zh-CN", "千英尺", LengthUnit.Kilofoot)] + [InlineData("zh-CN", "千米", LengthUnit.Kilometer)] + [InlineData("zh-CN", "千码", LengthUnit.Kiloyard)] + [InlineData("zh-CN", "兆米", LengthUnit.Megameter)] + [InlineData("zh-CN", "米", LengthUnit.Meter)] + [InlineData("zh-CN", "微英寸", LengthUnit.Microinch)] + [InlineData("zh-CN", "微米", LengthUnit.Micrometer)] + [InlineData("zh-CN", "密耳", LengthUnit.Mil)] + [InlineData("zh-CN", "英里", LengthUnit.Mile)] + [InlineData("zh-CN", "毫米", LengthUnit.Millimeter)] + [InlineData("zh-CN", "皮米", LengthUnit.Picometer)] + [InlineData("zh-CN", "码", LengthUnit.Yard)] + public void TryParseUnitWithCulture(string culture, string abbreviation, LengthUnit expectedUnit) + { + Assert.True(Length.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "pica")] // [DtpPica, PrinterPica] + [InlineData("en-US", "pt")] // [DtpPoint, PrinterPoint] + [InlineData("ru-RU", "мил")] // [Mil, NauticalMile] + [InlineData("zh-CN", "纳米")] // [Nanometer, NauticalMile] + public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) + { + Assert.False(Length.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out _)); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs index 7223411046..19aa857c9f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs @@ -223,36 +223,42 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("dB", LevelUnit.Decibel)] + [InlineData("Np", LevelUnit.Neper)] + public void ParseUnit(string abbreviation, LevelUnit expectedUnit) { - try - { - var parsedUnit = Level.ParseUnit("dB", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LevelUnit.Decibel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Level.ParseUnit("Np", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LevelUnit.Neper, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + LevelUnit parsedUnit = Level.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "dB", LevelUnit.Decibel)] + [InlineData("en-US", "Np", LevelUnit.Neper)] + public void ParseUnitWithCulture(string culture, string abbreviation, LevelUnit expectedUnit) { - { - Assert.True(Level.TryParseUnit("dB", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LevelUnit.Decibel, parsedUnit); - } + LevelUnit parsedUnit = Level.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Level.TryParseUnit("Np", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LevelUnit.Neper, parsedUnit); - } + [Theory] + [InlineData("dB", LevelUnit.Decibel)] + [InlineData("Np", LevelUnit.Neper)] + public void TryParseUnit(string abbreviation, LevelUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Level.TryParseUnit(abbreviation, out LevelUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "dB", LevelUnit.Decibel)] + [InlineData("en-US", "Np", LevelUnit.Neper)] + public void TryParseUnitWithCulture(string culture, string abbreviation, LevelUnit expectedUnit) + { + Assert.True(Level.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LevelUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs index 2fb3cb4715..339679b470 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs @@ -591,212 +591,106 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = LinearDensity.ParseUnit("g/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.GramPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("g/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.GramPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("g/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.GramPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("g/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.GramPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("kg/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.KilogramPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("kg/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.KilogramPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("kg/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.KilogramPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("kg/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.KilogramPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("µg/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.MicrogramPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("µg/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.MicrogramPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("µg/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.MicrogramPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("µg/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.MicrogramPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("mg/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.MilligramPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("mg/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.MilligramPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("mg/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.MilligramPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("mg/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.MilligramPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("lb/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.PoundPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearDensity.ParseUnit("lb/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearDensityUnit.PoundPerInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("g/cm", LinearDensityUnit.GramPerCentimeter)] + [InlineData("g/ft", LinearDensityUnit.GramPerFoot)] + [InlineData("g/m", LinearDensityUnit.GramPerMeter)] + [InlineData("g/mm", LinearDensityUnit.GramPerMillimeter)] + [InlineData("kg/cm", LinearDensityUnit.KilogramPerCentimeter)] + [InlineData("kg/ft", LinearDensityUnit.KilogramPerFoot)] + [InlineData("kg/m", LinearDensityUnit.KilogramPerMeter)] + [InlineData("kg/mm", LinearDensityUnit.KilogramPerMillimeter)] + [InlineData("µg/cm", LinearDensityUnit.MicrogramPerCentimeter)] + [InlineData("µg/ft", LinearDensityUnit.MicrogramPerFoot)] + [InlineData("µg/m", LinearDensityUnit.MicrogramPerMeter)] + [InlineData("µg/mm", LinearDensityUnit.MicrogramPerMillimeter)] + [InlineData("mg/cm", LinearDensityUnit.MilligramPerCentimeter)] + [InlineData("mg/ft", LinearDensityUnit.MilligramPerFoot)] + [InlineData("mg/m", LinearDensityUnit.MilligramPerMeter)] + [InlineData("mg/mm", LinearDensityUnit.MilligramPerMillimeter)] + [InlineData("lb/ft", LinearDensityUnit.PoundPerFoot)] + [InlineData("lb/in", LinearDensityUnit.PoundPerInch)] + public void ParseUnit(string abbreviation, LinearDensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + LinearDensityUnit parsedUnit = LinearDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(LinearDensity.TryParseUnit("g/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.GramPerCentimeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("g/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.GramPerFoot, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("g/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.GramPerMeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("g/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.GramPerMillimeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("kg/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.KilogramPerCentimeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("kg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.KilogramPerFoot, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("kg/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.KilogramPerMeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("kg/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.KilogramPerMillimeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("µg/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.MicrogramPerCentimeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("µg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.MicrogramPerFoot, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("µg/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.MicrogramPerMeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("µg/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.MicrogramPerMillimeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("mg/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.MilligramPerCentimeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("mg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.MilligramPerFoot, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("mg/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.MilligramPerMeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("mg/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.MilligramPerMillimeter, parsedUnit); - } - - { - Assert.True(LinearDensity.TryParseUnit("lb/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.PoundPerFoot, parsedUnit); - } + [Theory] + [InlineData("en-US", "g/cm", LinearDensityUnit.GramPerCentimeter)] + [InlineData("en-US", "g/ft", LinearDensityUnit.GramPerFoot)] + [InlineData("en-US", "g/m", LinearDensityUnit.GramPerMeter)] + [InlineData("en-US", "g/mm", LinearDensityUnit.GramPerMillimeter)] + [InlineData("en-US", "kg/cm", LinearDensityUnit.KilogramPerCentimeter)] + [InlineData("en-US", "kg/ft", LinearDensityUnit.KilogramPerFoot)] + [InlineData("en-US", "kg/m", LinearDensityUnit.KilogramPerMeter)] + [InlineData("en-US", "kg/mm", LinearDensityUnit.KilogramPerMillimeter)] + [InlineData("en-US", "µg/cm", LinearDensityUnit.MicrogramPerCentimeter)] + [InlineData("en-US", "µg/ft", LinearDensityUnit.MicrogramPerFoot)] + [InlineData("en-US", "µg/m", LinearDensityUnit.MicrogramPerMeter)] + [InlineData("en-US", "µg/mm", LinearDensityUnit.MicrogramPerMillimeter)] + [InlineData("en-US", "mg/cm", LinearDensityUnit.MilligramPerCentimeter)] + [InlineData("en-US", "mg/ft", LinearDensityUnit.MilligramPerFoot)] + [InlineData("en-US", "mg/m", LinearDensityUnit.MilligramPerMeter)] + [InlineData("en-US", "mg/mm", LinearDensityUnit.MilligramPerMillimeter)] + [InlineData("en-US", "lb/ft", LinearDensityUnit.PoundPerFoot)] + [InlineData("en-US", "lb/in", LinearDensityUnit.PoundPerInch)] + public void ParseUnitWithCulture(string culture, string abbreviation, LinearDensityUnit expectedUnit) + { + LinearDensityUnit parsedUnit = LinearDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(LinearDensity.TryParseUnit("lb/in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearDensityUnit.PoundPerInch, parsedUnit); - } + [Theory] + [InlineData("g/cm", LinearDensityUnit.GramPerCentimeter)] + [InlineData("g/ft", LinearDensityUnit.GramPerFoot)] + [InlineData("g/m", LinearDensityUnit.GramPerMeter)] + [InlineData("g/mm", LinearDensityUnit.GramPerMillimeter)] + [InlineData("kg/cm", LinearDensityUnit.KilogramPerCentimeter)] + [InlineData("kg/ft", LinearDensityUnit.KilogramPerFoot)] + [InlineData("kg/m", LinearDensityUnit.KilogramPerMeter)] + [InlineData("kg/mm", LinearDensityUnit.KilogramPerMillimeter)] + [InlineData("µg/cm", LinearDensityUnit.MicrogramPerCentimeter)] + [InlineData("µg/ft", LinearDensityUnit.MicrogramPerFoot)] + [InlineData("µg/m", LinearDensityUnit.MicrogramPerMeter)] + [InlineData("µg/mm", LinearDensityUnit.MicrogramPerMillimeter)] + [InlineData("mg/cm", LinearDensityUnit.MilligramPerCentimeter)] + [InlineData("mg/ft", LinearDensityUnit.MilligramPerFoot)] + [InlineData("mg/m", LinearDensityUnit.MilligramPerMeter)] + [InlineData("mg/mm", LinearDensityUnit.MilligramPerMillimeter)] + [InlineData("lb/ft", LinearDensityUnit.PoundPerFoot)] + [InlineData("lb/in", LinearDensityUnit.PoundPerInch)] + public void TryParseUnit(string abbreviation, LinearDensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(LinearDensity.TryParseUnit(abbreviation, out LinearDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "g/cm", LinearDensityUnit.GramPerCentimeter)] + [InlineData("en-US", "g/ft", LinearDensityUnit.GramPerFoot)] + [InlineData("en-US", "g/m", LinearDensityUnit.GramPerMeter)] + [InlineData("en-US", "g/mm", LinearDensityUnit.GramPerMillimeter)] + [InlineData("en-US", "kg/cm", LinearDensityUnit.KilogramPerCentimeter)] + [InlineData("en-US", "kg/ft", LinearDensityUnit.KilogramPerFoot)] + [InlineData("en-US", "kg/m", LinearDensityUnit.KilogramPerMeter)] + [InlineData("en-US", "kg/mm", LinearDensityUnit.KilogramPerMillimeter)] + [InlineData("en-US", "µg/cm", LinearDensityUnit.MicrogramPerCentimeter)] + [InlineData("en-US", "µg/ft", LinearDensityUnit.MicrogramPerFoot)] + [InlineData("en-US", "µg/m", LinearDensityUnit.MicrogramPerMeter)] + [InlineData("en-US", "µg/mm", LinearDensityUnit.MicrogramPerMillimeter)] + [InlineData("en-US", "mg/cm", LinearDensityUnit.MilligramPerCentimeter)] + [InlineData("en-US", "mg/ft", LinearDensityUnit.MilligramPerFoot)] + [InlineData("en-US", "mg/m", LinearDensityUnit.MilligramPerMeter)] + [InlineData("en-US", "mg/mm", LinearDensityUnit.MilligramPerMillimeter)] + [InlineData("en-US", "lb/ft", LinearDensityUnit.PoundPerFoot)] + [InlineData("en-US", "lb/in", LinearDensityUnit.PoundPerInch)] + public void TryParseUnitWithCulture(string culture, string abbreviation, LinearDensityUnit expectedUnit) + { + Assert.True(LinearDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LinearDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs index 7e95ed9c15..3fb096c5e2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs @@ -692,239 +692,134 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("GW/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.GigawattPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("GW/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.GigawattPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("GW/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.GigawattPerInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("GW/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.GigawattPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("GW/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.GigawattPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("kW/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.KilowattPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("kW/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.KilowattPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("kW/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.KilowattPerInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("kW/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.KilowattPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("kW/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.KilowattPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("MW/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.MegawattPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("MW/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.MegawattPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("MW/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.MegawattPerInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("MW/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.MegawattPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("MW/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.MegawattPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("mW/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.MilliwattPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("mW/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.MilliwattPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("mW/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.MilliwattPerInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("mW/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.MilliwattPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("mW/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.MilliwattPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("W/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.WattPerCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("W/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.WattPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("W/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.WattPerInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("W/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.WattPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = LinearPowerDensity.ParseUnit("W/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LinearPowerDensityUnit.WattPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("GW/cm", LinearPowerDensityUnit.GigawattPerCentimeter)] + [InlineData("GW/ft", LinearPowerDensityUnit.GigawattPerFoot)] + [InlineData("GW/in", LinearPowerDensityUnit.GigawattPerInch)] + [InlineData("GW/m", LinearPowerDensityUnit.GigawattPerMeter)] + [InlineData("GW/mm", LinearPowerDensityUnit.GigawattPerMillimeter)] + [InlineData("kW/cm", LinearPowerDensityUnit.KilowattPerCentimeter)] + [InlineData("kW/ft", LinearPowerDensityUnit.KilowattPerFoot)] + [InlineData("kW/in", LinearPowerDensityUnit.KilowattPerInch)] + [InlineData("kW/m", LinearPowerDensityUnit.KilowattPerMeter)] + [InlineData("kW/mm", LinearPowerDensityUnit.KilowattPerMillimeter)] + [InlineData("MW/cm", LinearPowerDensityUnit.MegawattPerCentimeter)] + [InlineData("MW/ft", LinearPowerDensityUnit.MegawattPerFoot)] + [InlineData("MW/in", LinearPowerDensityUnit.MegawattPerInch)] + [InlineData("MW/m", LinearPowerDensityUnit.MegawattPerMeter)] + [InlineData("MW/mm", LinearPowerDensityUnit.MegawattPerMillimeter)] + [InlineData("mW/cm", LinearPowerDensityUnit.MilliwattPerCentimeter)] + [InlineData("mW/ft", LinearPowerDensityUnit.MilliwattPerFoot)] + [InlineData("mW/in", LinearPowerDensityUnit.MilliwattPerInch)] + [InlineData("mW/m", LinearPowerDensityUnit.MilliwattPerMeter)] + [InlineData("mW/mm", LinearPowerDensityUnit.MilliwattPerMillimeter)] + [InlineData("W/cm", LinearPowerDensityUnit.WattPerCentimeter)] + [InlineData("W/ft", LinearPowerDensityUnit.WattPerFoot)] + [InlineData("W/in", LinearPowerDensityUnit.WattPerInch)] + [InlineData("W/m", LinearPowerDensityUnit.WattPerMeter)] + [InlineData("W/mm", LinearPowerDensityUnit.WattPerMillimeter)] + public void ParseUnit(string abbreviation, LinearPowerDensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + LinearPowerDensityUnit parsedUnit = LinearPowerDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(LinearPowerDensity.TryParseUnit("GW/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.GigawattPerCentimeter, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("GW/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.GigawattPerFoot, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("GW/in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.GigawattPerInch, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("GW/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.GigawattPerMeter, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("GW/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.GigawattPerMillimeter, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("kW/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.KilowattPerCentimeter, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("kW/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.KilowattPerFoot, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("kW/in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.KilowattPerInch, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("kW/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.KilowattPerMeter, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("kW/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.KilowattPerMillimeter, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("W/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.WattPerCentimeter, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("W/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.WattPerFoot, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("W/in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.WattPerInch, parsedUnit); - } - - { - Assert.True(LinearPowerDensity.TryParseUnit("W/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.WattPerMeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "GW/cm", LinearPowerDensityUnit.GigawattPerCentimeter)] + [InlineData("en-US", "GW/ft", LinearPowerDensityUnit.GigawattPerFoot)] + [InlineData("en-US", "GW/in", LinearPowerDensityUnit.GigawattPerInch)] + [InlineData("en-US", "GW/m", LinearPowerDensityUnit.GigawattPerMeter)] + [InlineData("en-US", "GW/mm", LinearPowerDensityUnit.GigawattPerMillimeter)] + [InlineData("en-US", "kW/cm", LinearPowerDensityUnit.KilowattPerCentimeter)] + [InlineData("en-US", "kW/ft", LinearPowerDensityUnit.KilowattPerFoot)] + [InlineData("en-US", "kW/in", LinearPowerDensityUnit.KilowattPerInch)] + [InlineData("en-US", "kW/m", LinearPowerDensityUnit.KilowattPerMeter)] + [InlineData("en-US", "kW/mm", LinearPowerDensityUnit.KilowattPerMillimeter)] + [InlineData("en-US", "MW/cm", LinearPowerDensityUnit.MegawattPerCentimeter)] + [InlineData("en-US", "MW/ft", LinearPowerDensityUnit.MegawattPerFoot)] + [InlineData("en-US", "MW/in", LinearPowerDensityUnit.MegawattPerInch)] + [InlineData("en-US", "MW/m", LinearPowerDensityUnit.MegawattPerMeter)] + [InlineData("en-US", "MW/mm", LinearPowerDensityUnit.MegawattPerMillimeter)] + [InlineData("en-US", "mW/cm", LinearPowerDensityUnit.MilliwattPerCentimeter)] + [InlineData("en-US", "mW/ft", LinearPowerDensityUnit.MilliwattPerFoot)] + [InlineData("en-US", "mW/in", LinearPowerDensityUnit.MilliwattPerInch)] + [InlineData("en-US", "mW/m", LinearPowerDensityUnit.MilliwattPerMeter)] + [InlineData("en-US", "mW/mm", LinearPowerDensityUnit.MilliwattPerMillimeter)] + [InlineData("en-US", "W/cm", LinearPowerDensityUnit.WattPerCentimeter)] + [InlineData("en-US", "W/ft", LinearPowerDensityUnit.WattPerFoot)] + [InlineData("en-US", "W/in", LinearPowerDensityUnit.WattPerInch)] + [InlineData("en-US", "W/m", LinearPowerDensityUnit.WattPerMeter)] + [InlineData("en-US", "W/mm", LinearPowerDensityUnit.WattPerMillimeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, LinearPowerDensityUnit expectedUnit) + { + LinearPowerDensityUnit parsedUnit = LinearPowerDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(LinearPowerDensity.TryParseUnit("W/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LinearPowerDensityUnit.WattPerMillimeter, parsedUnit); - } + [Theory] + [InlineData("GW/cm", LinearPowerDensityUnit.GigawattPerCentimeter)] + [InlineData("GW/ft", LinearPowerDensityUnit.GigawattPerFoot)] + [InlineData("GW/in", LinearPowerDensityUnit.GigawattPerInch)] + [InlineData("GW/m", LinearPowerDensityUnit.GigawattPerMeter)] + [InlineData("GW/mm", LinearPowerDensityUnit.GigawattPerMillimeter)] + [InlineData("kW/cm", LinearPowerDensityUnit.KilowattPerCentimeter)] + [InlineData("kW/ft", LinearPowerDensityUnit.KilowattPerFoot)] + [InlineData("kW/in", LinearPowerDensityUnit.KilowattPerInch)] + [InlineData("kW/m", LinearPowerDensityUnit.KilowattPerMeter)] + [InlineData("kW/mm", LinearPowerDensityUnit.KilowattPerMillimeter)] + [InlineData("MW/cm", LinearPowerDensityUnit.MegawattPerCentimeter)] + [InlineData("MW/ft", LinearPowerDensityUnit.MegawattPerFoot)] + [InlineData("MW/in", LinearPowerDensityUnit.MegawattPerInch)] + [InlineData("MW/m", LinearPowerDensityUnit.MegawattPerMeter)] + [InlineData("MW/mm", LinearPowerDensityUnit.MegawattPerMillimeter)] + [InlineData("mW/cm", LinearPowerDensityUnit.MilliwattPerCentimeter)] + [InlineData("mW/ft", LinearPowerDensityUnit.MilliwattPerFoot)] + [InlineData("mW/in", LinearPowerDensityUnit.MilliwattPerInch)] + [InlineData("mW/m", LinearPowerDensityUnit.MilliwattPerMeter)] + [InlineData("mW/mm", LinearPowerDensityUnit.MilliwattPerMillimeter)] + [InlineData("W/cm", LinearPowerDensityUnit.WattPerCentimeter)] + [InlineData("W/ft", LinearPowerDensityUnit.WattPerFoot)] + [InlineData("W/in", LinearPowerDensityUnit.WattPerInch)] + [InlineData("W/m", LinearPowerDensityUnit.WattPerMeter)] + [InlineData("W/mm", LinearPowerDensityUnit.WattPerMillimeter)] + public void TryParseUnit(string abbreviation, LinearPowerDensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(LinearPowerDensity.TryParseUnit(abbreviation, out LinearPowerDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "GW/cm", LinearPowerDensityUnit.GigawattPerCentimeter)] + [InlineData("en-US", "GW/ft", LinearPowerDensityUnit.GigawattPerFoot)] + [InlineData("en-US", "GW/in", LinearPowerDensityUnit.GigawattPerInch)] + [InlineData("en-US", "GW/m", LinearPowerDensityUnit.GigawattPerMeter)] + [InlineData("en-US", "GW/mm", LinearPowerDensityUnit.GigawattPerMillimeter)] + [InlineData("en-US", "kW/cm", LinearPowerDensityUnit.KilowattPerCentimeter)] + [InlineData("en-US", "kW/ft", LinearPowerDensityUnit.KilowattPerFoot)] + [InlineData("en-US", "kW/in", LinearPowerDensityUnit.KilowattPerInch)] + [InlineData("en-US", "kW/m", LinearPowerDensityUnit.KilowattPerMeter)] + [InlineData("en-US", "kW/mm", LinearPowerDensityUnit.KilowattPerMillimeter)] + [InlineData("en-US", "MW/cm", LinearPowerDensityUnit.MegawattPerCentimeter)] + [InlineData("en-US", "MW/ft", LinearPowerDensityUnit.MegawattPerFoot)] + [InlineData("en-US", "MW/in", LinearPowerDensityUnit.MegawattPerInch)] + [InlineData("en-US", "MW/m", LinearPowerDensityUnit.MegawattPerMeter)] + [InlineData("en-US", "MW/mm", LinearPowerDensityUnit.MegawattPerMillimeter)] + [InlineData("en-US", "mW/cm", LinearPowerDensityUnit.MilliwattPerCentimeter)] + [InlineData("en-US", "mW/ft", LinearPowerDensityUnit.MilliwattPerFoot)] + [InlineData("en-US", "mW/in", LinearPowerDensityUnit.MilliwattPerInch)] + [InlineData("en-US", "mW/m", LinearPowerDensityUnit.MilliwattPerMeter)] + [InlineData("en-US", "mW/mm", LinearPowerDensityUnit.MilliwattPerMillimeter)] + [InlineData("en-US", "W/cm", LinearPowerDensityUnit.WattPerCentimeter)] + [InlineData("en-US", "W/ft", LinearPowerDensityUnit.WattPerFoot)] + [InlineData("en-US", "W/in", LinearPowerDensityUnit.WattPerInch)] + [InlineData("en-US", "W/m", LinearPowerDensityUnit.WattPerMeter)] + [InlineData("en-US", "W/mm", LinearPowerDensityUnit.WattPerMillimeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, LinearPowerDensityUnit expectedUnit) + { + Assert.True(LinearPowerDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LinearPowerDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs index 5753e5396e..51a3590034 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs @@ -407,124 +407,74 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Luminance.ParseUnit("Cd/ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminanceUnit.CandelaPerSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminance.ParseUnit("Cd/in²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminanceUnit.CandelaPerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminance.ParseUnit("Cd/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminanceUnit.CandelaPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminance.ParseUnit("cCd/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminanceUnit.CenticandelaPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminance.ParseUnit("dCd/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminanceUnit.DecicandelaPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminance.ParseUnit("kCd/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminanceUnit.KilocandelaPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminance.ParseUnit("µCd/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminanceUnit.MicrocandelaPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminance.ParseUnit("mCd/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminanceUnit.MillicandelaPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminance.ParseUnit("nCd/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminanceUnit.NanocandelaPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminance.ParseUnit("nt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminanceUnit.Nit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("Cd/ft²", LuminanceUnit.CandelaPerSquareFoot)] + [InlineData("Cd/in²", LuminanceUnit.CandelaPerSquareInch)] + [InlineData("Cd/m²", LuminanceUnit.CandelaPerSquareMeter)] + [InlineData("cCd/m²", LuminanceUnit.CenticandelaPerSquareMeter)] + [InlineData("dCd/m²", LuminanceUnit.DecicandelaPerSquareMeter)] + [InlineData("kCd/m²", LuminanceUnit.KilocandelaPerSquareMeter)] + [InlineData("µCd/m²", LuminanceUnit.MicrocandelaPerSquareMeter)] + [InlineData("mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] + [InlineData("nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] + [InlineData("nt", LuminanceUnit.Nit)] + public void ParseUnit(string abbreviation, LuminanceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + LuminanceUnit parsedUnit = Luminance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Luminance.TryParseUnit("Cd/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminanceUnit.CandelaPerSquareFoot, parsedUnit); - } - - { - Assert.True(Luminance.TryParseUnit("Cd/in²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminanceUnit.CandelaPerSquareInch, parsedUnit); - } - - { - Assert.True(Luminance.TryParseUnit("Cd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminanceUnit.CandelaPerSquareMeter, parsedUnit); - } - - { - Assert.True(Luminance.TryParseUnit("cCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminanceUnit.CenticandelaPerSquareMeter, parsedUnit); - } - - { - Assert.True(Luminance.TryParseUnit("dCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminanceUnit.DecicandelaPerSquareMeter, parsedUnit); - } - - { - Assert.True(Luminance.TryParseUnit("kCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminanceUnit.KilocandelaPerSquareMeter, parsedUnit); - } - - { - Assert.True(Luminance.TryParseUnit("µCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminanceUnit.MicrocandelaPerSquareMeter, parsedUnit); - } - - { - Assert.True(Luminance.TryParseUnit("mCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminanceUnit.MillicandelaPerSquareMeter, parsedUnit); - } - - { - Assert.True(Luminance.TryParseUnit("nCd/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminanceUnit.NanocandelaPerSquareMeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "Cd/ft²", LuminanceUnit.CandelaPerSquareFoot)] + [InlineData("en-US", "Cd/in²", LuminanceUnit.CandelaPerSquareInch)] + [InlineData("en-US", "Cd/m²", LuminanceUnit.CandelaPerSquareMeter)] + [InlineData("en-US", "cCd/m²", LuminanceUnit.CenticandelaPerSquareMeter)] + [InlineData("en-US", "dCd/m²", LuminanceUnit.DecicandelaPerSquareMeter)] + [InlineData("en-US", "kCd/m²", LuminanceUnit.KilocandelaPerSquareMeter)] + [InlineData("en-US", "µCd/m²", LuminanceUnit.MicrocandelaPerSquareMeter)] + [InlineData("en-US", "mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] + [InlineData("en-US", "nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] + [InlineData("en-US", "nt", LuminanceUnit.Nit)] + public void ParseUnitWithCulture(string culture, string abbreviation, LuminanceUnit expectedUnit) + { + LuminanceUnit parsedUnit = Luminance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Luminance.TryParseUnit("nt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminanceUnit.Nit, parsedUnit); - } + [Theory] + [InlineData("Cd/ft²", LuminanceUnit.CandelaPerSquareFoot)] + [InlineData("Cd/in²", LuminanceUnit.CandelaPerSquareInch)] + [InlineData("Cd/m²", LuminanceUnit.CandelaPerSquareMeter)] + [InlineData("cCd/m²", LuminanceUnit.CenticandelaPerSquareMeter)] + [InlineData("dCd/m²", LuminanceUnit.DecicandelaPerSquareMeter)] + [InlineData("kCd/m²", LuminanceUnit.KilocandelaPerSquareMeter)] + [InlineData("µCd/m²", LuminanceUnit.MicrocandelaPerSquareMeter)] + [InlineData("mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] + [InlineData("nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] + [InlineData("nt", LuminanceUnit.Nit)] + public void TryParseUnit(string abbreviation, LuminanceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Luminance.TryParseUnit(abbreviation, out LuminanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "Cd/ft²", LuminanceUnit.CandelaPerSquareFoot)] + [InlineData("en-US", "Cd/in²", LuminanceUnit.CandelaPerSquareInch)] + [InlineData("en-US", "Cd/m²", LuminanceUnit.CandelaPerSquareMeter)] + [InlineData("en-US", "cCd/m²", LuminanceUnit.CenticandelaPerSquareMeter)] + [InlineData("en-US", "dCd/m²", LuminanceUnit.DecicandelaPerSquareMeter)] + [InlineData("en-US", "kCd/m²", LuminanceUnit.KilocandelaPerSquareMeter)] + [InlineData("en-US", "µCd/m²", LuminanceUnit.MicrocandelaPerSquareMeter)] + [InlineData("en-US", "mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] + [InlineData("en-US", "nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] + [InlineData("en-US", "nt", LuminanceUnit.Nit)] + public void TryParseUnitWithCulture(string culture, string abbreviation, LuminanceUnit expectedUnit) + { + Assert.True(Luminance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LuminanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs index 2ad218bfd9..50aebd008a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs @@ -475,148 +475,90 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Luminosity.ParseUnit("daW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Decawatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("dW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Deciwatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("fW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Femtowatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("GW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Gigawatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("kW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Kilowatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("MW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Megawatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("µW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Microwatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("mW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Milliwatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("nW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Nanowatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("PW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Petawatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("pW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Picowatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("L⊙", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.SolarLuminosity, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("TW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Terawatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Luminosity.ParseUnit("W", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminosityUnit.Watt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("daW", LuminosityUnit.Decawatt)] + [InlineData("dW", LuminosityUnit.Deciwatt)] + [InlineData("fW", LuminosityUnit.Femtowatt)] + [InlineData("GW", LuminosityUnit.Gigawatt)] + [InlineData("kW", LuminosityUnit.Kilowatt)] + [InlineData("MW", LuminosityUnit.Megawatt)] + [InlineData("µW", LuminosityUnit.Microwatt)] + [InlineData("mW", LuminosityUnit.Milliwatt)] + [InlineData("nW", LuminosityUnit.Nanowatt)] + [InlineData("PW", LuminosityUnit.Petawatt)] + [InlineData("pW", LuminosityUnit.Picowatt)] + [InlineData("L⊙", LuminosityUnit.SolarLuminosity)] + [InlineData("TW", LuminosityUnit.Terawatt)] + [InlineData("W", LuminosityUnit.Watt)] + public void ParseUnit(string abbreviation, LuminosityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + LuminosityUnit parsedUnit = Luminosity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Luminosity.TryParseUnit("daW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminosityUnit.Decawatt, parsedUnit); - } - - { - Assert.True(Luminosity.TryParseUnit("dW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminosityUnit.Deciwatt, parsedUnit); - } - - { - Assert.True(Luminosity.TryParseUnit("fW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminosityUnit.Femtowatt, parsedUnit); - } - - { - Assert.True(Luminosity.TryParseUnit("GW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminosityUnit.Gigawatt, parsedUnit); - } - - { - Assert.True(Luminosity.TryParseUnit("kW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminosityUnit.Kilowatt, parsedUnit); - } - - { - Assert.True(Luminosity.TryParseUnit("µW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminosityUnit.Microwatt, parsedUnit); - } - - { - Assert.True(Luminosity.TryParseUnit("nW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminosityUnit.Nanowatt, parsedUnit); - } - - { - Assert.True(Luminosity.TryParseUnit("L⊙", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminosityUnit.SolarLuminosity, parsedUnit); - } - - { - Assert.True(Luminosity.TryParseUnit("TW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminosityUnit.Terawatt, parsedUnit); - } + [Theory] + [InlineData("en-US", "daW", LuminosityUnit.Decawatt)] + [InlineData("en-US", "dW", LuminosityUnit.Deciwatt)] + [InlineData("en-US", "fW", LuminosityUnit.Femtowatt)] + [InlineData("en-US", "GW", LuminosityUnit.Gigawatt)] + [InlineData("en-US", "kW", LuminosityUnit.Kilowatt)] + [InlineData("en-US", "MW", LuminosityUnit.Megawatt)] + [InlineData("en-US", "µW", LuminosityUnit.Microwatt)] + [InlineData("en-US", "mW", LuminosityUnit.Milliwatt)] + [InlineData("en-US", "nW", LuminosityUnit.Nanowatt)] + [InlineData("en-US", "PW", LuminosityUnit.Petawatt)] + [InlineData("en-US", "pW", LuminosityUnit.Picowatt)] + [InlineData("en-US", "L⊙", LuminosityUnit.SolarLuminosity)] + [InlineData("en-US", "TW", LuminosityUnit.Terawatt)] + [InlineData("en-US", "W", LuminosityUnit.Watt)] + public void ParseUnitWithCulture(string culture, string abbreviation, LuminosityUnit expectedUnit) + { + LuminosityUnit parsedUnit = Luminosity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Luminosity.TryParseUnit("W", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminosityUnit.Watt, parsedUnit); - } + [Theory] + [InlineData("daW", LuminosityUnit.Decawatt)] + [InlineData("dW", LuminosityUnit.Deciwatt)] + [InlineData("fW", LuminosityUnit.Femtowatt)] + [InlineData("GW", LuminosityUnit.Gigawatt)] + [InlineData("kW", LuminosityUnit.Kilowatt)] + [InlineData("MW", LuminosityUnit.Megawatt)] + [InlineData("µW", LuminosityUnit.Microwatt)] + [InlineData("mW", LuminosityUnit.Milliwatt)] + [InlineData("nW", LuminosityUnit.Nanowatt)] + [InlineData("PW", LuminosityUnit.Petawatt)] + [InlineData("pW", LuminosityUnit.Picowatt)] + [InlineData("L⊙", LuminosityUnit.SolarLuminosity)] + [InlineData("TW", LuminosityUnit.Terawatt)] + [InlineData("W", LuminosityUnit.Watt)] + public void TryParseUnit(string abbreviation, LuminosityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Luminosity.TryParseUnit(abbreviation, out LuminosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "daW", LuminosityUnit.Decawatt)] + [InlineData("en-US", "dW", LuminosityUnit.Deciwatt)] + [InlineData("en-US", "fW", LuminosityUnit.Femtowatt)] + [InlineData("en-US", "GW", LuminosityUnit.Gigawatt)] + [InlineData("en-US", "kW", LuminosityUnit.Kilowatt)] + [InlineData("en-US", "MW", LuminosityUnit.Megawatt)] + [InlineData("en-US", "µW", LuminosityUnit.Microwatt)] + [InlineData("en-US", "mW", LuminosityUnit.Milliwatt)] + [InlineData("en-US", "nW", LuminosityUnit.Nanowatt)] + [InlineData("en-US", "PW", LuminosityUnit.Petawatt)] + [InlineData("en-US", "pW", LuminosityUnit.Picowatt)] + [InlineData("en-US", "L⊙", LuminosityUnit.SolarLuminosity)] + [InlineData("en-US", "TW", LuminosityUnit.Terawatt)] + [InlineData("en-US", "W", LuminosityUnit.Watt)] + public void TryParseUnitWithCulture(string culture, string abbreviation, LuminosityUnit expectedUnit) + { + Assert.True(Luminosity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LuminosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs index b75595c081..9a451c665b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("lm", LuminousFluxUnit.Lumen)] + public void ParseUnit(string abbreviation, LuminousFluxUnit expectedUnit) { - try - { - var parsedUnit = LuminousFlux.ParseUnit("lm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminousFluxUnit.Lumen, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + LuminousFluxUnit parsedUnit = LuminousFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "lm", LuminousFluxUnit.Lumen)] + public void ParseUnitWithCulture(string culture, string abbreviation, LuminousFluxUnit expectedUnit) + { + LuminousFluxUnit parsedUnit = LuminousFlux.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("lm", LuminousFluxUnit.Lumen)] + public void TryParseUnit(string abbreviation, LuminousFluxUnit expectedUnit) { - { - Assert.True(LuminousFlux.TryParseUnit("lm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminousFluxUnit.Lumen, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(LuminousFlux.TryParseUnit(abbreviation, out LuminousFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "lm", LuminousFluxUnit.Lumen)] + public void TryParseUnitWithCulture(string culture, string abbreviation, LuminousFluxUnit expectedUnit) + { + Assert.True(LuminousFlux.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LuminousFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs index 68cec786e8..5c6f38d55d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("cd", LuminousIntensityUnit.Candela)] + public void ParseUnit(string abbreviation, LuminousIntensityUnit expectedUnit) { - try - { - var parsedUnit = LuminousIntensity.ParseUnit("cd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(LuminousIntensityUnit.Candela, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + LuminousIntensityUnit parsedUnit = LuminousIntensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cd", LuminousIntensityUnit.Candela)] + public void ParseUnitWithCulture(string culture, string abbreviation, LuminousIntensityUnit expectedUnit) + { + LuminousIntensityUnit parsedUnit = LuminousIntensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("cd", LuminousIntensityUnit.Candela)] + public void TryParseUnit(string abbreviation, LuminousIntensityUnit expectedUnit) { - { - Assert.True(LuminousIntensity.TryParseUnit("cd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(LuminousIntensityUnit.Candela, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(LuminousIntensity.TryParseUnit(abbreviation, out LuminousIntensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cd", LuminousIntensityUnit.Candela)] + public void TryParseUnitWithCulture(string culture, string abbreviation, LuminousIntensityUnit expectedUnit) + { + Assert.True(LuminousIntensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LuminousIntensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs index c8ceb52869..887c96a3da 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs @@ -315,80 +315,58 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("G", MagneticFieldUnit.Gauss)] + [InlineData("µT", MagneticFieldUnit.Microtesla)] + [InlineData("mG", MagneticFieldUnit.Milligauss)] + [InlineData("mT", MagneticFieldUnit.Millitesla)] + [InlineData("nT", MagneticFieldUnit.Nanotesla)] + [InlineData("T", MagneticFieldUnit.Tesla)] + public void ParseUnit(string abbreviation, MagneticFieldUnit expectedUnit) { - try - { - var parsedUnit = MagneticField.ParseUnit("G", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MagneticFieldUnit.Gauss, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MagneticField.ParseUnit("µT", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MagneticFieldUnit.Microtesla, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MagneticField.ParseUnit("mG", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MagneticFieldUnit.Milligauss, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MagneticField.ParseUnit("mT", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MagneticFieldUnit.Millitesla, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MagneticField.ParseUnit("nT", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MagneticFieldUnit.Nanotesla, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MagneticField.ParseUnit("T", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MagneticFieldUnit.Tesla, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MagneticFieldUnit parsedUnit = MagneticField.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "G", MagneticFieldUnit.Gauss)] + [InlineData("en-US", "µT", MagneticFieldUnit.Microtesla)] + [InlineData("en-US", "mG", MagneticFieldUnit.Milligauss)] + [InlineData("en-US", "mT", MagneticFieldUnit.Millitesla)] + [InlineData("en-US", "nT", MagneticFieldUnit.Nanotesla)] + [InlineData("en-US", "T", MagneticFieldUnit.Tesla)] + public void ParseUnitWithCulture(string culture, string abbreviation, MagneticFieldUnit expectedUnit) { - { - Assert.True(MagneticField.TryParseUnit("G", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MagneticFieldUnit.Gauss, parsedUnit); - } - - { - Assert.True(MagneticField.TryParseUnit("µT", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MagneticFieldUnit.Microtesla, parsedUnit); - } - - { - Assert.True(MagneticField.TryParseUnit("mG", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MagneticFieldUnit.Milligauss, parsedUnit); - } - - { - Assert.True(MagneticField.TryParseUnit("mT", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MagneticFieldUnit.Millitesla, parsedUnit); - } - - { - Assert.True(MagneticField.TryParseUnit("nT", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MagneticFieldUnit.Nanotesla, parsedUnit); - } + MagneticFieldUnit parsedUnit = MagneticField.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(MagneticField.TryParseUnit("T", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MagneticFieldUnit.Tesla, parsedUnit); - } + [Theory] + [InlineData("G", MagneticFieldUnit.Gauss)] + [InlineData("µT", MagneticFieldUnit.Microtesla)] + [InlineData("mG", MagneticFieldUnit.Milligauss)] + [InlineData("mT", MagneticFieldUnit.Millitesla)] + [InlineData("nT", MagneticFieldUnit.Nanotesla)] + [InlineData("T", MagneticFieldUnit.Tesla)] + public void TryParseUnit(string abbreviation, MagneticFieldUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(MagneticField.TryParseUnit(abbreviation, out MagneticFieldUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "G", MagneticFieldUnit.Gauss)] + [InlineData("en-US", "µT", MagneticFieldUnit.Microtesla)] + [InlineData("en-US", "mG", MagneticFieldUnit.Milligauss)] + [InlineData("en-US", "mT", MagneticFieldUnit.Millitesla)] + [InlineData("en-US", "nT", MagneticFieldUnit.Nanotesla)] + [InlineData("en-US", "T", MagneticFieldUnit.Tesla)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MagneticFieldUnit expectedUnit) + { + Assert.True(MagneticField.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MagneticFieldUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs index cb894b7d55..de42287ffb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("Wb", MagneticFluxUnit.Weber)] + public void ParseUnit(string abbreviation, MagneticFluxUnit expectedUnit) { - try - { - var parsedUnit = MagneticFlux.ParseUnit("Wb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MagneticFluxUnit.Weber, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MagneticFluxUnit parsedUnit = MagneticFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "Wb", MagneticFluxUnit.Weber)] + public void ParseUnitWithCulture(string culture, string abbreviation, MagneticFluxUnit expectedUnit) + { + MagneticFluxUnit parsedUnit = MagneticFlux.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("Wb", MagneticFluxUnit.Weber)] + public void TryParseUnit(string abbreviation, MagneticFluxUnit expectedUnit) { - { - Assert.True(MagneticFlux.TryParseUnit("Wb", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MagneticFluxUnit.Weber, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(MagneticFlux.TryParseUnit(abbreviation, out MagneticFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "Wb", MagneticFluxUnit.Weber)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MagneticFluxUnit expectedUnit) + { + Assert.True(MagneticFlux.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MagneticFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs index ea0c1ead65..44ec060e21 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("A/m", MagnetizationUnit.AmperePerMeter)] + public void ParseUnit(string abbreviation, MagnetizationUnit expectedUnit) { - try - { - var parsedUnit = Magnetization.ParseUnit("A/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MagnetizationUnit.AmperePerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MagnetizationUnit parsedUnit = Magnetization.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "A/m", MagnetizationUnit.AmperePerMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, MagnetizationUnit expectedUnit) + { + MagnetizationUnit parsedUnit = Magnetization.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("A/m", MagnetizationUnit.AmperePerMeter)] + public void TryParseUnit(string abbreviation, MagnetizationUnit expectedUnit) { - { - Assert.True(Magnetization.TryParseUnit("A/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MagnetizationUnit.AmperePerMeter, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Magnetization.TryParseUnit(abbreviation, out MagnetizationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "A/m", MagnetizationUnit.AmperePerMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MagnetizationUnit expectedUnit) + { + Assert.True(Magnetization.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MagnetizationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs index 326bb8d522..4cd37bf5cd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs @@ -1356,597 +1356,238 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = MassConcentration.ParseUnit("cg/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.CentigramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("cg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.CentigramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("cg/μl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.CentigramPerMicroliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("cg/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.CentigramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("dg/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.DecigramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("dg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.DecigramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("dg/μl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.DecigramPerMicroliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("dg/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.DecigramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("g/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.GramPerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("g/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.GramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("г/м³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassConcentrationUnit.GramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("g/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.GramPerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("g/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.GramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("g/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.GramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("g/μl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.GramPerMicroliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("g/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.GramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("kg/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("kg/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("кг/м³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("kg/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("kg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.KilogramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("kip/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.KilopoundPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("kip/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.KilopoundPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("µg/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.MicrogramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("мкг/м³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassConcentrationUnit.MicrogramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("µg/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.MicrogramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("µg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.MicrogramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("µg/μl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.MicrogramPerMicroliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("µg/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.MicrogramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("mg/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.MilligramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("мг/м³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassConcentrationUnit.MilligramPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("mg/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.MilligramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("mg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.MilligramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("mg/μl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.MilligramPerMicroliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("mg/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.MilligramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("ng/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.NanogramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("ng/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.NanogramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("ng/μl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.NanogramPerMicroliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("ng/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.NanogramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("oz/gal (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.OuncePerImperialGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("oz/gal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.OuncePerUSGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("pg/dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.PicogramPerDeciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("pg/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.PicogramPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("pg/μl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.PicogramPerMicroliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("pg/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.PicogramPerMilliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("lb/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.PoundPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("lb/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.PoundPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("ppg (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.PoundPerImperialGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("ppg (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.PoundPerUSGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("slug/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.SlugPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("t/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.TonnePerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("t/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.TonnePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassConcentration.ParseUnit("t/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassConcentrationUnit.TonnePerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cg/dl", MassConcentrationUnit.CentigramPerDeciliter)] + [InlineData("cg/l", MassConcentrationUnit.CentigramPerLiter)] + [InlineData("cg/μl", MassConcentrationUnit.CentigramPerMicroliter)] + [InlineData("cg/ml", MassConcentrationUnit.CentigramPerMilliliter)] + [InlineData("dg/dl", MassConcentrationUnit.DecigramPerDeciliter)] + [InlineData("dg/l", MassConcentrationUnit.DecigramPerLiter)] + [InlineData("dg/μl", MassConcentrationUnit.DecigramPerMicroliter)] + [InlineData("dg/ml", MassConcentrationUnit.DecigramPerMilliliter)] + [InlineData("g/cm³", MassConcentrationUnit.GramPerCubicCentimeter)] + [InlineData("g/m³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("g/mm³", MassConcentrationUnit.GramPerCubicMillimeter)] + [InlineData("g/dl", MassConcentrationUnit.GramPerDeciliter)] + [InlineData("g/l", MassConcentrationUnit.GramPerLiter)] + [InlineData("g/μl", MassConcentrationUnit.GramPerMicroliter)] + [InlineData("g/ml", MassConcentrationUnit.GramPerMilliliter)] + [InlineData("kg/cm³", MassConcentrationUnit.KilogramPerCubicCentimeter)] + [InlineData("kg/m³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("kg/mm³", MassConcentrationUnit.KilogramPerCubicMillimeter)] + [InlineData("kg/l", MassConcentrationUnit.KilogramPerLiter)] + [InlineData("kip/ft³", MassConcentrationUnit.KilopoundPerCubicFoot)] + [InlineData("kip/in³", MassConcentrationUnit.KilopoundPerCubicInch)] + [InlineData("µg/m³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("µg/dl", MassConcentrationUnit.MicrogramPerDeciliter)] + [InlineData("µg/l", MassConcentrationUnit.MicrogramPerLiter)] + [InlineData("µg/μl", MassConcentrationUnit.MicrogramPerMicroliter)] + [InlineData("µg/ml", MassConcentrationUnit.MicrogramPerMilliliter)] + [InlineData("mg/m³", MassConcentrationUnit.MilligramPerCubicMeter)] + [InlineData("mg/dl", MassConcentrationUnit.MilligramPerDeciliter)] + [InlineData("mg/l", MassConcentrationUnit.MilligramPerLiter)] + [InlineData("mg/μl", MassConcentrationUnit.MilligramPerMicroliter)] + [InlineData("mg/ml", MassConcentrationUnit.MilligramPerMilliliter)] + [InlineData("ng/dl", MassConcentrationUnit.NanogramPerDeciliter)] + [InlineData("ng/l", MassConcentrationUnit.NanogramPerLiter)] + [InlineData("ng/μl", MassConcentrationUnit.NanogramPerMicroliter)] + [InlineData("ng/ml", MassConcentrationUnit.NanogramPerMilliliter)] + [InlineData("oz/gal (imp.)", MassConcentrationUnit.OuncePerImperialGallon)] + [InlineData("oz/gal (U.S.)", MassConcentrationUnit.OuncePerUSGallon)] + [InlineData("pg/dl", MassConcentrationUnit.PicogramPerDeciliter)] + [InlineData("pg/l", MassConcentrationUnit.PicogramPerLiter)] + [InlineData("pg/μl", MassConcentrationUnit.PicogramPerMicroliter)] + [InlineData("pg/ml", MassConcentrationUnit.PicogramPerMilliliter)] + [InlineData("lb/ft³", MassConcentrationUnit.PoundPerCubicFoot)] + [InlineData("lb/in³", MassConcentrationUnit.PoundPerCubicInch)] + [InlineData("ppg (imp.)", MassConcentrationUnit.PoundPerImperialGallon)] + [InlineData("ppg (U.S.)", MassConcentrationUnit.PoundPerUSGallon)] + [InlineData("slug/ft³", MassConcentrationUnit.SlugPerCubicFoot)] + [InlineData("t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter)] + [InlineData("t/m³", MassConcentrationUnit.TonnePerCubicMeter)] + [InlineData("t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter)] + public void ParseUnit(string abbreviation, MassConcentrationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MassConcentrationUnit parsedUnit = MassConcentration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(MassConcentration.TryParseUnit("cg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.CentigramPerDeciliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("cg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.CentigramPerLiter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("cg/μl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.CentigramPerMicroliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("cg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.CentigramPerMilliliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("dg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.DecigramPerDeciliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("dg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.DecigramPerLiter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("dg/μl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.DecigramPerMicroliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("dg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.DecigramPerMilliliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("g/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.GramPerCubicCentimeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("g/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.GramPerCubicMeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("г/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.GramPerCubicMeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("g/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.GramPerCubicMillimeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("g/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.GramPerDeciliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("g/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.GramPerLiter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("g/μl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.GramPerMicroliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("g/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.GramPerMilliliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("kg/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicCentimeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("kg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("кг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("kg/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.KilogramPerCubicMillimeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("kg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.KilogramPerLiter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("kip/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.KilopoundPerCubicFoot, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("kip/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.KilopoundPerCubicInch, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("µg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MicrogramPerCubicMeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("мкг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MicrogramPerCubicMeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("µg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MicrogramPerDeciliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("µg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MicrogramPerLiter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("µg/μl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MicrogramPerMicroliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("µg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MicrogramPerMilliliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("mg/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MilligramPerCubicMeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("мг/м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MilligramPerCubicMeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("mg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MilligramPerDeciliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("mg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MilligramPerLiter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("mg/μl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MilligramPerMicroliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("mg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.MilligramPerMilliliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("ng/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.NanogramPerDeciliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("ng/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.NanogramPerLiter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("ng/μl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.NanogramPerMicroliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("ng/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.NanogramPerMilliliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("oz/gal (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.OuncePerImperialGallon, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("oz/gal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.OuncePerUSGallon, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("pg/dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.PicogramPerDeciliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("pg/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.PicogramPerLiter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("pg/μl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.PicogramPerMicroliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("pg/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.PicogramPerMilliliter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("lb/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.PoundPerCubicFoot, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("lb/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.PoundPerCubicInch, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("ppg (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.PoundPerImperialGallon, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("ppg (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.PoundPerUSGallon, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("slug/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.SlugPerCubicFoot, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("t/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.TonnePerCubicCentimeter, parsedUnit); - } - - { - Assert.True(MassConcentration.TryParseUnit("t/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.TonnePerCubicMeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "cg/dl", MassConcentrationUnit.CentigramPerDeciliter)] + [InlineData("en-US", "cg/l", MassConcentrationUnit.CentigramPerLiter)] + [InlineData("en-US", "cg/μl", MassConcentrationUnit.CentigramPerMicroliter)] + [InlineData("en-US", "cg/ml", MassConcentrationUnit.CentigramPerMilliliter)] + [InlineData("en-US", "dg/dl", MassConcentrationUnit.DecigramPerDeciliter)] + [InlineData("en-US", "dg/l", MassConcentrationUnit.DecigramPerLiter)] + [InlineData("en-US", "dg/μl", MassConcentrationUnit.DecigramPerMicroliter)] + [InlineData("en-US", "dg/ml", MassConcentrationUnit.DecigramPerMilliliter)] + [InlineData("en-US", "g/cm³", MassConcentrationUnit.GramPerCubicCentimeter)] + [InlineData("en-US", "g/m³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("en-US", "g/mm³", MassConcentrationUnit.GramPerCubicMillimeter)] + [InlineData("en-US", "g/dl", MassConcentrationUnit.GramPerDeciliter)] + [InlineData("en-US", "g/l", MassConcentrationUnit.GramPerLiter)] + [InlineData("en-US", "g/μl", MassConcentrationUnit.GramPerMicroliter)] + [InlineData("en-US", "g/ml", MassConcentrationUnit.GramPerMilliliter)] + [InlineData("en-US", "kg/cm³", MassConcentrationUnit.KilogramPerCubicCentimeter)] + [InlineData("en-US", "kg/m³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("en-US", "kg/mm³", MassConcentrationUnit.KilogramPerCubicMillimeter)] + [InlineData("en-US", "kg/l", MassConcentrationUnit.KilogramPerLiter)] + [InlineData("en-US", "kip/ft³", MassConcentrationUnit.KilopoundPerCubicFoot)] + [InlineData("en-US", "kip/in³", MassConcentrationUnit.KilopoundPerCubicInch)] + [InlineData("en-US", "µg/m³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("en-US", "µg/dl", MassConcentrationUnit.MicrogramPerDeciliter)] + [InlineData("en-US", "µg/l", MassConcentrationUnit.MicrogramPerLiter)] + [InlineData("en-US", "µg/μl", MassConcentrationUnit.MicrogramPerMicroliter)] + [InlineData("en-US", "µg/ml", MassConcentrationUnit.MicrogramPerMilliliter)] + [InlineData("en-US", "mg/m³", MassConcentrationUnit.MilligramPerCubicMeter)] + [InlineData("en-US", "mg/dl", MassConcentrationUnit.MilligramPerDeciliter)] + [InlineData("en-US", "mg/l", MassConcentrationUnit.MilligramPerLiter)] + [InlineData("en-US", "mg/μl", MassConcentrationUnit.MilligramPerMicroliter)] + [InlineData("en-US", "mg/ml", MassConcentrationUnit.MilligramPerMilliliter)] + [InlineData("en-US", "ng/dl", MassConcentrationUnit.NanogramPerDeciliter)] + [InlineData("en-US", "ng/l", MassConcentrationUnit.NanogramPerLiter)] + [InlineData("en-US", "ng/μl", MassConcentrationUnit.NanogramPerMicroliter)] + [InlineData("en-US", "ng/ml", MassConcentrationUnit.NanogramPerMilliliter)] + [InlineData("en-US", "oz/gal (imp.)", MassConcentrationUnit.OuncePerImperialGallon)] + [InlineData("en-US", "oz/gal (U.S.)", MassConcentrationUnit.OuncePerUSGallon)] + [InlineData("en-US", "pg/dl", MassConcentrationUnit.PicogramPerDeciliter)] + [InlineData("en-US", "pg/l", MassConcentrationUnit.PicogramPerLiter)] + [InlineData("en-US", "pg/μl", MassConcentrationUnit.PicogramPerMicroliter)] + [InlineData("en-US", "pg/ml", MassConcentrationUnit.PicogramPerMilliliter)] + [InlineData("en-US", "lb/ft³", MassConcentrationUnit.PoundPerCubicFoot)] + [InlineData("en-US", "lb/in³", MassConcentrationUnit.PoundPerCubicInch)] + [InlineData("en-US", "ppg (imp.)", MassConcentrationUnit.PoundPerImperialGallon)] + [InlineData("en-US", "ppg (U.S.)", MassConcentrationUnit.PoundPerUSGallon)] + [InlineData("en-US", "slug/ft³", MassConcentrationUnit.SlugPerCubicFoot)] + [InlineData("en-US", "t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter)] + [InlineData("en-US", "t/m³", MassConcentrationUnit.TonnePerCubicMeter)] + [InlineData("en-US", "t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter)] + [InlineData("ru-RU", "г/м³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("ru-RU", "кг/м³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("ru-RU", "мкг/м³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("ru-RU", "мг/м³", MassConcentrationUnit.MilligramPerCubicMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, MassConcentrationUnit expectedUnit) + { + MassConcentrationUnit parsedUnit = MassConcentration.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(MassConcentration.TryParseUnit("t/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassConcentrationUnit.TonnePerCubicMillimeter, parsedUnit); - } + [Theory] + [InlineData("cg/dl", MassConcentrationUnit.CentigramPerDeciliter)] + [InlineData("cg/l", MassConcentrationUnit.CentigramPerLiter)] + [InlineData("cg/μl", MassConcentrationUnit.CentigramPerMicroliter)] + [InlineData("cg/ml", MassConcentrationUnit.CentigramPerMilliliter)] + [InlineData("dg/dl", MassConcentrationUnit.DecigramPerDeciliter)] + [InlineData("dg/l", MassConcentrationUnit.DecigramPerLiter)] + [InlineData("dg/μl", MassConcentrationUnit.DecigramPerMicroliter)] + [InlineData("dg/ml", MassConcentrationUnit.DecigramPerMilliliter)] + [InlineData("g/cm³", MassConcentrationUnit.GramPerCubicCentimeter)] + [InlineData("g/m³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("g/mm³", MassConcentrationUnit.GramPerCubicMillimeter)] + [InlineData("g/dl", MassConcentrationUnit.GramPerDeciliter)] + [InlineData("g/l", MassConcentrationUnit.GramPerLiter)] + [InlineData("g/μl", MassConcentrationUnit.GramPerMicroliter)] + [InlineData("g/ml", MassConcentrationUnit.GramPerMilliliter)] + [InlineData("kg/cm³", MassConcentrationUnit.KilogramPerCubicCentimeter)] + [InlineData("kg/m³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("kg/mm³", MassConcentrationUnit.KilogramPerCubicMillimeter)] + [InlineData("kg/l", MassConcentrationUnit.KilogramPerLiter)] + [InlineData("kip/ft³", MassConcentrationUnit.KilopoundPerCubicFoot)] + [InlineData("kip/in³", MassConcentrationUnit.KilopoundPerCubicInch)] + [InlineData("µg/m³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("µg/dl", MassConcentrationUnit.MicrogramPerDeciliter)] + [InlineData("µg/l", MassConcentrationUnit.MicrogramPerLiter)] + [InlineData("µg/μl", MassConcentrationUnit.MicrogramPerMicroliter)] + [InlineData("µg/ml", MassConcentrationUnit.MicrogramPerMilliliter)] + [InlineData("mg/m³", MassConcentrationUnit.MilligramPerCubicMeter)] + [InlineData("mg/dl", MassConcentrationUnit.MilligramPerDeciliter)] + [InlineData("mg/l", MassConcentrationUnit.MilligramPerLiter)] + [InlineData("mg/μl", MassConcentrationUnit.MilligramPerMicroliter)] + [InlineData("mg/ml", MassConcentrationUnit.MilligramPerMilliliter)] + [InlineData("ng/dl", MassConcentrationUnit.NanogramPerDeciliter)] + [InlineData("ng/l", MassConcentrationUnit.NanogramPerLiter)] + [InlineData("ng/μl", MassConcentrationUnit.NanogramPerMicroliter)] + [InlineData("ng/ml", MassConcentrationUnit.NanogramPerMilliliter)] + [InlineData("oz/gal (imp.)", MassConcentrationUnit.OuncePerImperialGallon)] + [InlineData("oz/gal (U.S.)", MassConcentrationUnit.OuncePerUSGallon)] + [InlineData("pg/dl", MassConcentrationUnit.PicogramPerDeciliter)] + [InlineData("pg/l", MassConcentrationUnit.PicogramPerLiter)] + [InlineData("pg/μl", MassConcentrationUnit.PicogramPerMicroliter)] + [InlineData("pg/ml", MassConcentrationUnit.PicogramPerMilliliter)] + [InlineData("lb/ft³", MassConcentrationUnit.PoundPerCubicFoot)] + [InlineData("lb/in³", MassConcentrationUnit.PoundPerCubicInch)] + [InlineData("ppg (imp.)", MassConcentrationUnit.PoundPerImperialGallon)] + [InlineData("ppg (U.S.)", MassConcentrationUnit.PoundPerUSGallon)] + [InlineData("slug/ft³", MassConcentrationUnit.SlugPerCubicFoot)] + [InlineData("t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter)] + [InlineData("t/m³", MassConcentrationUnit.TonnePerCubicMeter)] + [InlineData("t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter)] + public void TryParseUnit(string abbreviation, MassConcentrationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(MassConcentration.TryParseUnit(abbreviation, out MassConcentrationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cg/dl", MassConcentrationUnit.CentigramPerDeciliter)] + [InlineData("en-US", "cg/l", MassConcentrationUnit.CentigramPerLiter)] + [InlineData("en-US", "cg/μl", MassConcentrationUnit.CentigramPerMicroliter)] + [InlineData("en-US", "cg/ml", MassConcentrationUnit.CentigramPerMilliliter)] + [InlineData("en-US", "dg/dl", MassConcentrationUnit.DecigramPerDeciliter)] + [InlineData("en-US", "dg/l", MassConcentrationUnit.DecigramPerLiter)] + [InlineData("en-US", "dg/μl", MassConcentrationUnit.DecigramPerMicroliter)] + [InlineData("en-US", "dg/ml", MassConcentrationUnit.DecigramPerMilliliter)] + [InlineData("en-US", "g/cm³", MassConcentrationUnit.GramPerCubicCentimeter)] + [InlineData("en-US", "g/m³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("en-US", "g/mm³", MassConcentrationUnit.GramPerCubicMillimeter)] + [InlineData("en-US", "g/dl", MassConcentrationUnit.GramPerDeciliter)] + [InlineData("en-US", "g/l", MassConcentrationUnit.GramPerLiter)] + [InlineData("en-US", "g/μl", MassConcentrationUnit.GramPerMicroliter)] + [InlineData("en-US", "g/ml", MassConcentrationUnit.GramPerMilliliter)] + [InlineData("en-US", "kg/cm³", MassConcentrationUnit.KilogramPerCubicCentimeter)] + [InlineData("en-US", "kg/m³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("en-US", "kg/mm³", MassConcentrationUnit.KilogramPerCubicMillimeter)] + [InlineData("en-US", "kg/l", MassConcentrationUnit.KilogramPerLiter)] + [InlineData("en-US", "kip/ft³", MassConcentrationUnit.KilopoundPerCubicFoot)] + [InlineData("en-US", "kip/in³", MassConcentrationUnit.KilopoundPerCubicInch)] + [InlineData("en-US", "µg/m³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("en-US", "µg/dl", MassConcentrationUnit.MicrogramPerDeciliter)] + [InlineData("en-US", "µg/l", MassConcentrationUnit.MicrogramPerLiter)] + [InlineData("en-US", "µg/μl", MassConcentrationUnit.MicrogramPerMicroliter)] + [InlineData("en-US", "µg/ml", MassConcentrationUnit.MicrogramPerMilliliter)] + [InlineData("en-US", "mg/m³", MassConcentrationUnit.MilligramPerCubicMeter)] + [InlineData("en-US", "mg/dl", MassConcentrationUnit.MilligramPerDeciliter)] + [InlineData("en-US", "mg/l", MassConcentrationUnit.MilligramPerLiter)] + [InlineData("en-US", "mg/μl", MassConcentrationUnit.MilligramPerMicroliter)] + [InlineData("en-US", "mg/ml", MassConcentrationUnit.MilligramPerMilliliter)] + [InlineData("en-US", "ng/dl", MassConcentrationUnit.NanogramPerDeciliter)] + [InlineData("en-US", "ng/l", MassConcentrationUnit.NanogramPerLiter)] + [InlineData("en-US", "ng/μl", MassConcentrationUnit.NanogramPerMicroliter)] + [InlineData("en-US", "ng/ml", MassConcentrationUnit.NanogramPerMilliliter)] + [InlineData("en-US", "oz/gal (imp.)", MassConcentrationUnit.OuncePerImperialGallon)] + [InlineData("en-US", "oz/gal (U.S.)", MassConcentrationUnit.OuncePerUSGallon)] + [InlineData("en-US", "pg/dl", MassConcentrationUnit.PicogramPerDeciliter)] + [InlineData("en-US", "pg/l", MassConcentrationUnit.PicogramPerLiter)] + [InlineData("en-US", "pg/μl", MassConcentrationUnit.PicogramPerMicroliter)] + [InlineData("en-US", "pg/ml", MassConcentrationUnit.PicogramPerMilliliter)] + [InlineData("en-US", "lb/ft³", MassConcentrationUnit.PoundPerCubicFoot)] + [InlineData("en-US", "lb/in³", MassConcentrationUnit.PoundPerCubicInch)] + [InlineData("en-US", "ppg (imp.)", MassConcentrationUnit.PoundPerImperialGallon)] + [InlineData("en-US", "ppg (U.S.)", MassConcentrationUnit.PoundPerUSGallon)] + [InlineData("en-US", "slug/ft³", MassConcentrationUnit.SlugPerCubicFoot)] + [InlineData("en-US", "t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter)] + [InlineData("en-US", "t/m³", MassConcentrationUnit.TonnePerCubicMeter)] + [InlineData("en-US", "t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter)] + [InlineData("ru-RU", "г/м³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("ru-RU", "кг/м³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("ru-RU", "мкг/м³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("ru-RU", "мг/м³", MassConcentrationUnit.MilligramPerCubicMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MassConcentrationUnit expectedUnit) + { + Assert.True(MassConcentration.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassConcentrationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs index f951053fcd..621fe98a93 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs @@ -1067,488 +1067,206 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = MassFlow.ParseUnit("cg/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.CentigramPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("cg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.CentigramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("cg/S", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.CentigramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("dag/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.DecagramPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("dag/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.DecagramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("dag/S", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.DecagramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("dg/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.DecigramPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("dg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.DecigramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("dg/S", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.DecigramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("g/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.GramPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("g/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.GramPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("g/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.GramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("g/S", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.GramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("hg/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.HectogramPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("hg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.HectogramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("hg/S", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.HectogramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("kg/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.KilogramPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("kg/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.KilogramPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("кг/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassFlowUnit.KilogramPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("kg/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.KilogramPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("кг/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassFlowUnit.KilogramPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("kg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.KilogramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("kg/S", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.KilogramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("Mg/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.MegagramPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("Mlb/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.MegapoundPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("Mlb/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.MegapoundPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("Mlb/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.MegapoundPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("Mlb/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.MegapoundPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("µg/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.MicrogramPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("µg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.MicrogramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("µg/S", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.MicrogramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("mg/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.MilligramPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("mg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.MilligramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("mg/S", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.MilligramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("ng/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.NanogramPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("ng/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.NanogramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("ng/S", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.NanogramPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("lb/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.PoundPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("lb/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.PoundPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("lb/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.PoundPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("lb/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.PoundPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("short tn/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.ShortTonPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("t/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.TonnePerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlow.ParseUnit("t/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFlowUnit.TonnePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cg/d", MassFlowUnit.CentigramPerDay)] + [InlineData("cg/s", MassFlowUnit.CentigramPerSecond)] + [InlineData("cg/S", MassFlowUnit.CentigramPerSecond)] + [InlineData("dag/d", MassFlowUnit.DecagramPerDay)] + [InlineData("dag/s", MassFlowUnit.DecagramPerSecond)] + [InlineData("dag/S", MassFlowUnit.DecagramPerSecond)] + [InlineData("dg/d", MassFlowUnit.DecigramPerDay)] + [InlineData("dg/s", MassFlowUnit.DecigramPerSecond)] + [InlineData("dg/S", MassFlowUnit.DecigramPerSecond)] + [InlineData("g/d", MassFlowUnit.GramPerDay)] + [InlineData("g/h", MassFlowUnit.GramPerHour)] + [InlineData("g/s", MassFlowUnit.GramPerSecond)] + [InlineData("g/S", MassFlowUnit.GramPerSecond)] + [InlineData("hg/d", MassFlowUnit.HectogramPerDay)] + [InlineData("hg/s", MassFlowUnit.HectogramPerSecond)] + [InlineData("hg/S", MassFlowUnit.HectogramPerSecond)] + [InlineData("kg/d", MassFlowUnit.KilogramPerDay)] + [InlineData("kg/h", MassFlowUnit.KilogramPerHour)] + [InlineData("kg/min", MassFlowUnit.KilogramPerMinute)] + [InlineData("kg/s", MassFlowUnit.KilogramPerSecond)] + [InlineData("kg/S", MassFlowUnit.KilogramPerSecond)] + [InlineData("Mg/d", MassFlowUnit.MegagramPerDay)] + [InlineData("Mlb/d", MassFlowUnit.MegapoundPerDay)] + [InlineData("Mlb/h", MassFlowUnit.MegapoundPerHour)] + [InlineData("Mlb/min", MassFlowUnit.MegapoundPerMinute)] + [InlineData("Mlb/s", MassFlowUnit.MegapoundPerSecond)] + [InlineData("µg/d", MassFlowUnit.MicrogramPerDay)] + [InlineData("µg/s", MassFlowUnit.MicrogramPerSecond)] + [InlineData("µg/S", MassFlowUnit.MicrogramPerSecond)] + [InlineData("mg/d", MassFlowUnit.MilligramPerDay)] + [InlineData("mg/s", MassFlowUnit.MilligramPerSecond)] + [InlineData("mg/S", MassFlowUnit.MilligramPerSecond)] + [InlineData("ng/d", MassFlowUnit.NanogramPerDay)] + [InlineData("ng/s", MassFlowUnit.NanogramPerSecond)] + [InlineData("ng/S", MassFlowUnit.NanogramPerSecond)] + [InlineData("lb/d", MassFlowUnit.PoundPerDay)] + [InlineData("lb/h", MassFlowUnit.PoundPerHour)] + [InlineData("lb/min", MassFlowUnit.PoundPerMinute)] + [InlineData("lb/s", MassFlowUnit.PoundPerSecond)] + [InlineData("short tn/h", MassFlowUnit.ShortTonPerHour)] + [InlineData("t/d", MassFlowUnit.TonnePerDay)] + [InlineData("t/h", MassFlowUnit.TonnePerHour)] + public void ParseUnit(string abbreviation, MassFlowUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MassFlowUnit parsedUnit = MassFlow.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(MassFlow.TryParseUnit("cg/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.CentigramPerDay, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("cg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.CentigramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("cg/S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.CentigramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("dag/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.DecagramPerDay, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("dag/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.DecagramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("dag/S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.DecagramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("dg/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.DecigramPerDay, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("dg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.DecigramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("dg/S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.DecigramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("g/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.GramPerDay, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("g/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.GramPerHour, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("g/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.GramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("g/S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.GramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("hg/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.HectogramPerDay, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("hg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.HectogramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("hg/S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.HectogramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("kg/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.KilogramPerDay, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("kg/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.KilogramPerHour, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("кг/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.KilogramPerHour, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("kg/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.KilogramPerMinute, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("кг/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.KilogramPerMinute, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("kg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.KilogramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("kg/S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.KilogramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("Mlb/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.MegapoundPerDay, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("Mlb/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.MegapoundPerHour, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("Mlb/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.MegapoundPerMinute, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("Mlb/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.MegapoundPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("µg/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.MicrogramPerDay, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("µg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.MicrogramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("µg/S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.MicrogramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("mg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.MilligramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("mg/S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.MilligramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("ng/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.NanogramPerDay, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("ng/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.NanogramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("ng/S", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.NanogramPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("lb/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.PoundPerDay, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("lb/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.PoundPerHour, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("lb/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.PoundPerMinute, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("lb/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.PoundPerSecond, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("short tn/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.ShortTonPerHour, parsedUnit); - } - - { - Assert.True(MassFlow.TryParseUnit("t/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.TonnePerDay, parsedUnit); - } + [Theory] + [InlineData("en-US", "cg/d", MassFlowUnit.CentigramPerDay)] + [InlineData("en-US", "cg/s", MassFlowUnit.CentigramPerSecond)] + [InlineData("en-US", "cg/S", MassFlowUnit.CentigramPerSecond)] + [InlineData("en-US", "dag/d", MassFlowUnit.DecagramPerDay)] + [InlineData("en-US", "dag/s", MassFlowUnit.DecagramPerSecond)] + [InlineData("en-US", "dag/S", MassFlowUnit.DecagramPerSecond)] + [InlineData("en-US", "dg/d", MassFlowUnit.DecigramPerDay)] + [InlineData("en-US", "dg/s", MassFlowUnit.DecigramPerSecond)] + [InlineData("en-US", "dg/S", MassFlowUnit.DecigramPerSecond)] + [InlineData("en-US", "g/d", MassFlowUnit.GramPerDay)] + [InlineData("en-US", "g/h", MassFlowUnit.GramPerHour)] + [InlineData("en-US", "g/s", MassFlowUnit.GramPerSecond)] + [InlineData("en-US", "g/S", MassFlowUnit.GramPerSecond)] + [InlineData("en-US", "hg/d", MassFlowUnit.HectogramPerDay)] + [InlineData("en-US", "hg/s", MassFlowUnit.HectogramPerSecond)] + [InlineData("en-US", "hg/S", MassFlowUnit.HectogramPerSecond)] + [InlineData("en-US", "kg/d", MassFlowUnit.KilogramPerDay)] + [InlineData("en-US", "kg/h", MassFlowUnit.KilogramPerHour)] + [InlineData("en-US", "kg/min", MassFlowUnit.KilogramPerMinute)] + [InlineData("en-US", "kg/s", MassFlowUnit.KilogramPerSecond)] + [InlineData("en-US", "kg/S", MassFlowUnit.KilogramPerSecond)] + [InlineData("en-US", "Mg/d", MassFlowUnit.MegagramPerDay)] + [InlineData("en-US", "Mlb/d", MassFlowUnit.MegapoundPerDay)] + [InlineData("en-US", "Mlb/h", MassFlowUnit.MegapoundPerHour)] + [InlineData("en-US", "Mlb/min", MassFlowUnit.MegapoundPerMinute)] + [InlineData("en-US", "Mlb/s", MassFlowUnit.MegapoundPerSecond)] + [InlineData("en-US", "µg/d", MassFlowUnit.MicrogramPerDay)] + [InlineData("en-US", "µg/s", MassFlowUnit.MicrogramPerSecond)] + [InlineData("en-US", "µg/S", MassFlowUnit.MicrogramPerSecond)] + [InlineData("en-US", "mg/d", MassFlowUnit.MilligramPerDay)] + [InlineData("en-US", "mg/s", MassFlowUnit.MilligramPerSecond)] + [InlineData("en-US", "mg/S", MassFlowUnit.MilligramPerSecond)] + [InlineData("en-US", "ng/d", MassFlowUnit.NanogramPerDay)] + [InlineData("en-US", "ng/s", MassFlowUnit.NanogramPerSecond)] + [InlineData("en-US", "ng/S", MassFlowUnit.NanogramPerSecond)] + [InlineData("en-US", "lb/d", MassFlowUnit.PoundPerDay)] + [InlineData("en-US", "lb/h", MassFlowUnit.PoundPerHour)] + [InlineData("en-US", "lb/min", MassFlowUnit.PoundPerMinute)] + [InlineData("en-US", "lb/s", MassFlowUnit.PoundPerSecond)] + [InlineData("en-US", "short tn/h", MassFlowUnit.ShortTonPerHour)] + [InlineData("en-US", "t/d", MassFlowUnit.TonnePerDay)] + [InlineData("en-US", "t/h", MassFlowUnit.TonnePerHour)] + [InlineData("ru-RU", "кг/ч", MassFlowUnit.KilogramPerHour)] + [InlineData("ru-RU", "кг/мин", MassFlowUnit.KilogramPerMinute)] + public void ParseUnitWithCulture(string culture, string abbreviation, MassFlowUnit expectedUnit) + { + MassFlowUnit parsedUnit = MassFlow.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(MassFlow.TryParseUnit("t/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFlowUnit.TonnePerHour, parsedUnit); - } + [Theory] + [InlineData("cg/d", MassFlowUnit.CentigramPerDay)] + [InlineData("cg/s", MassFlowUnit.CentigramPerSecond)] + [InlineData("cg/S", MassFlowUnit.CentigramPerSecond)] + [InlineData("dag/d", MassFlowUnit.DecagramPerDay)] + [InlineData("dag/s", MassFlowUnit.DecagramPerSecond)] + [InlineData("dag/S", MassFlowUnit.DecagramPerSecond)] + [InlineData("dg/d", MassFlowUnit.DecigramPerDay)] + [InlineData("dg/s", MassFlowUnit.DecigramPerSecond)] + [InlineData("dg/S", MassFlowUnit.DecigramPerSecond)] + [InlineData("g/d", MassFlowUnit.GramPerDay)] + [InlineData("g/h", MassFlowUnit.GramPerHour)] + [InlineData("g/s", MassFlowUnit.GramPerSecond)] + [InlineData("g/S", MassFlowUnit.GramPerSecond)] + [InlineData("hg/d", MassFlowUnit.HectogramPerDay)] + [InlineData("hg/s", MassFlowUnit.HectogramPerSecond)] + [InlineData("hg/S", MassFlowUnit.HectogramPerSecond)] + [InlineData("kg/d", MassFlowUnit.KilogramPerDay)] + [InlineData("kg/h", MassFlowUnit.KilogramPerHour)] + [InlineData("kg/min", MassFlowUnit.KilogramPerMinute)] + [InlineData("kg/s", MassFlowUnit.KilogramPerSecond)] + [InlineData("kg/S", MassFlowUnit.KilogramPerSecond)] + [InlineData("Mg/d", MassFlowUnit.MegagramPerDay)] + [InlineData("Mlb/d", MassFlowUnit.MegapoundPerDay)] + [InlineData("Mlb/h", MassFlowUnit.MegapoundPerHour)] + [InlineData("Mlb/min", MassFlowUnit.MegapoundPerMinute)] + [InlineData("Mlb/s", MassFlowUnit.MegapoundPerSecond)] + [InlineData("µg/d", MassFlowUnit.MicrogramPerDay)] + [InlineData("µg/s", MassFlowUnit.MicrogramPerSecond)] + [InlineData("µg/S", MassFlowUnit.MicrogramPerSecond)] + [InlineData("mg/d", MassFlowUnit.MilligramPerDay)] + [InlineData("mg/s", MassFlowUnit.MilligramPerSecond)] + [InlineData("mg/S", MassFlowUnit.MilligramPerSecond)] + [InlineData("ng/d", MassFlowUnit.NanogramPerDay)] + [InlineData("ng/s", MassFlowUnit.NanogramPerSecond)] + [InlineData("ng/S", MassFlowUnit.NanogramPerSecond)] + [InlineData("lb/d", MassFlowUnit.PoundPerDay)] + [InlineData("lb/h", MassFlowUnit.PoundPerHour)] + [InlineData("lb/min", MassFlowUnit.PoundPerMinute)] + [InlineData("lb/s", MassFlowUnit.PoundPerSecond)] + [InlineData("short tn/h", MassFlowUnit.ShortTonPerHour)] + [InlineData("t/d", MassFlowUnit.TonnePerDay)] + [InlineData("t/h", MassFlowUnit.TonnePerHour)] + public void TryParseUnit(string abbreviation, MassFlowUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(MassFlow.TryParseUnit(abbreviation, out MassFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cg/d", MassFlowUnit.CentigramPerDay)] + [InlineData("en-US", "cg/s", MassFlowUnit.CentigramPerSecond)] + [InlineData("en-US", "cg/S", MassFlowUnit.CentigramPerSecond)] + [InlineData("en-US", "dag/d", MassFlowUnit.DecagramPerDay)] + [InlineData("en-US", "dag/s", MassFlowUnit.DecagramPerSecond)] + [InlineData("en-US", "dag/S", MassFlowUnit.DecagramPerSecond)] + [InlineData("en-US", "dg/d", MassFlowUnit.DecigramPerDay)] + [InlineData("en-US", "dg/s", MassFlowUnit.DecigramPerSecond)] + [InlineData("en-US", "dg/S", MassFlowUnit.DecigramPerSecond)] + [InlineData("en-US", "g/d", MassFlowUnit.GramPerDay)] + [InlineData("en-US", "g/h", MassFlowUnit.GramPerHour)] + [InlineData("en-US", "g/s", MassFlowUnit.GramPerSecond)] + [InlineData("en-US", "g/S", MassFlowUnit.GramPerSecond)] + [InlineData("en-US", "hg/d", MassFlowUnit.HectogramPerDay)] + [InlineData("en-US", "hg/s", MassFlowUnit.HectogramPerSecond)] + [InlineData("en-US", "hg/S", MassFlowUnit.HectogramPerSecond)] + [InlineData("en-US", "kg/d", MassFlowUnit.KilogramPerDay)] + [InlineData("en-US", "kg/h", MassFlowUnit.KilogramPerHour)] + [InlineData("en-US", "kg/min", MassFlowUnit.KilogramPerMinute)] + [InlineData("en-US", "kg/s", MassFlowUnit.KilogramPerSecond)] + [InlineData("en-US", "kg/S", MassFlowUnit.KilogramPerSecond)] + [InlineData("en-US", "Mg/d", MassFlowUnit.MegagramPerDay)] + [InlineData("en-US", "Mlb/d", MassFlowUnit.MegapoundPerDay)] + [InlineData("en-US", "Mlb/h", MassFlowUnit.MegapoundPerHour)] + [InlineData("en-US", "Mlb/min", MassFlowUnit.MegapoundPerMinute)] + [InlineData("en-US", "Mlb/s", MassFlowUnit.MegapoundPerSecond)] + [InlineData("en-US", "µg/d", MassFlowUnit.MicrogramPerDay)] + [InlineData("en-US", "µg/s", MassFlowUnit.MicrogramPerSecond)] + [InlineData("en-US", "µg/S", MassFlowUnit.MicrogramPerSecond)] + [InlineData("en-US", "mg/d", MassFlowUnit.MilligramPerDay)] + [InlineData("en-US", "mg/s", MassFlowUnit.MilligramPerSecond)] + [InlineData("en-US", "mg/S", MassFlowUnit.MilligramPerSecond)] + [InlineData("en-US", "ng/d", MassFlowUnit.NanogramPerDay)] + [InlineData("en-US", "ng/s", MassFlowUnit.NanogramPerSecond)] + [InlineData("en-US", "ng/S", MassFlowUnit.NanogramPerSecond)] + [InlineData("en-US", "lb/d", MassFlowUnit.PoundPerDay)] + [InlineData("en-US", "lb/h", MassFlowUnit.PoundPerHour)] + [InlineData("en-US", "lb/min", MassFlowUnit.PoundPerMinute)] + [InlineData("en-US", "lb/s", MassFlowUnit.PoundPerSecond)] + [InlineData("en-US", "short tn/h", MassFlowUnit.ShortTonPerHour)] + [InlineData("en-US", "t/d", MassFlowUnit.TonnePerDay)] + [InlineData("en-US", "t/h", MassFlowUnit.TonnePerHour)] + [InlineData("ru-RU", "кг/ч", MassFlowUnit.KilogramPerHour)] + [InlineData("ru-RU", "кг/мин", MassFlowUnit.KilogramPerMinute)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MassFlowUnit expectedUnit) + { + Assert.True(MassFlow.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs index 694fa54e1f..043feb6510 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs @@ -453,146 +453,82 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = MassFlux.ParseUnit("g·h⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlux.ParseUnit("g·h⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlux.ParseUnit("g·h⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlux.ParseUnit("g·s⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlux.ParseUnit("g·s⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlux.ParseUnit("g·s⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlux.ParseUnit("kg·h⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlux.ParseUnit("kg·h⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlux.ParseUnit("kg·h⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlux.ParseUnit("kg·s⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlux.ParseUnit("kg·s⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFlux.ParseUnit("kg·s⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("g·h⁻¹·cm⁻²", MassFluxUnit.GramPerHourPerSquareCentimeter)] + [InlineData("g·h⁻¹·m⁻²", MassFluxUnit.GramPerHourPerSquareMeter)] + [InlineData("g·h⁻¹·mm⁻²", MassFluxUnit.GramPerHourPerSquareMillimeter)] + [InlineData("g·s⁻¹·cm⁻²", MassFluxUnit.GramPerSecondPerSquareCentimeter)] + [InlineData("g·s⁻¹·m⁻²", MassFluxUnit.GramPerSecondPerSquareMeter)] + [InlineData("g·s⁻¹·mm⁻²", MassFluxUnit.GramPerSecondPerSquareMillimeter)] + [InlineData("kg·h⁻¹·cm⁻²", MassFluxUnit.KilogramPerHourPerSquareCentimeter)] + [InlineData("kg·h⁻¹·m⁻²", MassFluxUnit.KilogramPerHourPerSquareMeter)] + [InlineData("kg·h⁻¹·mm⁻²", MassFluxUnit.KilogramPerHourPerSquareMillimeter)] + [InlineData("kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] + [InlineData("kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] + [InlineData("kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] + public void ParseUnit(string abbreviation, MassFluxUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MassFluxUnit parsedUnit = MassFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(MassFlux.TryParseUnit("g·h⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(MassFlux.TryParseUnit("g·h⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareMeter, parsedUnit); - } - - { - Assert.True(MassFlux.TryParseUnit("g·h⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.GramPerHourPerSquareMillimeter, parsedUnit); - } - - { - Assert.True(MassFlux.TryParseUnit("g·s⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(MassFlux.TryParseUnit("g·s⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMeter, parsedUnit); - } - - { - Assert.True(MassFlux.TryParseUnit("g·s⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.GramPerSecondPerSquareMillimeter, parsedUnit); - } - - { - Assert.True(MassFlux.TryParseUnit("kg·h⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(MassFlux.TryParseUnit("kg·h⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMeter, parsedUnit); - } - - { - Assert.True(MassFlux.TryParseUnit("kg·h⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.KilogramPerHourPerSquareMillimeter, parsedUnit); - } - - { - Assert.True(MassFlux.TryParseUnit("kg·s⁻¹·cm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(MassFlux.TryParseUnit("kg·s⁻¹·m⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "g·h⁻¹·cm⁻²", MassFluxUnit.GramPerHourPerSquareCentimeter)] + [InlineData("en-US", "g·h⁻¹·m⁻²", MassFluxUnit.GramPerHourPerSquareMeter)] + [InlineData("en-US", "g·h⁻¹·mm⁻²", MassFluxUnit.GramPerHourPerSquareMillimeter)] + [InlineData("en-US", "g·s⁻¹·cm⁻²", MassFluxUnit.GramPerSecondPerSquareCentimeter)] + [InlineData("en-US", "g·s⁻¹·m⁻²", MassFluxUnit.GramPerSecondPerSquareMeter)] + [InlineData("en-US", "g·s⁻¹·mm⁻²", MassFluxUnit.GramPerSecondPerSquareMillimeter)] + [InlineData("en-US", "kg·h⁻¹·cm⁻²", MassFluxUnit.KilogramPerHourPerSquareCentimeter)] + [InlineData("en-US", "kg·h⁻¹·m⁻²", MassFluxUnit.KilogramPerHourPerSquareMeter)] + [InlineData("en-US", "kg·h⁻¹·mm⁻²", MassFluxUnit.KilogramPerHourPerSquareMillimeter)] + [InlineData("en-US", "kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] + [InlineData("en-US", "kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] + [InlineData("en-US", "kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, MassFluxUnit expectedUnit) + { + MassFluxUnit parsedUnit = MassFlux.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(MassFlux.TryParseUnit("kg·s⁻¹·mm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFluxUnit.KilogramPerSecondPerSquareMillimeter, parsedUnit); - } + [Theory] + [InlineData("g·h⁻¹·cm⁻²", MassFluxUnit.GramPerHourPerSquareCentimeter)] + [InlineData("g·h⁻¹·m⁻²", MassFluxUnit.GramPerHourPerSquareMeter)] + [InlineData("g·h⁻¹·mm⁻²", MassFluxUnit.GramPerHourPerSquareMillimeter)] + [InlineData("g·s⁻¹·cm⁻²", MassFluxUnit.GramPerSecondPerSquareCentimeter)] + [InlineData("g·s⁻¹·m⁻²", MassFluxUnit.GramPerSecondPerSquareMeter)] + [InlineData("g·s⁻¹·mm⁻²", MassFluxUnit.GramPerSecondPerSquareMillimeter)] + [InlineData("kg·h⁻¹·cm⁻²", MassFluxUnit.KilogramPerHourPerSquareCentimeter)] + [InlineData("kg·h⁻¹·m⁻²", MassFluxUnit.KilogramPerHourPerSquareMeter)] + [InlineData("kg·h⁻¹·mm⁻²", MassFluxUnit.KilogramPerHourPerSquareMillimeter)] + [InlineData("kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] + [InlineData("kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] + [InlineData("kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] + public void TryParseUnit(string abbreviation, MassFluxUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(MassFlux.TryParseUnit(abbreviation, out MassFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "g·h⁻¹·cm⁻²", MassFluxUnit.GramPerHourPerSquareCentimeter)] + [InlineData("en-US", "g·h⁻¹·m⁻²", MassFluxUnit.GramPerHourPerSquareMeter)] + [InlineData("en-US", "g·h⁻¹·mm⁻²", MassFluxUnit.GramPerHourPerSquareMillimeter)] + [InlineData("en-US", "g·s⁻¹·cm⁻²", MassFluxUnit.GramPerSecondPerSquareCentimeter)] + [InlineData("en-US", "g·s⁻¹·m⁻²", MassFluxUnit.GramPerSecondPerSquareMeter)] + [InlineData("en-US", "g·s⁻¹·mm⁻²", MassFluxUnit.GramPerSecondPerSquareMillimeter)] + [InlineData("en-US", "kg·h⁻¹·cm⁻²", MassFluxUnit.KilogramPerHourPerSquareCentimeter)] + [InlineData("en-US", "kg·h⁻¹·m⁻²", MassFluxUnit.KilogramPerHourPerSquareMeter)] + [InlineData("en-US", "kg·h⁻¹·mm⁻²", MassFluxUnit.KilogramPerHourPerSquareMillimeter)] + [InlineData("en-US", "kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] + [InlineData("en-US", "kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] + [InlineData("en-US", "kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MassFluxUnit expectedUnit) + { + Assert.True(MassFlux.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs index eebf93d9ed..4305c0a56b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs @@ -742,289 +742,134 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = MassFraction.ParseUnit("cg/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.CentigramPerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("cg/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.CentigramPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("dag/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.DecagramPerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("dag/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.DecagramPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("dg/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.DecigramPerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("dg/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.DecigramPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.DecimalFraction, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("g/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.GramPerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("g/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.GramPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("hg/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.HectogramPerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("hg/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.HectogramPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("kg/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.KilogramPerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("kg/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.KilogramPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("µg/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.MicrogramPerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("µg/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.MicrogramPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("mg/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.MilligramPerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("mg/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.MilligramPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("ng/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.NanogramPerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("ng/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.NanogramPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("ppb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.PartPerBillion, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("ppm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.PartPerMillion, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("‰", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.PartPerThousand, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("ppt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.PartPerTrillion, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("%", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.Percent, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassFraction.ParseUnit("% (w/w)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassFractionUnit.Percent, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cg/g", MassFractionUnit.CentigramPerGram)] + [InlineData("cg/kg", MassFractionUnit.CentigramPerKilogram)] + [InlineData("dag/g", MassFractionUnit.DecagramPerGram)] + [InlineData("dag/kg", MassFractionUnit.DecagramPerKilogram)] + [InlineData("dg/g", MassFractionUnit.DecigramPerGram)] + [InlineData("dg/kg", MassFractionUnit.DecigramPerKilogram)] + [InlineData("", MassFractionUnit.DecimalFraction)] + [InlineData("g/g", MassFractionUnit.GramPerGram)] + [InlineData("g/kg", MassFractionUnit.GramPerKilogram)] + [InlineData("hg/g", MassFractionUnit.HectogramPerGram)] + [InlineData("hg/kg", MassFractionUnit.HectogramPerKilogram)] + [InlineData("kg/g", MassFractionUnit.KilogramPerGram)] + [InlineData("kg/kg", MassFractionUnit.KilogramPerKilogram)] + [InlineData("µg/g", MassFractionUnit.MicrogramPerGram)] + [InlineData("µg/kg", MassFractionUnit.MicrogramPerKilogram)] + [InlineData("mg/g", MassFractionUnit.MilligramPerGram)] + [InlineData("mg/kg", MassFractionUnit.MilligramPerKilogram)] + [InlineData("ng/g", MassFractionUnit.NanogramPerGram)] + [InlineData("ng/kg", MassFractionUnit.NanogramPerKilogram)] + [InlineData("ppb", MassFractionUnit.PartPerBillion)] + [InlineData("ppm", MassFractionUnit.PartPerMillion)] + [InlineData("‰", MassFractionUnit.PartPerThousand)] + [InlineData("ppt", MassFractionUnit.PartPerTrillion)] + [InlineData("%", MassFractionUnit.Percent)] + [InlineData("% (w/w)", MassFractionUnit.Percent)] + public void ParseUnit(string abbreviation, MassFractionUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MassFractionUnit parsedUnit = MassFraction.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(MassFraction.TryParseUnit("cg/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.CentigramPerGram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("cg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.CentigramPerKilogram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("dag/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.DecagramPerGram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("dag/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.DecagramPerKilogram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("dg/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.DecigramPerGram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("dg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.DecigramPerKilogram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.DecimalFraction, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("g/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.GramPerGram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("g/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.GramPerKilogram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("hg/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.HectogramPerGram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("hg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.HectogramPerKilogram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("kg/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.KilogramPerGram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("kg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.KilogramPerKilogram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("µg/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.MicrogramPerGram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("µg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.MicrogramPerKilogram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("mg/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.MilligramPerGram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("mg/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.MilligramPerKilogram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("ng/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.NanogramPerGram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("ng/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.NanogramPerKilogram, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("ppb", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.PartPerBillion, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("ppm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.PartPerMillion, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("‰", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.PartPerThousand, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("ppt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.PartPerTrillion, parsedUnit); - } - - { - Assert.True(MassFraction.TryParseUnit("%", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.Percent, parsedUnit); - } + [Theory] + [InlineData("en-US", "cg/g", MassFractionUnit.CentigramPerGram)] + [InlineData("en-US", "cg/kg", MassFractionUnit.CentigramPerKilogram)] + [InlineData("en-US", "dag/g", MassFractionUnit.DecagramPerGram)] + [InlineData("en-US", "dag/kg", MassFractionUnit.DecagramPerKilogram)] + [InlineData("en-US", "dg/g", MassFractionUnit.DecigramPerGram)] + [InlineData("en-US", "dg/kg", MassFractionUnit.DecigramPerKilogram)] + [InlineData("en-US", "", MassFractionUnit.DecimalFraction)] + [InlineData("en-US", "g/g", MassFractionUnit.GramPerGram)] + [InlineData("en-US", "g/kg", MassFractionUnit.GramPerKilogram)] + [InlineData("en-US", "hg/g", MassFractionUnit.HectogramPerGram)] + [InlineData("en-US", "hg/kg", MassFractionUnit.HectogramPerKilogram)] + [InlineData("en-US", "kg/g", MassFractionUnit.KilogramPerGram)] + [InlineData("en-US", "kg/kg", MassFractionUnit.KilogramPerKilogram)] + [InlineData("en-US", "µg/g", MassFractionUnit.MicrogramPerGram)] + [InlineData("en-US", "µg/kg", MassFractionUnit.MicrogramPerKilogram)] + [InlineData("en-US", "mg/g", MassFractionUnit.MilligramPerGram)] + [InlineData("en-US", "mg/kg", MassFractionUnit.MilligramPerKilogram)] + [InlineData("en-US", "ng/g", MassFractionUnit.NanogramPerGram)] + [InlineData("en-US", "ng/kg", MassFractionUnit.NanogramPerKilogram)] + [InlineData("en-US", "ppb", MassFractionUnit.PartPerBillion)] + [InlineData("en-US", "ppm", MassFractionUnit.PartPerMillion)] + [InlineData("en-US", "‰", MassFractionUnit.PartPerThousand)] + [InlineData("en-US", "ppt", MassFractionUnit.PartPerTrillion)] + [InlineData("en-US", "%", MassFractionUnit.Percent)] + [InlineData("en-US", "% (w/w)", MassFractionUnit.Percent)] + public void ParseUnitWithCulture(string culture, string abbreviation, MassFractionUnit expectedUnit) + { + MassFractionUnit parsedUnit = MassFraction.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(MassFraction.TryParseUnit("% (w/w)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassFractionUnit.Percent, parsedUnit); - } + [Theory] + [InlineData("cg/g", MassFractionUnit.CentigramPerGram)] + [InlineData("cg/kg", MassFractionUnit.CentigramPerKilogram)] + [InlineData("dag/g", MassFractionUnit.DecagramPerGram)] + [InlineData("dag/kg", MassFractionUnit.DecagramPerKilogram)] + [InlineData("dg/g", MassFractionUnit.DecigramPerGram)] + [InlineData("dg/kg", MassFractionUnit.DecigramPerKilogram)] + [InlineData("", MassFractionUnit.DecimalFraction)] + [InlineData("g/g", MassFractionUnit.GramPerGram)] + [InlineData("g/kg", MassFractionUnit.GramPerKilogram)] + [InlineData("hg/g", MassFractionUnit.HectogramPerGram)] + [InlineData("hg/kg", MassFractionUnit.HectogramPerKilogram)] + [InlineData("kg/g", MassFractionUnit.KilogramPerGram)] + [InlineData("kg/kg", MassFractionUnit.KilogramPerKilogram)] + [InlineData("µg/g", MassFractionUnit.MicrogramPerGram)] + [InlineData("µg/kg", MassFractionUnit.MicrogramPerKilogram)] + [InlineData("mg/g", MassFractionUnit.MilligramPerGram)] + [InlineData("mg/kg", MassFractionUnit.MilligramPerKilogram)] + [InlineData("ng/g", MassFractionUnit.NanogramPerGram)] + [InlineData("ng/kg", MassFractionUnit.NanogramPerKilogram)] + [InlineData("ppb", MassFractionUnit.PartPerBillion)] + [InlineData("ppm", MassFractionUnit.PartPerMillion)] + [InlineData("‰", MassFractionUnit.PartPerThousand)] + [InlineData("ppt", MassFractionUnit.PartPerTrillion)] + [InlineData("%", MassFractionUnit.Percent)] + [InlineData("% (w/w)", MassFractionUnit.Percent)] + public void TryParseUnit(string abbreviation, MassFractionUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(MassFraction.TryParseUnit(abbreviation, out MassFractionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cg/g", MassFractionUnit.CentigramPerGram)] + [InlineData("en-US", "cg/kg", MassFractionUnit.CentigramPerKilogram)] + [InlineData("en-US", "dag/g", MassFractionUnit.DecagramPerGram)] + [InlineData("en-US", "dag/kg", MassFractionUnit.DecagramPerKilogram)] + [InlineData("en-US", "dg/g", MassFractionUnit.DecigramPerGram)] + [InlineData("en-US", "dg/kg", MassFractionUnit.DecigramPerKilogram)] + [InlineData("en-US", "", MassFractionUnit.DecimalFraction)] + [InlineData("en-US", "g/g", MassFractionUnit.GramPerGram)] + [InlineData("en-US", "g/kg", MassFractionUnit.GramPerKilogram)] + [InlineData("en-US", "hg/g", MassFractionUnit.HectogramPerGram)] + [InlineData("en-US", "hg/kg", MassFractionUnit.HectogramPerKilogram)] + [InlineData("en-US", "kg/g", MassFractionUnit.KilogramPerGram)] + [InlineData("en-US", "kg/kg", MassFractionUnit.KilogramPerKilogram)] + [InlineData("en-US", "µg/g", MassFractionUnit.MicrogramPerGram)] + [InlineData("en-US", "µg/kg", MassFractionUnit.MicrogramPerKilogram)] + [InlineData("en-US", "mg/g", MassFractionUnit.MilligramPerGram)] + [InlineData("en-US", "mg/kg", MassFractionUnit.MilligramPerKilogram)] + [InlineData("en-US", "ng/g", MassFractionUnit.NanogramPerGram)] + [InlineData("en-US", "ng/kg", MassFractionUnit.NanogramPerKilogram)] + [InlineData("en-US", "ppb", MassFractionUnit.PartPerBillion)] + [InlineData("en-US", "ppm", MassFractionUnit.PartPerMillion)] + [InlineData("en-US", "‰", MassFractionUnit.PartPerThousand)] + [InlineData("en-US", "ppt", MassFractionUnit.PartPerTrillion)] + [InlineData("en-US", "%", MassFractionUnit.Percent)] + [InlineData("en-US", "% (w/w)", MassFractionUnit.Percent)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MassFractionUnit expectedUnit) + { + Assert.True(MassFraction.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassFractionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs index 557e88fd0a..e017d09326 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs @@ -821,322 +821,146 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("g·cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("g·dm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("g·m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("g·mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("kg·cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("kg·dm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("kg·m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("kg·mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("kt·cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("kt·dm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("kt·m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("kt·mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareMilimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("Mt·cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("Mt·dm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("Mt·m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("Mt·mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareMilimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("mg·cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("mg·dm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("mg·m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("mg·mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("lb·ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.PoundSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("lb·in²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.PoundSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("slug·ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.SlugSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("slug·in²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.SlugSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("t·cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("t·dm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("t·m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MassMomentOfInertia.ParseUnit("t·mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareMilimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("g·cm²", MassMomentOfInertiaUnit.GramSquareCentimeter)] + [InlineData("g·dm²", MassMomentOfInertiaUnit.GramSquareDecimeter)] + [InlineData("g·m²", MassMomentOfInertiaUnit.GramSquareMeter)] + [InlineData("g·mm²", MassMomentOfInertiaUnit.GramSquareMillimeter)] + [InlineData("kg·cm²", MassMomentOfInertiaUnit.KilogramSquareCentimeter)] + [InlineData("kg·dm²", MassMomentOfInertiaUnit.KilogramSquareDecimeter)] + [InlineData("kg·m²", MassMomentOfInertiaUnit.KilogramSquareMeter)] + [InlineData("kg·mm²", MassMomentOfInertiaUnit.KilogramSquareMillimeter)] + [InlineData("kt·cm²", MassMomentOfInertiaUnit.KilotonneSquareCentimeter)] + [InlineData("kt·dm²", MassMomentOfInertiaUnit.KilotonneSquareDecimeter)] + [InlineData("kt·m²", MassMomentOfInertiaUnit.KilotonneSquareMeter)] + [InlineData("kt·mm²", MassMomentOfInertiaUnit.KilotonneSquareMilimeter)] + [InlineData("Mt·cm²", MassMomentOfInertiaUnit.MegatonneSquareCentimeter)] + [InlineData("Mt·dm²", MassMomentOfInertiaUnit.MegatonneSquareDecimeter)] + [InlineData("Mt·m²", MassMomentOfInertiaUnit.MegatonneSquareMeter)] + [InlineData("Mt·mm²", MassMomentOfInertiaUnit.MegatonneSquareMilimeter)] + [InlineData("mg·cm²", MassMomentOfInertiaUnit.MilligramSquareCentimeter)] + [InlineData("mg·dm²", MassMomentOfInertiaUnit.MilligramSquareDecimeter)] + [InlineData("mg·m²", MassMomentOfInertiaUnit.MilligramSquareMeter)] + [InlineData("mg·mm²", MassMomentOfInertiaUnit.MilligramSquareMillimeter)] + [InlineData("lb·ft²", MassMomentOfInertiaUnit.PoundSquareFoot)] + [InlineData("lb·in²", MassMomentOfInertiaUnit.PoundSquareInch)] + [InlineData("slug·ft²", MassMomentOfInertiaUnit.SlugSquareFoot)] + [InlineData("slug·in²", MassMomentOfInertiaUnit.SlugSquareInch)] + [InlineData("t·cm²", MassMomentOfInertiaUnit.TonneSquareCentimeter)] + [InlineData("t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] + [InlineData("t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] + [InlineData("t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] + public void ParseUnit(string abbreviation, MassMomentOfInertiaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MassMomentOfInertiaUnit parsedUnit = MassMomentOfInertia.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(MassMomentOfInertia.TryParseUnit("g·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareCentimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("g·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareDecimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("g·m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareMeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("g·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.GramSquareMillimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("kg·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareCentimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("kg·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareDecimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("kg·m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareMeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("kg·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.KilogramSquareMillimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("kt·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareCentimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("kt·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareDecimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("kt·m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareMeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("kt·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.KilotonneSquareMilimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("Mt·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareCentimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("Mt·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareDecimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("Mt·m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareMeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("Mt·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.MegatonneSquareMilimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("mg·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareCentimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("mg·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareDecimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("mg·m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareMeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("mg·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.MilligramSquareMillimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("lb·ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.PoundSquareFoot, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("lb·in²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.PoundSquareInch, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("slug·ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.SlugSquareFoot, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("slug·in²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.SlugSquareInch, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("t·cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareCentimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("t·dm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareDecimeter, parsedUnit); - } - - { - Assert.True(MassMomentOfInertia.TryParseUnit("t·m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareMeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "g·cm²", MassMomentOfInertiaUnit.GramSquareCentimeter)] + [InlineData("en-US", "g·dm²", MassMomentOfInertiaUnit.GramSquareDecimeter)] + [InlineData("en-US", "g·m²", MassMomentOfInertiaUnit.GramSquareMeter)] + [InlineData("en-US", "g·mm²", MassMomentOfInertiaUnit.GramSquareMillimeter)] + [InlineData("en-US", "kg·cm²", MassMomentOfInertiaUnit.KilogramSquareCentimeter)] + [InlineData("en-US", "kg·dm²", MassMomentOfInertiaUnit.KilogramSquareDecimeter)] + [InlineData("en-US", "kg·m²", MassMomentOfInertiaUnit.KilogramSquareMeter)] + [InlineData("en-US", "kg·mm²", MassMomentOfInertiaUnit.KilogramSquareMillimeter)] + [InlineData("en-US", "kt·cm²", MassMomentOfInertiaUnit.KilotonneSquareCentimeter)] + [InlineData("en-US", "kt·dm²", MassMomentOfInertiaUnit.KilotonneSquareDecimeter)] + [InlineData("en-US", "kt·m²", MassMomentOfInertiaUnit.KilotonneSquareMeter)] + [InlineData("en-US", "kt·mm²", MassMomentOfInertiaUnit.KilotonneSquareMilimeter)] + [InlineData("en-US", "Mt·cm²", MassMomentOfInertiaUnit.MegatonneSquareCentimeter)] + [InlineData("en-US", "Mt·dm²", MassMomentOfInertiaUnit.MegatonneSquareDecimeter)] + [InlineData("en-US", "Mt·m²", MassMomentOfInertiaUnit.MegatonneSquareMeter)] + [InlineData("en-US", "Mt·mm²", MassMomentOfInertiaUnit.MegatonneSquareMilimeter)] + [InlineData("en-US", "mg·cm²", MassMomentOfInertiaUnit.MilligramSquareCentimeter)] + [InlineData("en-US", "mg·dm²", MassMomentOfInertiaUnit.MilligramSquareDecimeter)] + [InlineData("en-US", "mg·m²", MassMomentOfInertiaUnit.MilligramSquareMeter)] + [InlineData("en-US", "mg·mm²", MassMomentOfInertiaUnit.MilligramSquareMillimeter)] + [InlineData("en-US", "lb·ft²", MassMomentOfInertiaUnit.PoundSquareFoot)] + [InlineData("en-US", "lb·in²", MassMomentOfInertiaUnit.PoundSquareInch)] + [InlineData("en-US", "slug·ft²", MassMomentOfInertiaUnit.SlugSquareFoot)] + [InlineData("en-US", "slug·in²", MassMomentOfInertiaUnit.SlugSquareInch)] + [InlineData("en-US", "t·cm²", MassMomentOfInertiaUnit.TonneSquareCentimeter)] + [InlineData("en-US", "t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] + [InlineData("en-US", "t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] + [InlineData("en-US", "t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, MassMomentOfInertiaUnit expectedUnit) + { + MassMomentOfInertiaUnit parsedUnit = MassMomentOfInertia.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(MassMomentOfInertia.TryParseUnit("t·mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassMomentOfInertiaUnit.TonneSquareMilimeter, parsedUnit); - } + [Theory] + [InlineData("g·cm²", MassMomentOfInertiaUnit.GramSquareCentimeter)] + [InlineData("g·dm²", MassMomentOfInertiaUnit.GramSquareDecimeter)] + [InlineData("g·m²", MassMomentOfInertiaUnit.GramSquareMeter)] + [InlineData("g·mm²", MassMomentOfInertiaUnit.GramSquareMillimeter)] + [InlineData("kg·cm²", MassMomentOfInertiaUnit.KilogramSquareCentimeter)] + [InlineData("kg·dm²", MassMomentOfInertiaUnit.KilogramSquareDecimeter)] + [InlineData("kg·m²", MassMomentOfInertiaUnit.KilogramSquareMeter)] + [InlineData("kg·mm²", MassMomentOfInertiaUnit.KilogramSquareMillimeter)] + [InlineData("kt·cm²", MassMomentOfInertiaUnit.KilotonneSquareCentimeter)] + [InlineData("kt·dm²", MassMomentOfInertiaUnit.KilotonneSquareDecimeter)] + [InlineData("kt·m²", MassMomentOfInertiaUnit.KilotonneSquareMeter)] + [InlineData("kt·mm²", MassMomentOfInertiaUnit.KilotonneSquareMilimeter)] + [InlineData("Mt·cm²", MassMomentOfInertiaUnit.MegatonneSquareCentimeter)] + [InlineData("Mt·dm²", MassMomentOfInertiaUnit.MegatonneSquareDecimeter)] + [InlineData("Mt·m²", MassMomentOfInertiaUnit.MegatonneSquareMeter)] + [InlineData("Mt·mm²", MassMomentOfInertiaUnit.MegatonneSquareMilimeter)] + [InlineData("mg·cm²", MassMomentOfInertiaUnit.MilligramSquareCentimeter)] + [InlineData("mg·dm²", MassMomentOfInertiaUnit.MilligramSquareDecimeter)] + [InlineData("mg·m²", MassMomentOfInertiaUnit.MilligramSquareMeter)] + [InlineData("mg·mm²", MassMomentOfInertiaUnit.MilligramSquareMillimeter)] + [InlineData("lb·ft²", MassMomentOfInertiaUnit.PoundSquareFoot)] + [InlineData("lb·in²", MassMomentOfInertiaUnit.PoundSquareInch)] + [InlineData("slug·ft²", MassMomentOfInertiaUnit.SlugSquareFoot)] + [InlineData("slug·in²", MassMomentOfInertiaUnit.SlugSquareInch)] + [InlineData("t·cm²", MassMomentOfInertiaUnit.TonneSquareCentimeter)] + [InlineData("t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] + [InlineData("t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] + [InlineData("t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] + public void TryParseUnit(string abbreviation, MassMomentOfInertiaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(MassMomentOfInertia.TryParseUnit(abbreviation, out MassMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "g·cm²", MassMomentOfInertiaUnit.GramSquareCentimeter)] + [InlineData("en-US", "g·dm²", MassMomentOfInertiaUnit.GramSquareDecimeter)] + [InlineData("en-US", "g·m²", MassMomentOfInertiaUnit.GramSquareMeter)] + [InlineData("en-US", "g·mm²", MassMomentOfInertiaUnit.GramSquareMillimeter)] + [InlineData("en-US", "kg·cm²", MassMomentOfInertiaUnit.KilogramSquareCentimeter)] + [InlineData("en-US", "kg·dm²", MassMomentOfInertiaUnit.KilogramSquareDecimeter)] + [InlineData("en-US", "kg·m²", MassMomentOfInertiaUnit.KilogramSquareMeter)] + [InlineData("en-US", "kg·mm²", MassMomentOfInertiaUnit.KilogramSquareMillimeter)] + [InlineData("en-US", "kt·cm²", MassMomentOfInertiaUnit.KilotonneSquareCentimeter)] + [InlineData("en-US", "kt·dm²", MassMomentOfInertiaUnit.KilotonneSquareDecimeter)] + [InlineData("en-US", "kt·m²", MassMomentOfInertiaUnit.KilotonneSquareMeter)] + [InlineData("en-US", "kt·mm²", MassMomentOfInertiaUnit.KilotonneSquareMilimeter)] + [InlineData("en-US", "Mt·cm²", MassMomentOfInertiaUnit.MegatonneSquareCentimeter)] + [InlineData("en-US", "Mt·dm²", MassMomentOfInertiaUnit.MegatonneSquareDecimeter)] + [InlineData("en-US", "Mt·m²", MassMomentOfInertiaUnit.MegatonneSquareMeter)] + [InlineData("en-US", "Mt·mm²", MassMomentOfInertiaUnit.MegatonneSquareMilimeter)] + [InlineData("en-US", "mg·cm²", MassMomentOfInertiaUnit.MilligramSquareCentimeter)] + [InlineData("en-US", "mg·dm²", MassMomentOfInertiaUnit.MilligramSquareDecimeter)] + [InlineData("en-US", "mg·m²", MassMomentOfInertiaUnit.MilligramSquareMeter)] + [InlineData("en-US", "mg·mm²", MassMomentOfInertiaUnit.MilligramSquareMillimeter)] + [InlineData("en-US", "lb·ft²", MassMomentOfInertiaUnit.PoundSquareFoot)] + [InlineData("en-US", "lb·in²", MassMomentOfInertiaUnit.PoundSquareInch)] + [InlineData("en-US", "slug·ft²", MassMomentOfInertiaUnit.SlugSquareFoot)] + [InlineData("en-US", "slug·in²", MassMomentOfInertiaUnit.SlugSquareInch)] + [InlineData("en-US", "t·cm²", MassMomentOfInertiaUnit.TonneSquareCentimeter)] + [InlineData("en-US", "t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] + [InlineData("en-US", "t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] + [InlineData("en-US", "t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MassMomentOfInertiaUnit expectedUnit) + { + Assert.True(MassMomentOfInertia.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs index 1856a1d0ae..c7ef259756 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs @@ -1398,819 +1398,262 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Mass.ParseUnit("cg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Centigram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("сг", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Centigram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("厘克", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Centigram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("dag", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Decagram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("даг", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Decagram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("十克", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Decagram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("dg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Decigram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("дг", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Decigram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("分克", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Decigram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("em", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.EarthMass, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("fg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Femtogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("фг", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Femtogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("飞克", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Femtogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("gr", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Grain, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Gram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("г", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Gram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("克", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Gram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("hg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Hectogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("гг", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Hectogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("百克", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Hectogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Kilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("кг", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Kilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("千克", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Kilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("klb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Kilopound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("klbs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Kilopound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("klbm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Kilopound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("кфунт", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Kilopound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("千磅", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Kilopound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("kt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Kilotonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("кт", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Kilotonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("千吨", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Kilotonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("cwt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.LongHundredweight, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("long tn", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.LongTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("тонна большая", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.LongTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("长吨", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.LongTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("Mlb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Megapound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("Mlbs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Megapound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("Mlbm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Megapound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("Мфунт", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Megapound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("兆磅", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Megapound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("Mt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Megatonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("Мт", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Megatonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("兆吨", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Megatonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("µg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Microgram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("мкг", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Microgram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("微克", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Microgram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("mg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Milligram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("мг", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Milligram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("毫克", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Milligram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("ng", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Nanogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("нг", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Nanogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("纳克", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Nanogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("oz", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Ounce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("盎司", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Ounce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("pg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Picogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("пг", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Picogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("皮克", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Picogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("lb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Pound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("lbs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Pound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("lbm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Pound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("фунт", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Pound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("磅", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Pound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("cwt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.ShortHundredweight, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("t (short)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.ShortTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("short tn", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.ShortTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("ST", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.ShortTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("тонна малая", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.ShortTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("短吨", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.ShortTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("slug", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Slug, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("M☉", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.SolarMass, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("M⊙", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.SolarMass, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("st", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Stone, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("t", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MassUnit.Tonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("т", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MassUnit.Tonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Mass.ParseUnit("吨", CultureInfo.GetCultureInfo("zh-CN")); - Assert.Equal(MassUnit.Tonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + [Theory] + [InlineData("cg", MassUnit.Centigram)] + [InlineData("dag", MassUnit.Decagram)] + [InlineData("dg", MassUnit.Decigram)] + [InlineData("em", MassUnit.EarthMass)] + [InlineData("fg", MassUnit.Femtogram)] + [InlineData("gr", MassUnit.Grain)] + [InlineData("g", MassUnit.Gram)] + [InlineData("hg", MassUnit.Hectogram)] + [InlineData("kg", MassUnit.Kilogram)] + [InlineData("klb", MassUnit.Kilopound)] + [InlineData("klbs", MassUnit.Kilopound)] + [InlineData("klbm", MassUnit.Kilopound)] + [InlineData("kt", MassUnit.Kilotonne)] + [InlineData("long tn", MassUnit.LongTon)] + [InlineData("Mlb", MassUnit.Megapound)] + [InlineData("Mlbs", MassUnit.Megapound)] + [InlineData("Mlbm", MassUnit.Megapound)] + [InlineData("Mt", MassUnit.Megatonne)] + [InlineData("µg", MassUnit.Microgram)] + [InlineData("mg", MassUnit.Milligram)] + [InlineData("ng", MassUnit.Nanogram)] + [InlineData("oz", MassUnit.Ounce)] + [InlineData("pg", MassUnit.Picogram)] + [InlineData("lb", MassUnit.Pound)] + [InlineData("lbs", MassUnit.Pound)] + [InlineData("lbm", MassUnit.Pound)] + [InlineData("t (short)", MassUnit.ShortTon)] + [InlineData("short tn", MassUnit.ShortTon)] + [InlineData("ST", MassUnit.ShortTon)] + [InlineData("slug", MassUnit.Slug)] + [InlineData("M☉", MassUnit.SolarMass)] + [InlineData("M⊙", MassUnit.SolarMass)] + [InlineData("st", MassUnit.Stone)] + [InlineData("t", MassUnit.Tonne)] + public void ParseUnit(string abbreviation, MassUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MassUnit parsedUnit = Mass.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cg", MassUnit.Centigram)] + [InlineData("en-US", "dag", MassUnit.Decagram)] + [InlineData("en-US", "dg", MassUnit.Decigram)] + [InlineData("en-US", "em", MassUnit.EarthMass)] + [InlineData("en-US", "fg", MassUnit.Femtogram)] + [InlineData("en-US", "gr", MassUnit.Grain)] + [InlineData("en-US", "g", MassUnit.Gram)] + [InlineData("en-US", "hg", MassUnit.Hectogram)] + [InlineData("en-US", "kg", MassUnit.Kilogram)] + [InlineData("en-US", "klb", MassUnit.Kilopound)] + [InlineData("en-US", "klbs", MassUnit.Kilopound)] + [InlineData("en-US", "klbm", MassUnit.Kilopound)] + [InlineData("en-US", "kt", MassUnit.Kilotonne)] + [InlineData("en-US", "long tn", MassUnit.LongTon)] + [InlineData("en-US", "Mlb", MassUnit.Megapound)] + [InlineData("en-US", "Mlbs", MassUnit.Megapound)] + [InlineData("en-US", "Mlbm", MassUnit.Megapound)] + [InlineData("en-US", "Mt", MassUnit.Megatonne)] + [InlineData("en-US", "µg", MassUnit.Microgram)] + [InlineData("en-US", "mg", MassUnit.Milligram)] + [InlineData("en-US", "ng", MassUnit.Nanogram)] + [InlineData("en-US", "oz", MassUnit.Ounce)] + [InlineData("en-US", "pg", MassUnit.Picogram)] + [InlineData("en-US", "lb", MassUnit.Pound)] + [InlineData("en-US", "lbs", MassUnit.Pound)] + [InlineData("en-US", "lbm", MassUnit.Pound)] + [InlineData("en-US", "t (short)", MassUnit.ShortTon)] + [InlineData("en-US", "short tn", MassUnit.ShortTon)] + [InlineData("en-US", "ST", MassUnit.ShortTon)] + [InlineData("en-US", "slug", MassUnit.Slug)] + [InlineData("en-US", "M☉", MassUnit.SolarMass)] + [InlineData("en-US", "M⊙", MassUnit.SolarMass)] + [InlineData("en-US", "st", MassUnit.Stone)] + [InlineData("en-US", "t", MassUnit.Tonne)] + [InlineData("ru-RU", "сг", MassUnit.Centigram)] + [InlineData("ru-RU", "даг", MassUnit.Decagram)] + [InlineData("ru-RU", "дг", MassUnit.Decigram)] + [InlineData("ru-RU", "фг", MassUnit.Femtogram)] + [InlineData("ru-RU", "г", MassUnit.Gram)] + [InlineData("ru-RU", "гг", MassUnit.Hectogram)] + [InlineData("ru-RU", "кг", MassUnit.Kilogram)] + [InlineData("ru-RU", "кфунт", MassUnit.Kilopound)] + [InlineData("ru-RU", "кт", MassUnit.Kilotonne)] + [InlineData("ru-RU", "тонна большая", MassUnit.LongTon)] + [InlineData("ru-RU", "Мфунт", MassUnit.Megapound)] + [InlineData("ru-RU", "Мт", MassUnit.Megatonne)] + [InlineData("ru-RU", "мкг", MassUnit.Microgram)] + [InlineData("ru-RU", "мг", MassUnit.Milligram)] + [InlineData("ru-RU", "нг", MassUnit.Nanogram)] + [InlineData("ru-RU", "пг", MassUnit.Picogram)] + [InlineData("ru-RU", "фунт", MassUnit.Pound)] + [InlineData("ru-RU", "тонна малая", MassUnit.ShortTon)] + [InlineData("ru-RU", "т", MassUnit.Tonne)] + [InlineData("zh-CN", "厘克", MassUnit.Centigram)] + [InlineData("zh-CN", "十克", MassUnit.Decagram)] + [InlineData("zh-CN", "分克", MassUnit.Decigram)] + [InlineData("zh-CN", "飞克", MassUnit.Femtogram)] + [InlineData("zh-CN", "克", MassUnit.Gram)] + [InlineData("zh-CN", "百克", MassUnit.Hectogram)] + [InlineData("zh-CN", "千克", MassUnit.Kilogram)] + [InlineData("zh-CN", "千磅", MassUnit.Kilopound)] + [InlineData("zh-CN", "千吨", MassUnit.Kilotonne)] + [InlineData("zh-CN", "长吨", MassUnit.LongTon)] + [InlineData("zh-CN", "兆磅", MassUnit.Megapound)] + [InlineData("zh-CN", "兆吨", MassUnit.Megatonne)] + [InlineData("zh-CN", "微克", MassUnit.Microgram)] + [InlineData("zh-CN", "毫克", MassUnit.Milligram)] + [InlineData("zh-CN", "纳克", MassUnit.Nanogram)] + [InlineData("zh-CN", "盎司", MassUnit.Ounce)] + [InlineData("zh-CN", "皮克", MassUnit.Picogram)] + [InlineData("zh-CN", "磅", MassUnit.Pound)] + [InlineData("zh-CN", "短吨", MassUnit.ShortTon)] + [InlineData("zh-CN", "吨", MassUnit.Tonne)] + public void ParseUnitWithCulture(string culture, string abbreviation, MassUnit expectedUnit) + { + MassUnit parsedUnit = Mass.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "cwt")] // [LongHundredweight, ShortHundredweight] + public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) { - { - Assert.True(Mass.TryParseUnit("cg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Centigram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("сг", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Centigram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("厘克", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Centigram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("dag", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Decagram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("даг", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Decagram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("十克", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Decagram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("dg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Decigram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("дг", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Decigram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("分克", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Decigram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("em", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.EarthMass, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("fg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Femtogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("фг", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Femtogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("飞克", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Femtogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("gr", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Grain, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Gram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("г", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Gram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("克", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Gram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("hg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Hectogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("гг", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Hectogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("百克", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Hectogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Kilogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("кг", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Kilogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("千克", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Kilogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("klb", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Kilopound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("klbs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Kilopound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("klbm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Kilopound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("кфунт", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Kilopound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("千磅", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Kilopound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("kt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Kilotonne, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("кт", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Kilotonne, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("千吨", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Kilotonne, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("long tn", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.LongTon, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("тонна большая", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.LongTon, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("长吨", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.LongTon, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("Mlb", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Megapound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("Mlbs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Megapound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("Mlbm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Megapound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("Мфунт", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Megapound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("兆磅", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Megapound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("Mt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Megatonne, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("Мт", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Megatonne, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("兆吨", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Megatonne, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("µg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Microgram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("мкг", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Microgram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("微克", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Microgram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("mg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Milligram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("мг", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Milligram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("毫克", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Milligram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("ng", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Nanogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("нг", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Nanogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("纳克", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Nanogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("oz", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Ounce, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("盎司", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Ounce, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("pg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Picogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("пг", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Picogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("皮克", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Picogram, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("lb", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Pound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("lbs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Pound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("lbm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Pound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("фунт", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Pound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("磅", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Pound, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("t (short)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.ShortTon, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("short tn", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.ShortTon, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("тонна малая", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.ShortTon, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("短吨", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.ShortTon, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("slug", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Slug, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("M☉", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.SolarMass, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("M⊙", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.SolarMass, parsedUnit); - } - - { - Assert.True(Mass.TryParseUnit("t", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MassUnit.Tonne, parsedUnit); - } + Assert.Throws(() => Mass.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture))); + } - { - Assert.True(Mass.TryParseUnit("т", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MassUnit.Tonne, parsedUnit); - } + [Theory] + [InlineData("cg", MassUnit.Centigram)] + [InlineData("dag", MassUnit.Decagram)] + [InlineData("dg", MassUnit.Decigram)] + [InlineData("em", MassUnit.EarthMass)] + [InlineData("fg", MassUnit.Femtogram)] + [InlineData("gr", MassUnit.Grain)] + [InlineData("g", MassUnit.Gram)] + [InlineData("hg", MassUnit.Hectogram)] + [InlineData("kg", MassUnit.Kilogram)] + [InlineData("klb", MassUnit.Kilopound)] + [InlineData("klbs", MassUnit.Kilopound)] + [InlineData("klbm", MassUnit.Kilopound)] + [InlineData("kt", MassUnit.Kilotonne)] + [InlineData("long tn", MassUnit.LongTon)] + [InlineData("Mlb", MassUnit.Megapound)] + [InlineData("Mlbs", MassUnit.Megapound)] + [InlineData("Mlbm", MassUnit.Megapound)] + [InlineData("Mt", MassUnit.Megatonne)] + [InlineData("µg", MassUnit.Microgram)] + [InlineData("mg", MassUnit.Milligram)] + [InlineData("ng", MassUnit.Nanogram)] + [InlineData("oz", MassUnit.Ounce)] + [InlineData("pg", MassUnit.Picogram)] + [InlineData("lb", MassUnit.Pound)] + [InlineData("lbs", MassUnit.Pound)] + [InlineData("lbm", MassUnit.Pound)] + [InlineData("t (short)", MassUnit.ShortTon)] + [InlineData("short tn", MassUnit.ShortTon)] + [InlineData("ST", MassUnit.ShortTon)] + [InlineData("slug", MassUnit.Slug)] + [InlineData("M☉", MassUnit.SolarMass)] + [InlineData("M⊙", MassUnit.SolarMass)] + [InlineData("st", MassUnit.Stone)] + [InlineData("t", MassUnit.Tonne)] + public void TryParseUnit(string abbreviation, MassUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Mass.TryParseUnit(abbreviation, out MassUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Mass.TryParseUnit("吨", CultureInfo.GetCultureInfo("zh-CN"), out var parsedUnit)); - Assert.Equal(MassUnit.Tonne, parsedUnit); - } + [Theory] + [InlineData("en-US", "cg", MassUnit.Centigram)] + [InlineData("en-US", "dag", MassUnit.Decagram)] + [InlineData("en-US", "dg", MassUnit.Decigram)] + [InlineData("en-US", "em", MassUnit.EarthMass)] + [InlineData("en-US", "fg", MassUnit.Femtogram)] + [InlineData("en-US", "gr", MassUnit.Grain)] + [InlineData("en-US", "g", MassUnit.Gram)] + [InlineData("en-US", "hg", MassUnit.Hectogram)] + [InlineData("en-US", "kg", MassUnit.Kilogram)] + [InlineData("en-US", "klb", MassUnit.Kilopound)] + [InlineData("en-US", "klbs", MassUnit.Kilopound)] + [InlineData("en-US", "klbm", MassUnit.Kilopound)] + [InlineData("en-US", "kt", MassUnit.Kilotonne)] + [InlineData("en-US", "long tn", MassUnit.LongTon)] + [InlineData("en-US", "Mlb", MassUnit.Megapound)] + [InlineData("en-US", "Mlbs", MassUnit.Megapound)] + [InlineData("en-US", "Mlbm", MassUnit.Megapound)] + [InlineData("en-US", "Mt", MassUnit.Megatonne)] + [InlineData("en-US", "µg", MassUnit.Microgram)] + [InlineData("en-US", "mg", MassUnit.Milligram)] + [InlineData("en-US", "ng", MassUnit.Nanogram)] + [InlineData("en-US", "oz", MassUnit.Ounce)] + [InlineData("en-US", "pg", MassUnit.Picogram)] + [InlineData("en-US", "lb", MassUnit.Pound)] + [InlineData("en-US", "lbs", MassUnit.Pound)] + [InlineData("en-US", "lbm", MassUnit.Pound)] + [InlineData("en-US", "t (short)", MassUnit.ShortTon)] + [InlineData("en-US", "short tn", MassUnit.ShortTon)] + [InlineData("en-US", "ST", MassUnit.ShortTon)] + [InlineData("en-US", "slug", MassUnit.Slug)] + [InlineData("en-US", "M☉", MassUnit.SolarMass)] + [InlineData("en-US", "M⊙", MassUnit.SolarMass)] + [InlineData("en-US", "st", MassUnit.Stone)] + [InlineData("en-US", "t", MassUnit.Tonne)] + [InlineData("ru-RU", "сг", MassUnit.Centigram)] + [InlineData("ru-RU", "даг", MassUnit.Decagram)] + [InlineData("ru-RU", "дг", MassUnit.Decigram)] + [InlineData("ru-RU", "фг", MassUnit.Femtogram)] + [InlineData("ru-RU", "г", MassUnit.Gram)] + [InlineData("ru-RU", "гг", MassUnit.Hectogram)] + [InlineData("ru-RU", "кг", MassUnit.Kilogram)] + [InlineData("ru-RU", "кфунт", MassUnit.Kilopound)] + [InlineData("ru-RU", "кт", MassUnit.Kilotonne)] + [InlineData("ru-RU", "тонна большая", MassUnit.LongTon)] + [InlineData("ru-RU", "Мфунт", MassUnit.Megapound)] + [InlineData("ru-RU", "Мт", MassUnit.Megatonne)] + [InlineData("ru-RU", "мкг", MassUnit.Microgram)] + [InlineData("ru-RU", "мг", MassUnit.Milligram)] + [InlineData("ru-RU", "нг", MassUnit.Nanogram)] + [InlineData("ru-RU", "пг", MassUnit.Picogram)] + [InlineData("ru-RU", "фунт", MassUnit.Pound)] + [InlineData("ru-RU", "тонна малая", MassUnit.ShortTon)] + [InlineData("ru-RU", "т", MassUnit.Tonne)] + [InlineData("zh-CN", "厘克", MassUnit.Centigram)] + [InlineData("zh-CN", "十克", MassUnit.Decagram)] + [InlineData("zh-CN", "分克", MassUnit.Decigram)] + [InlineData("zh-CN", "飞克", MassUnit.Femtogram)] + [InlineData("zh-CN", "克", MassUnit.Gram)] + [InlineData("zh-CN", "百克", MassUnit.Hectogram)] + [InlineData("zh-CN", "千克", MassUnit.Kilogram)] + [InlineData("zh-CN", "千磅", MassUnit.Kilopound)] + [InlineData("zh-CN", "千吨", MassUnit.Kilotonne)] + [InlineData("zh-CN", "长吨", MassUnit.LongTon)] + [InlineData("zh-CN", "兆磅", MassUnit.Megapound)] + [InlineData("zh-CN", "兆吨", MassUnit.Megatonne)] + [InlineData("zh-CN", "微克", MassUnit.Microgram)] + [InlineData("zh-CN", "毫克", MassUnit.Milligram)] + [InlineData("zh-CN", "纳克", MassUnit.Nanogram)] + [InlineData("zh-CN", "盎司", MassUnit.Ounce)] + [InlineData("zh-CN", "皮克", MassUnit.Picogram)] + [InlineData("zh-CN", "磅", MassUnit.Pound)] + [InlineData("zh-CN", "短吨", MassUnit.ShortTon)] + [InlineData("zh-CN", "吨", MassUnit.Tonne)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MassUnit expectedUnit) + { + Assert.True(Mass.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cwt")] // [LongHundredweight, ShortHundredweight] + public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) + { + Assert.False(Mass.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out _)); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs index a1ab73c241..a577ebf0ba 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs @@ -246,47 +246,46 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("mmol/kg", MolalityUnit.MillimolePerKilogram)] + [InlineData("mol/g", MolalityUnit.MolePerGram)] + [InlineData("mol/kg", MolalityUnit.MolePerKilogram)] + public void ParseUnit(string abbreviation, MolalityUnit expectedUnit) { - try - { - var parsedUnit = Molality.ParseUnit("mmol/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolalityUnit.MillimolePerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molality.ParseUnit("mol/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolalityUnit.MolePerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molality.ParseUnit("mol/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolalityUnit.MolePerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MolalityUnit parsedUnit = Molality.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "mmol/kg", MolalityUnit.MillimolePerKilogram)] + [InlineData("en-US", "mol/g", MolalityUnit.MolePerGram)] + [InlineData("en-US", "mol/kg", MolalityUnit.MolePerKilogram)] + public void ParseUnitWithCulture(string culture, string abbreviation, MolalityUnit expectedUnit) { - { - Assert.True(Molality.TryParseUnit("mmol/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolalityUnit.MillimolePerKilogram, parsedUnit); - } - - { - Assert.True(Molality.TryParseUnit("mol/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolalityUnit.MolePerGram, parsedUnit); - } + MolalityUnit parsedUnit = Molality.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Molality.TryParseUnit("mol/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolalityUnit.MolePerKilogram, parsedUnit); - } + [Theory] + [InlineData("mmol/kg", MolalityUnit.MillimolePerKilogram)] + [InlineData("mol/g", MolalityUnit.MolePerGram)] + [InlineData("mol/kg", MolalityUnit.MolePerKilogram)] + public void TryParseUnit(string abbreviation, MolalityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Molality.TryParseUnit(abbreviation, out MolalityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "mmol/kg", MolalityUnit.MillimolePerKilogram)] + [InlineData("en-US", "mol/g", MolalityUnit.MolePerGram)] + [InlineData("en-US", "mol/kg", MolalityUnit.MolePerKilogram)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MolalityUnit expectedUnit) + { + Assert.True(Molality.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolalityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs index 0a676afff3..0442cfaf67 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs @@ -246,47 +246,46 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("J/mol", MolarEnergyUnit.JoulePerMole)] + [InlineData("kJ/mol", MolarEnergyUnit.KilojoulePerMole)] + [InlineData("MJ/mol", MolarEnergyUnit.MegajoulePerMole)] + public void ParseUnit(string abbreviation, MolarEnergyUnit expectedUnit) { - try - { - var parsedUnit = MolarEnergy.ParseUnit("J/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarEnergyUnit.JoulePerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarEnergy.ParseUnit("kJ/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarEnergyUnit.KilojoulePerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarEnergy.ParseUnit("MJ/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarEnergyUnit.MegajoulePerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MolarEnergyUnit parsedUnit = MolarEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "J/mol", MolarEnergyUnit.JoulePerMole)] + [InlineData("en-US", "kJ/mol", MolarEnergyUnit.KilojoulePerMole)] + [InlineData("en-US", "MJ/mol", MolarEnergyUnit.MegajoulePerMole)] + public void ParseUnitWithCulture(string culture, string abbreviation, MolarEnergyUnit expectedUnit) { - { - Assert.True(MolarEnergy.TryParseUnit("J/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarEnergyUnit.JoulePerMole, parsedUnit); - } - - { - Assert.True(MolarEnergy.TryParseUnit("kJ/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarEnergyUnit.KilojoulePerMole, parsedUnit); - } + MolarEnergyUnit parsedUnit = MolarEnergy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(MolarEnergy.TryParseUnit("MJ/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarEnergyUnit.MegajoulePerMole, parsedUnit); - } + [Theory] + [InlineData("J/mol", MolarEnergyUnit.JoulePerMole)] + [InlineData("kJ/mol", MolarEnergyUnit.KilojoulePerMole)] + [InlineData("MJ/mol", MolarEnergyUnit.MegajoulePerMole)] + public void TryParseUnit(string abbreviation, MolarEnergyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(MolarEnergy.TryParseUnit(abbreviation, out MolarEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "J/mol", MolarEnergyUnit.JoulePerMole)] + [InlineData("en-US", "kJ/mol", MolarEnergyUnit.KilojoulePerMole)] + [InlineData("en-US", "MJ/mol", MolarEnergyUnit.MegajoulePerMole)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MolarEnergyUnit expectedUnit) + { + Assert.True(MolarEnergy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolarEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs index 0589bb00ea..67149f5dff 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs @@ -246,47 +246,46 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] + [InlineData("kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] + [InlineData("MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] + public void ParseUnit(string abbreviation, MolarEntropyUnit expectedUnit) { - try - { - var parsedUnit = MolarEntropy.ParseUnit("J/(mol*K)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarEntropyUnit.JoulePerMoleKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarEntropy.ParseUnit("kJ/(mol*K)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarEntropyUnit.KilojoulePerMoleKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarEntropy.ParseUnit("MJ/(mol*K)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarEntropyUnit.MegajoulePerMoleKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MolarEntropyUnit parsedUnit = MolarEntropy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] + [InlineData("en-US", "kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] + [InlineData("en-US", "MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] + public void ParseUnitWithCulture(string culture, string abbreviation, MolarEntropyUnit expectedUnit) { - { - Assert.True(MolarEntropy.TryParseUnit("J/(mol*K)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarEntropyUnit.JoulePerMoleKelvin, parsedUnit); - } - - { - Assert.True(MolarEntropy.TryParseUnit("kJ/(mol*K)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarEntropyUnit.KilojoulePerMoleKelvin, parsedUnit); - } + MolarEntropyUnit parsedUnit = MolarEntropy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(MolarEntropy.TryParseUnit("MJ/(mol*K)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarEntropyUnit.MegajoulePerMoleKelvin, parsedUnit); - } + [Theory] + [InlineData("J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] + [InlineData("kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] + [InlineData("MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] + public void TryParseUnit(string abbreviation, MolarEntropyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(MolarEntropy.TryParseUnit(abbreviation, out MolarEntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] + [InlineData("en-US", "kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] + [InlineData("en-US", "MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MolarEntropyUnit expectedUnit) + { + Assert.True(MolarEntropy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolarEntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs index 90c03c7871..500387ddb9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs @@ -384,113 +384,70 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = MolarFlow.ParseUnit("kkmol/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarFlowUnit.KilomolePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarFlow.ParseUnit("kmol/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarFlowUnit.KilomolePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarFlow.ParseUnit("kmol/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarFlowUnit.KilomolePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarFlow.ParseUnit("kmol/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarFlowUnit.MolePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarFlow.ParseUnit("mol/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarFlowUnit.MolePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarFlow.ParseUnit("mol/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarFlowUnit.MolePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarFlow.ParseUnit("lbmol/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarFlowUnit.PoundMolePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarFlow.ParseUnit("lbmol/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarFlowUnit.PoundMolePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarFlow.ParseUnit("lbmol/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarFlowUnit.PoundMolePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("kkmol/h", MolarFlowUnit.KilomolePerHour)] + [InlineData("kmol/min", MolarFlowUnit.KilomolePerMinute)] + [InlineData("kmol/s", MolarFlowUnit.KilomolePerSecond)] + [InlineData("kmol/h", MolarFlowUnit.MolePerHour)] + [InlineData("mol/min", MolarFlowUnit.MolePerMinute)] + [InlineData("mol/s", MolarFlowUnit.MolePerSecond)] + [InlineData("lbmol/h", MolarFlowUnit.PoundMolePerHour)] + [InlineData("lbmol/min", MolarFlowUnit.PoundMolePerMinute)] + [InlineData("lbmol/s", MolarFlowUnit.PoundMolePerSecond)] + public void ParseUnit(string abbreviation, MolarFlowUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MolarFlowUnit parsedUnit = MolarFlow.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "kkmol/h", MolarFlowUnit.KilomolePerHour)] + [InlineData("en-US", "kmol/min", MolarFlowUnit.KilomolePerMinute)] + [InlineData("en-US", "kmol/s", MolarFlowUnit.KilomolePerSecond)] + [InlineData("en-US", "kmol/h", MolarFlowUnit.MolePerHour)] + [InlineData("en-US", "mol/min", MolarFlowUnit.MolePerMinute)] + [InlineData("en-US", "mol/s", MolarFlowUnit.MolePerSecond)] + [InlineData("en-US", "lbmol/h", MolarFlowUnit.PoundMolePerHour)] + [InlineData("en-US", "lbmol/min", MolarFlowUnit.PoundMolePerMinute)] + [InlineData("en-US", "lbmol/s", MolarFlowUnit.PoundMolePerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, MolarFlowUnit expectedUnit) { - { - Assert.True(MolarFlow.TryParseUnit("kkmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarFlowUnit.KilomolePerHour, parsedUnit); - } - - { - Assert.True(MolarFlow.TryParseUnit("kmol/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarFlowUnit.KilomolePerMinute, parsedUnit); - } - - { - Assert.True(MolarFlow.TryParseUnit("kmol/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarFlowUnit.KilomolePerSecond, parsedUnit); - } - - { - Assert.True(MolarFlow.TryParseUnit("kmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarFlowUnit.MolePerHour, parsedUnit); - } - - { - Assert.True(MolarFlow.TryParseUnit("mol/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarFlowUnit.MolePerMinute, parsedUnit); - } - - { - Assert.True(MolarFlow.TryParseUnit("mol/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarFlowUnit.MolePerSecond, parsedUnit); - } - - { - Assert.True(MolarFlow.TryParseUnit("lbmol/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarFlowUnit.PoundMolePerHour, parsedUnit); - } - - { - Assert.True(MolarFlow.TryParseUnit("lbmol/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarFlowUnit.PoundMolePerMinute, parsedUnit); - } + MolarFlowUnit parsedUnit = MolarFlow.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(MolarFlow.TryParseUnit("lbmol/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarFlowUnit.PoundMolePerSecond, parsedUnit); - } + [Theory] + [InlineData("kkmol/h", MolarFlowUnit.KilomolePerHour)] + [InlineData("kmol/min", MolarFlowUnit.KilomolePerMinute)] + [InlineData("kmol/s", MolarFlowUnit.KilomolePerSecond)] + [InlineData("kmol/h", MolarFlowUnit.MolePerHour)] + [InlineData("mol/min", MolarFlowUnit.MolePerMinute)] + [InlineData("mol/s", MolarFlowUnit.MolePerSecond)] + [InlineData("lbmol/h", MolarFlowUnit.PoundMolePerHour)] + [InlineData("lbmol/min", MolarFlowUnit.PoundMolePerMinute)] + [InlineData("lbmol/s", MolarFlowUnit.PoundMolePerSecond)] + public void TryParseUnit(string abbreviation, MolarFlowUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(MolarFlow.TryParseUnit(abbreviation, out MolarFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kkmol/h", MolarFlowUnit.KilomolePerHour)] + [InlineData("en-US", "kmol/min", MolarFlowUnit.KilomolePerMinute)] + [InlineData("en-US", "kmol/s", MolarFlowUnit.KilomolePerSecond)] + [InlineData("en-US", "kmol/h", MolarFlowUnit.MolePerHour)] + [InlineData("en-US", "mol/min", MolarFlowUnit.MolePerMinute)] + [InlineData("en-US", "mol/s", MolarFlowUnit.MolePerSecond)] + [InlineData("en-US", "lbmol/h", MolarFlowUnit.PoundMolePerHour)] + [InlineData("en-US", "lbmol/min", MolarFlowUnit.PoundMolePerMinute)] + [InlineData("en-US", "lbmol/s", MolarFlowUnit.PoundMolePerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MolarFlowUnit expectedUnit) + { + Assert.True(MolarFlow.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolarFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs index 87d64866a8..61cf49b07f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs @@ -632,289 +632,110 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = MolarMass.ParseUnit("cg/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.CentigramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("сг/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.CentigramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("dag/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.DecagramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("даг/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.DecagramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("dg/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.DecigramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("дг/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.DecigramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("g/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.GramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("г/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.GramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("hg/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.HectogramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("гг/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.HectogramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("kg/kmol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.KilogramPerKilomole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("kg/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.KilogramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("кг/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.KilogramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("klb/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.KilopoundPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("кфунт/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.KilopoundPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("Mlb/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.MegapoundPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("Мфунт/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.MegapoundPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("µg/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.MicrogramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("мкг/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.MicrogramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("mg/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.MilligramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("мг/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.MilligramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("ng/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.NanogramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("нг/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.NanogramPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("lb/mol", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarMassUnit.PoundPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = MolarMass.ParseUnit("фунт/моль", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(MolarMassUnit.PoundPerMole, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cg/mol", MolarMassUnit.CentigramPerMole)] + [InlineData("dag/mol", MolarMassUnit.DecagramPerMole)] + [InlineData("dg/mol", MolarMassUnit.DecigramPerMole)] + [InlineData("g/mol", MolarMassUnit.GramPerMole)] + [InlineData("hg/mol", MolarMassUnit.HectogramPerMole)] + [InlineData("kg/kmol", MolarMassUnit.KilogramPerKilomole)] + [InlineData("kg/mol", MolarMassUnit.KilogramPerMole)] + [InlineData("klb/mol", MolarMassUnit.KilopoundPerMole)] + [InlineData("Mlb/mol", MolarMassUnit.MegapoundPerMole)] + [InlineData("µg/mol", MolarMassUnit.MicrogramPerMole)] + [InlineData("mg/mol", MolarMassUnit.MilligramPerMole)] + [InlineData("ng/mol", MolarMassUnit.NanogramPerMole)] + [InlineData("lb/mol", MolarMassUnit.PoundPerMole)] + public void ParseUnit(string abbreviation, MolarMassUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MolarMassUnit parsedUnit = MolarMass.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(MolarMass.TryParseUnit("cg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.CentigramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("сг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.CentigramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("dag/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.DecagramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("даг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.DecagramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("dg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.DecigramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("дг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.DecigramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("g/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.GramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("г/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.GramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("hg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.HectogramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("гг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.HectogramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("kg/kmol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.KilogramPerKilomole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("kg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.KilogramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("кг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.KilogramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("klb/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.KilopoundPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("кфунт/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.KilopoundPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("Mlb/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.MegapoundPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("Мфунт/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.MegapoundPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("µg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.MicrogramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("мкг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.MicrogramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("mg/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.MilligramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("мг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.MilligramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("ng/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.NanogramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("нг/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.NanogramPerMole, parsedUnit); - } - - { - Assert.True(MolarMass.TryParseUnit("lb/mol", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.PoundPerMole, parsedUnit); - } + [Theory] + [InlineData("en-US", "cg/mol", MolarMassUnit.CentigramPerMole)] + [InlineData("en-US", "dag/mol", MolarMassUnit.DecagramPerMole)] + [InlineData("en-US", "dg/mol", MolarMassUnit.DecigramPerMole)] + [InlineData("en-US", "g/mol", MolarMassUnit.GramPerMole)] + [InlineData("en-US", "hg/mol", MolarMassUnit.HectogramPerMole)] + [InlineData("en-US", "kg/kmol", MolarMassUnit.KilogramPerKilomole)] + [InlineData("en-US", "kg/mol", MolarMassUnit.KilogramPerMole)] + [InlineData("en-US", "klb/mol", MolarMassUnit.KilopoundPerMole)] + [InlineData("en-US", "Mlb/mol", MolarMassUnit.MegapoundPerMole)] + [InlineData("en-US", "µg/mol", MolarMassUnit.MicrogramPerMole)] + [InlineData("en-US", "mg/mol", MolarMassUnit.MilligramPerMole)] + [InlineData("en-US", "ng/mol", MolarMassUnit.NanogramPerMole)] + [InlineData("en-US", "lb/mol", MolarMassUnit.PoundPerMole)] + [InlineData("ru-RU", "сг/моль", MolarMassUnit.CentigramPerMole)] + [InlineData("ru-RU", "даг/моль", MolarMassUnit.DecagramPerMole)] + [InlineData("ru-RU", "дг/моль", MolarMassUnit.DecigramPerMole)] + [InlineData("ru-RU", "г/моль", MolarMassUnit.GramPerMole)] + [InlineData("ru-RU", "гг/моль", MolarMassUnit.HectogramPerMole)] + [InlineData("ru-RU", "кг/моль", MolarMassUnit.KilogramPerMole)] + [InlineData("ru-RU", "кфунт/моль", MolarMassUnit.KilopoundPerMole)] + [InlineData("ru-RU", "Мфунт/моль", MolarMassUnit.MegapoundPerMole)] + [InlineData("ru-RU", "мкг/моль", MolarMassUnit.MicrogramPerMole)] + [InlineData("ru-RU", "мг/моль", MolarMassUnit.MilligramPerMole)] + [InlineData("ru-RU", "нг/моль", MolarMassUnit.NanogramPerMole)] + [InlineData("ru-RU", "фунт/моль", MolarMassUnit.PoundPerMole)] + public void ParseUnitWithCulture(string culture, string abbreviation, MolarMassUnit expectedUnit) + { + MolarMassUnit parsedUnit = MolarMass.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(MolarMass.TryParseUnit("фунт/моль", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(MolarMassUnit.PoundPerMole, parsedUnit); - } + [Theory] + [InlineData("cg/mol", MolarMassUnit.CentigramPerMole)] + [InlineData("dag/mol", MolarMassUnit.DecagramPerMole)] + [InlineData("dg/mol", MolarMassUnit.DecigramPerMole)] + [InlineData("g/mol", MolarMassUnit.GramPerMole)] + [InlineData("hg/mol", MolarMassUnit.HectogramPerMole)] + [InlineData("kg/kmol", MolarMassUnit.KilogramPerKilomole)] + [InlineData("kg/mol", MolarMassUnit.KilogramPerMole)] + [InlineData("klb/mol", MolarMassUnit.KilopoundPerMole)] + [InlineData("Mlb/mol", MolarMassUnit.MegapoundPerMole)] + [InlineData("µg/mol", MolarMassUnit.MicrogramPerMole)] + [InlineData("mg/mol", MolarMassUnit.MilligramPerMole)] + [InlineData("ng/mol", MolarMassUnit.NanogramPerMole)] + [InlineData("lb/mol", MolarMassUnit.PoundPerMole)] + public void TryParseUnit(string abbreviation, MolarMassUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(MolarMass.TryParseUnit(abbreviation, out MolarMassUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cg/mol", MolarMassUnit.CentigramPerMole)] + [InlineData("en-US", "dag/mol", MolarMassUnit.DecagramPerMole)] + [InlineData("en-US", "dg/mol", MolarMassUnit.DecigramPerMole)] + [InlineData("en-US", "g/mol", MolarMassUnit.GramPerMole)] + [InlineData("en-US", "hg/mol", MolarMassUnit.HectogramPerMole)] + [InlineData("en-US", "kg/kmol", MolarMassUnit.KilogramPerKilomole)] + [InlineData("en-US", "kg/mol", MolarMassUnit.KilogramPerMole)] + [InlineData("en-US", "klb/mol", MolarMassUnit.KilopoundPerMole)] + [InlineData("en-US", "Mlb/mol", MolarMassUnit.MegapoundPerMole)] + [InlineData("en-US", "µg/mol", MolarMassUnit.MicrogramPerMole)] + [InlineData("en-US", "mg/mol", MolarMassUnit.MilligramPerMole)] + [InlineData("en-US", "ng/mol", MolarMassUnit.NanogramPerMole)] + [InlineData("en-US", "lb/mol", MolarMassUnit.PoundPerMole)] + [InlineData("ru-RU", "сг/моль", MolarMassUnit.CentigramPerMole)] + [InlineData("ru-RU", "даг/моль", MolarMassUnit.DecagramPerMole)] + [InlineData("ru-RU", "дг/моль", MolarMassUnit.DecigramPerMole)] + [InlineData("ru-RU", "г/моль", MolarMassUnit.GramPerMole)] + [InlineData("ru-RU", "гг/моль", MolarMassUnit.HectogramPerMole)] + [InlineData("ru-RU", "кг/моль", MolarMassUnit.KilogramPerMole)] + [InlineData("ru-RU", "кфунт/моль", MolarMassUnit.KilopoundPerMole)] + [InlineData("ru-RU", "Мфунт/моль", MolarMassUnit.MegapoundPerMole)] + [InlineData("ru-RU", "мкг/моль", MolarMassUnit.MicrogramPerMole)] + [InlineData("ru-RU", "мг/моль", MolarMassUnit.MilligramPerMole)] + [InlineData("ru-RU", "нг/моль", MolarMassUnit.NanogramPerMole)] + [InlineData("ru-RU", "фунт/моль", MolarMassUnit.PoundPerMole)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MolarMassUnit expectedUnit) + { + Assert.True(MolarMass.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolarMassUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs index 01b6056687..af17b73475 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs @@ -534,223 +534,110 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Molarity.ParseUnit("cmol/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.CentimolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("cM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.CentimolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("dmol/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.DecimolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("dM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.DecimolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("fmol/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.FemtomolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("fM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.FemtomolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("kmol/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.KilomolePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("µmol/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.MicromolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("µM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.MicromolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("mmol/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.MillimolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("mM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.MillimolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("mol/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.MolePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("mol/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.MolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("M", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.MolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("nmol/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.NanomolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("nM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.NanomolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("pmol/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.PicomolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("pM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.PicomolePerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Molarity.ParseUnit("lbmol/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(MolarityUnit.PoundMolePerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cmol/l", MolarityUnit.CentimolePerLiter)] + [InlineData("cM", MolarityUnit.CentimolePerLiter)] + [InlineData("dmol/l", MolarityUnit.DecimolePerLiter)] + [InlineData("dM", MolarityUnit.DecimolePerLiter)] + [InlineData("fmol/l", MolarityUnit.FemtomolePerLiter)] + [InlineData("fM", MolarityUnit.FemtomolePerLiter)] + [InlineData("kmol/m³", MolarityUnit.KilomolePerCubicMeter)] + [InlineData("µmol/l", MolarityUnit.MicromolePerLiter)] + [InlineData("µM", MolarityUnit.MicromolePerLiter)] + [InlineData("mmol/l", MolarityUnit.MillimolePerLiter)] + [InlineData("mM", MolarityUnit.MillimolePerLiter)] + [InlineData("mol/m³", MolarityUnit.MolePerCubicMeter)] + [InlineData("mol/l", MolarityUnit.MolePerLiter)] + [InlineData("M", MolarityUnit.MolePerLiter)] + [InlineData("nmol/l", MolarityUnit.NanomolePerLiter)] + [InlineData("nM", MolarityUnit.NanomolePerLiter)] + [InlineData("pmol/l", MolarityUnit.PicomolePerLiter)] + [InlineData("pM", MolarityUnit.PicomolePerLiter)] + [InlineData("lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] + public void ParseUnit(string abbreviation, MolarityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + MolarityUnit parsedUnit = Molarity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Molarity.TryParseUnit("cmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.CentimolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("cM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.CentimolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("dmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.DecimolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("dM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.DecimolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("fmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.FemtomolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("fM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.FemtomolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("kmol/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.KilomolePerCubicMeter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("µmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.MicromolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("µM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.MicromolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("mmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.MillimolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("mM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.MillimolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("mol/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.MolePerCubicMeter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("mol/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.MolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("M", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.MolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("nmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.NanomolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("nM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.NanomolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("pmol/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.PicomolePerLiter, parsedUnit); - } - - { - Assert.True(Molarity.TryParseUnit("pM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.PicomolePerLiter, parsedUnit); - } + [Theory] + [InlineData("en-US", "cmol/l", MolarityUnit.CentimolePerLiter)] + [InlineData("en-US", "cM", MolarityUnit.CentimolePerLiter)] + [InlineData("en-US", "dmol/l", MolarityUnit.DecimolePerLiter)] + [InlineData("en-US", "dM", MolarityUnit.DecimolePerLiter)] + [InlineData("en-US", "fmol/l", MolarityUnit.FemtomolePerLiter)] + [InlineData("en-US", "fM", MolarityUnit.FemtomolePerLiter)] + [InlineData("en-US", "kmol/m³", MolarityUnit.KilomolePerCubicMeter)] + [InlineData("en-US", "µmol/l", MolarityUnit.MicromolePerLiter)] + [InlineData("en-US", "µM", MolarityUnit.MicromolePerLiter)] + [InlineData("en-US", "mmol/l", MolarityUnit.MillimolePerLiter)] + [InlineData("en-US", "mM", MolarityUnit.MillimolePerLiter)] + [InlineData("en-US", "mol/m³", MolarityUnit.MolePerCubicMeter)] + [InlineData("en-US", "mol/l", MolarityUnit.MolePerLiter)] + [InlineData("en-US", "M", MolarityUnit.MolePerLiter)] + [InlineData("en-US", "nmol/l", MolarityUnit.NanomolePerLiter)] + [InlineData("en-US", "nM", MolarityUnit.NanomolePerLiter)] + [InlineData("en-US", "pmol/l", MolarityUnit.PicomolePerLiter)] + [InlineData("en-US", "pM", MolarityUnit.PicomolePerLiter)] + [InlineData("en-US", "lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] + public void ParseUnitWithCulture(string culture, string abbreviation, MolarityUnit expectedUnit) + { + MolarityUnit parsedUnit = Molarity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Molarity.TryParseUnit("lbmol/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(MolarityUnit.PoundMolePerCubicFoot, parsedUnit); - } + [Theory] + [InlineData("cmol/l", MolarityUnit.CentimolePerLiter)] + [InlineData("cM", MolarityUnit.CentimolePerLiter)] + [InlineData("dmol/l", MolarityUnit.DecimolePerLiter)] + [InlineData("dM", MolarityUnit.DecimolePerLiter)] + [InlineData("fmol/l", MolarityUnit.FemtomolePerLiter)] + [InlineData("fM", MolarityUnit.FemtomolePerLiter)] + [InlineData("kmol/m³", MolarityUnit.KilomolePerCubicMeter)] + [InlineData("µmol/l", MolarityUnit.MicromolePerLiter)] + [InlineData("µM", MolarityUnit.MicromolePerLiter)] + [InlineData("mmol/l", MolarityUnit.MillimolePerLiter)] + [InlineData("mM", MolarityUnit.MillimolePerLiter)] + [InlineData("mol/m³", MolarityUnit.MolePerCubicMeter)] + [InlineData("mol/l", MolarityUnit.MolePerLiter)] + [InlineData("M", MolarityUnit.MolePerLiter)] + [InlineData("nmol/l", MolarityUnit.NanomolePerLiter)] + [InlineData("nM", MolarityUnit.NanomolePerLiter)] + [InlineData("pmol/l", MolarityUnit.PicomolePerLiter)] + [InlineData("pM", MolarityUnit.PicomolePerLiter)] + [InlineData("lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] + public void TryParseUnit(string abbreviation, MolarityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Molarity.TryParseUnit(abbreviation, out MolarityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cmol/l", MolarityUnit.CentimolePerLiter)] + [InlineData("en-US", "cM", MolarityUnit.CentimolePerLiter)] + [InlineData("en-US", "dmol/l", MolarityUnit.DecimolePerLiter)] + [InlineData("en-US", "dM", MolarityUnit.DecimolePerLiter)] + [InlineData("en-US", "fmol/l", MolarityUnit.FemtomolePerLiter)] + [InlineData("en-US", "fM", MolarityUnit.FemtomolePerLiter)] + [InlineData("en-US", "kmol/m³", MolarityUnit.KilomolePerCubicMeter)] + [InlineData("en-US", "µmol/l", MolarityUnit.MicromolePerLiter)] + [InlineData("en-US", "µM", MolarityUnit.MicromolePerLiter)] + [InlineData("en-US", "mmol/l", MolarityUnit.MillimolePerLiter)] + [InlineData("en-US", "mM", MolarityUnit.MillimolePerLiter)] + [InlineData("en-US", "mol/m³", MolarityUnit.MolePerCubicMeter)] + [InlineData("en-US", "mol/l", MolarityUnit.MolePerLiter)] + [InlineData("en-US", "M", MolarityUnit.MolePerLiter)] + [InlineData("en-US", "nmol/l", MolarityUnit.NanomolePerLiter)] + [InlineData("en-US", "nM", MolarityUnit.NanomolePerLiter)] + [InlineData("en-US", "pmol/l", MolarityUnit.PicomolePerLiter)] + [InlineData("en-US", "pM", MolarityUnit.PicomolePerLiter)] + [InlineData("en-US", "lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] + public void TryParseUnitWithCulture(string culture, string abbreviation, MolarityUnit expectedUnit) + { + Assert.True(Molarity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolarityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs index 03a1cc9a42..430c05d0d7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("H/m", PermeabilityUnit.HenryPerMeter)] + public void ParseUnit(string abbreviation, PermeabilityUnit expectedUnit) { - try - { - var parsedUnit = Permeability.ParseUnit("H/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PermeabilityUnit.HenryPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + PermeabilityUnit parsedUnit = Permeability.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "H/m", PermeabilityUnit.HenryPerMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, PermeabilityUnit expectedUnit) + { + PermeabilityUnit parsedUnit = Permeability.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("H/m", PermeabilityUnit.HenryPerMeter)] + public void TryParseUnit(string abbreviation, PermeabilityUnit expectedUnit) { - { - Assert.True(Permeability.TryParseUnit("H/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PermeabilityUnit.HenryPerMeter, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Permeability.TryParseUnit(abbreviation, out PermeabilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "H/m", PermeabilityUnit.HenryPerMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, PermeabilityUnit expectedUnit) + { + Assert.True(Permeability.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PermeabilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs index c40bf7b596..23bb2df94f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("F/m", PermittivityUnit.FaradPerMeter)] + public void ParseUnit(string abbreviation, PermittivityUnit expectedUnit) { - try - { - var parsedUnit = Permittivity.ParseUnit("F/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PermittivityUnit.FaradPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + PermittivityUnit parsedUnit = Permittivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "F/m", PermittivityUnit.FaradPerMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, PermittivityUnit expectedUnit) + { + PermittivityUnit parsedUnit = Permittivity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("F/m", PermittivityUnit.FaradPerMeter)] + public void TryParseUnit(string abbreviation, PermittivityUnit expectedUnit) { - { - Assert.True(Permittivity.TryParseUnit("F/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PermittivityUnit.FaradPerMeter, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Permittivity.TryParseUnit(abbreviation, out PermittivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "F/m", PermittivityUnit.FaradPerMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, PermittivityUnit expectedUnit) + { + Assert.True(Permittivity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PermittivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs index d2772599a3..46fddd08b0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs @@ -292,69 +292,54 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("D", PorousMediumPermeabilityUnit.Darcy)] + [InlineData("µD", PorousMediumPermeabilityUnit.Microdarcy)] + [InlineData("mD", PorousMediumPermeabilityUnit.Millidarcy)] + [InlineData("cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] + [InlineData("m²", PorousMediumPermeabilityUnit.SquareMeter)] + public void ParseUnit(string abbreviation, PorousMediumPermeabilityUnit expectedUnit) { - try - { - var parsedUnit = PorousMediumPermeability.ParseUnit("D", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PorousMediumPermeabilityUnit.Darcy, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PorousMediumPermeability.ParseUnit("µD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PorousMediumPermeabilityUnit.Microdarcy, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PorousMediumPermeability.ParseUnit("mD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PorousMediumPermeabilityUnit.Millidarcy, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PorousMediumPermeability.ParseUnit("cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PorousMediumPermeabilityUnit.SquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PorousMediumPermeability.ParseUnit("m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PorousMediumPermeabilityUnit.SquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + PorousMediumPermeabilityUnit parsedUnit = PorousMediumPermeability.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "D", PorousMediumPermeabilityUnit.Darcy)] + [InlineData("en-US", "µD", PorousMediumPermeabilityUnit.Microdarcy)] + [InlineData("en-US", "mD", PorousMediumPermeabilityUnit.Millidarcy)] + [InlineData("en-US", "cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] + [InlineData("en-US", "m²", PorousMediumPermeabilityUnit.SquareMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, PorousMediumPermeabilityUnit expectedUnit) { - { - Assert.True(PorousMediumPermeability.TryParseUnit("D", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PorousMediumPermeabilityUnit.Darcy, parsedUnit); - } - - { - Assert.True(PorousMediumPermeability.TryParseUnit("µD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PorousMediumPermeabilityUnit.Microdarcy, parsedUnit); - } - - { - Assert.True(PorousMediumPermeability.TryParseUnit("mD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PorousMediumPermeabilityUnit.Millidarcy, parsedUnit); - } - - { - Assert.True(PorousMediumPermeability.TryParseUnit("cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PorousMediumPermeabilityUnit.SquareCentimeter, parsedUnit); - } + PorousMediumPermeabilityUnit parsedUnit = PorousMediumPermeability.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(PorousMediumPermeability.TryParseUnit("m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PorousMediumPermeabilityUnit.SquareMeter, parsedUnit); - } + [Theory] + [InlineData("D", PorousMediumPermeabilityUnit.Darcy)] + [InlineData("µD", PorousMediumPermeabilityUnit.Microdarcy)] + [InlineData("mD", PorousMediumPermeabilityUnit.Millidarcy)] + [InlineData("cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] + [InlineData("m²", PorousMediumPermeabilityUnit.SquareMeter)] + public void TryParseUnit(string abbreviation, PorousMediumPermeabilityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(PorousMediumPermeability.TryParseUnit(abbreviation, out PorousMediumPermeabilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "D", PorousMediumPermeabilityUnit.Darcy)] + [InlineData("en-US", "µD", PorousMediumPermeabilityUnit.Microdarcy)] + [InlineData("en-US", "mD", PorousMediumPermeabilityUnit.Millidarcy)] + [InlineData("en-US", "cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] + [InlineData("en-US", "m²", PorousMediumPermeabilityUnit.SquareMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, PorousMediumPermeabilityUnit expectedUnit) + { + Assert.True(PorousMediumPermeability.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PorousMediumPermeabilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs index 243ddf0124..bf4c539243 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs @@ -1141,458 +1141,210 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = PowerDensity.ParseUnit("daW/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.DecawattPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("daW/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.DecawattPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("daW/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.DecawattPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("daW/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.DecawattPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("dW/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("dW/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("dW/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("dW/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.DeciwattPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("GW/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.GigawattPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("GW/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.GigawattPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("GW/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.GigawattPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("GW/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.GigawattPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("kW/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.KilowattPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("kW/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.KilowattPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("kW/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.KilowattPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("kW/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.KilowattPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("MW/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MegawattPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("MW/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MegawattPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("MW/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MegawattPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("MW/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MegawattPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("µW/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("µW/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("µW/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("µW/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MicrowattPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("mW/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MilliwattPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("mW/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MilliwattPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("mW/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MilliwattPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("mW/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.MilliwattPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("nW/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.NanowattPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("nW/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.NanowattPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("nW/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.NanowattPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("nW/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.NanowattPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("pW/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.PicowattPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("pW/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.PicowattPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("pW/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.PicowattPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("pW/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.PicowattPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("TW/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.TerawattPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("TW/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.TerawattPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("TW/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.TerawattPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("TW/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.TerawattPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("W/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.WattPerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("W/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.WattPerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("W/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.WattPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerDensity.ParseUnit("W/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerDensityUnit.WattPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("daW/ft³", PowerDensityUnit.DecawattPerCubicFoot)] + [InlineData("daW/in³", PowerDensityUnit.DecawattPerCubicInch)] + [InlineData("daW/m³", PowerDensityUnit.DecawattPerCubicMeter)] + [InlineData("daW/l", PowerDensityUnit.DecawattPerLiter)] + [InlineData("dW/ft³", PowerDensityUnit.DeciwattPerCubicFoot)] + [InlineData("dW/in³", PowerDensityUnit.DeciwattPerCubicInch)] + [InlineData("dW/m³", PowerDensityUnit.DeciwattPerCubicMeter)] + [InlineData("dW/l", PowerDensityUnit.DeciwattPerLiter)] + [InlineData("GW/ft³", PowerDensityUnit.GigawattPerCubicFoot)] + [InlineData("GW/in³", PowerDensityUnit.GigawattPerCubicInch)] + [InlineData("GW/m³", PowerDensityUnit.GigawattPerCubicMeter)] + [InlineData("GW/l", PowerDensityUnit.GigawattPerLiter)] + [InlineData("kW/ft³", PowerDensityUnit.KilowattPerCubicFoot)] + [InlineData("kW/in³", PowerDensityUnit.KilowattPerCubicInch)] + [InlineData("kW/m³", PowerDensityUnit.KilowattPerCubicMeter)] + [InlineData("kW/l", PowerDensityUnit.KilowattPerLiter)] + [InlineData("MW/ft³", PowerDensityUnit.MegawattPerCubicFoot)] + [InlineData("MW/in³", PowerDensityUnit.MegawattPerCubicInch)] + [InlineData("MW/m³", PowerDensityUnit.MegawattPerCubicMeter)] + [InlineData("MW/l", PowerDensityUnit.MegawattPerLiter)] + [InlineData("µW/ft³", PowerDensityUnit.MicrowattPerCubicFoot)] + [InlineData("µW/in³", PowerDensityUnit.MicrowattPerCubicInch)] + [InlineData("µW/m³", PowerDensityUnit.MicrowattPerCubicMeter)] + [InlineData("µW/l", PowerDensityUnit.MicrowattPerLiter)] + [InlineData("mW/ft³", PowerDensityUnit.MilliwattPerCubicFoot)] + [InlineData("mW/in³", PowerDensityUnit.MilliwattPerCubicInch)] + [InlineData("mW/m³", PowerDensityUnit.MilliwattPerCubicMeter)] + [InlineData("mW/l", PowerDensityUnit.MilliwattPerLiter)] + [InlineData("nW/ft³", PowerDensityUnit.NanowattPerCubicFoot)] + [InlineData("nW/in³", PowerDensityUnit.NanowattPerCubicInch)] + [InlineData("nW/m³", PowerDensityUnit.NanowattPerCubicMeter)] + [InlineData("nW/l", PowerDensityUnit.NanowattPerLiter)] + [InlineData("pW/ft³", PowerDensityUnit.PicowattPerCubicFoot)] + [InlineData("pW/in³", PowerDensityUnit.PicowattPerCubicInch)] + [InlineData("pW/m³", PowerDensityUnit.PicowattPerCubicMeter)] + [InlineData("pW/l", PowerDensityUnit.PicowattPerLiter)] + [InlineData("TW/ft³", PowerDensityUnit.TerawattPerCubicFoot)] + [InlineData("TW/in³", PowerDensityUnit.TerawattPerCubicInch)] + [InlineData("TW/m³", PowerDensityUnit.TerawattPerCubicMeter)] + [InlineData("TW/l", PowerDensityUnit.TerawattPerLiter)] + [InlineData("W/ft³", PowerDensityUnit.WattPerCubicFoot)] + [InlineData("W/in³", PowerDensityUnit.WattPerCubicInch)] + [InlineData("W/m³", PowerDensityUnit.WattPerCubicMeter)] + [InlineData("W/l", PowerDensityUnit.WattPerLiter)] + public void ParseUnit(string abbreviation, PowerDensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + PowerDensityUnit parsedUnit = PowerDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(PowerDensity.TryParseUnit("daW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.DecawattPerCubicFoot, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("daW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.DecawattPerCubicInch, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("daW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.DecawattPerCubicMeter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("daW/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.DecawattPerLiter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("dW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicFoot, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("dW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicInch, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("dW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.DeciwattPerCubicMeter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("dW/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.DeciwattPerLiter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("GW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.GigawattPerCubicFoot, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("GW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.GigawattPerCubicInch, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("GW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.GigawattPerCubicMeter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("GW/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.GigawattPerLiter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("kW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.KilowattPerCubicFoot, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("kW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.KilowattPerCubicInch, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("kW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.KilowattPerCubicMeter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("kW/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.KilowattPerLiter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("µW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicFoot, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("µW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicInch, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("µW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.MicrowattPerCubicMeter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("µW/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.MicrowattPerLiter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("nW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.NanowattPerCubicFoot, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("nW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.NanowattPerCubicInch, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("nW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.NanowattPerCubicMeter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("nW/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.NanowattPerLiter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("pW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.PicowattPerCubicFoot, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("pW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.PicowattPerCubicInch, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("pW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.PicowattPerCubicMeter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("pW/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.PicowattPerLiter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("TW/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.TerawattPerCubicFoot, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("TW/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.TerawattPerCubicInch, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("TW/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.TerawattPerCubicMeter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("TW/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.TerawattPerLiter, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("W/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.WattPerCubicFoot, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("W/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.WattPerCubicInch, parsedUnit); - } - - { - Assert.True(PowerDensity.TryParseUnit("W/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.WattPerCubicMeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "daW/ft³", PowerDensityUnit.DecawattPerCubicFoot)] + [InlineData("en-US", "daW/in³", PowerDensityUnit.DecawattPerCubicInch)] + [InlineData("en-US", "daW/m³", PowerDensityUnit.DecawattPerCubicMeter)] + [InlineData("en-US", "daW/l", PowerDensityUnit.DecawattPerLiter)] + [InlineData("en-US", "dW/ft³", PowerDensityUnit.DeciwattPerCubicFoot)] + [InlineData("en-US", "dW/in³", PowerDensityUnit.DeciwattPerCubicInch)] + [InlineData("en-US", "dW/m³", PowerDensityUnit.DeciwattPerCubicMeter)] + [InlineData("en-US", "dW/l", PowerDensityUnit.DeciwattPerLiter)] + [InlineData("en-US", "GW/ft³", PowerDensityUnit.GigawattPerCubicFoot)] + [InlineData("en-US", "GW/in³", PowerDensityUnit.GigawattPerCubicInch)] + [InlineData("en-US", "GW/m³", PowerDensityUnit.GigawattPerCubicMeter)] + [InlineData("en-US", "GW/l", PowerDensityUnit.GigawattPerLiter)] + [InlineData("en-US", "kW/ft³", PowerDensityUnit.KilowattPerCubicFoot)] + [InlineData("en-US", "kW/in³", PowerDensityUnit.KilowattPerCubicInch)] + [InlineData("en-US", "kW/m³", PowerDensityUnit.KilowattPerCubicMeter)] + [InlineData("en-US", "kW/l", PowerDensityUnit.KilowattPerLiter)] + [InlineData("en-US", "MW/ft³", PowerDensityUnit.MegawattPerCubicFoot)] + [InlineData("en-US", "MW/in³", PowerDensityUnit.MegawattPerCubicInch)] + [InlineData("en-US", "MW/m³", PowerDensityUnit.MegawattPerCubicMeter)] + [InlineData("en-US", "MW/l", PowerDensityUnit.MegawattPerLiter)] + [InlineData("en-US", "µW/ft³", PowerDensityUnit.MicrowattPerCubicFoot)] + [InlineData("en-US", "µW/in³", PowerDensityUnit.MicrowattPerCubicInch)] + [InlineData("en-US", "µW/m³", PowerDensityUnit.MicrowattPerCubicMeter)] + [InlineData("en-US", "µW/l", PowerDensityUnit.MicrowattPerLiter)] + [InlineData("en-US", "mW/ft³", PowerDensityUnit.MilliwattPerCubicFoot)] + [InlineData("en-US", "mW/in³", PowerDensityUnit.MilliwattPerCubicInch)] + [InlineData("en-US", "mW/m³", PowerDensityUnit.MilliwattPerCubicMeter)] + [InlineData("en-US", "mW/l", PowerDensityUnit.MilliwattPerLiter)] + [InlineData("en-US", "nW/ft³", PowerDensityUnit.NanowattPerCubicFoot)] + [InlineData("en-US", "nW/in³", PowerDensityUnit.NanowattPerCubicInch)] + [InlineData("en-US", "nW/m³", PowerDensityUnit.NanowattPerCubicMeter)] + [InlineData("en-US", "nW/l", PowerDensityUnit.NanowattPerLiter)] + [InlineData("en-US", "pW/ft³", PowerDensityUnit.PicowattPerCubicFoot)] + [InlineData("en-US", "pW/in³", PowerDensityUnit.PicowattPerCubicInch)] + [InlineData("en-US", "pW/m³", PowerDensityUnit.PicowattPerCubicMeter)] + [InlineData("en-US", "pW/l", PowerDensityUnit.PicowattPerLiter)] + [InlineData("en-US", "TW/ft³", PowerDensityUnit.TerawattPerCubicFoot)] + [InlineData("en-US", "TW/in³", PowerDensityUnit.TerawattPerCubicInch)] + [InlineData("en-US", "TW/m³", PowerDensityUnit.TerawattPerCubicMeter)] + [InlineData("en-US", "TW/l", PowerDensityUnit.TerawattPerLiter)] + [InlineData("en-US", "W/ft³", PowerDensityUnit.WattPerCubicFoot)] + [InlineData("en-US", "W/in³", PowerDensityUnit.WattPerCubicInch)] + [InlineData("en-US", "W/m³", PowerDensityUnit.WattPerCubicMeter)] + [InlineData("en-US", "W/l", PowerDensityUnit.WattPerLiter)] + public void ParseUnitWithCulture(string culture, string abbreviation, PowerDensityUnit expectedUnit) + { + PowerDensityUnit parsedUnit = PowerDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(PowerDensity.TryParseUnit("W/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerDensityUnit.WattPerLiter, parsedUnit); - } + [Theory] + [InlineData("daW/ft³", PowerDensityUnit.DecawattPerCubicFoot)] + [InlineData("daW/in³", PowerDensityUnit.DecawattPerCubicInch)] + [InlineData("daW/m³", PowerDensityUnit.DecawattPerCubicMeter)] + [InlineData("daW/l", PowerDensityUnit.DecawattPerLiter)] + [InlineData("dW/ft³", PowerDensityUnit.DeciwattPerCubicFoot)] + [InlineData("dW/in³", PowerDensityUnit.DeciwattPerCubicInch)] + [InlineData("dW/m³", PowerDensityUnit.DeciwattPerCubicMeter)] + [InlineData("dW/l", PowerDensityUnit.DeciwattPerLiter)] + [InlineData("GW/ft³", PowerDensityUnit.GigawattPerCubicFoot)] + [InlineData("GW/in³", PowerDensityUnit.GigawattPerCubicInch)] + [InlineData("GW/m³", PowerDensityUnit.GigawattPerCubicMeter)] + [InlineData("GW/l", PowerDensityUnit.GigawattPerLiter)] + [InlineData("kW/ft³", PowerDensityUnit.KilowattPerCubicFoot)] + [InlineData("kW/in³", PowerDensityUnit.KilowattPerCubicInch)] + [InlineData("kW/m³", PowerDensityUnit.KilowattPerCubicMeter)] + [InlineData("kW/l", PowerDensityUnit.KilowattPerLiter)] + [InlineData("MW/ft³", PowerDensityUnit.MegawattPerCubicFoot)] + [InlineData("MW/in³", PowerDensityUnit.MegawattPerCubicInch)] + [InlineData("MW/m³", PowerDensityUnit.MegawattPerCubicMeter)] + [InlineData("MW/l", PowerDensityUnit.MegawattPerLiter)] + [InlineData("µW/ft³", PowerDensityUnit.MicrowattPerCubicFoot)] + [InlineData("µW/in³", PowerDensityUnit.MicrowattPerCubicInch)] + [InlineData("µW/m³", PowerDensityUnit.MicrowattPerCubicMeter)] + [InlineData("µW/l", PowerDensityUnit.MicrowattPerLiter)] + [InlineData("mW/ft³", PowerDensityUnit.MilliwattPerCubicFoot)] + [InlineData("mW/in³", PowerDensityUnit.MilliwattPerCubicInch)] + [InlineData("mW/m³", PowerDensityUnit.MilliwattPerCubicMeter)] + [InlineData("mW/l", PowerDensityUnit.MilliwattPerLiter)] + [InlineData("nW/ft³", PowerDensityUnit.NanowattPerCubicFoot)] + [InlineData("nW/in³", PowerDensityUnit.NanowattPerCubicInch)] + [InlineData("nW/m³", PowerDensityUnit.NanowattPerCubicMeter)] + [InlineData("nW/l", PowerDensityUnit.NanowattPerLiter)] + [InlineData("pW/ft³", PowerDensityUnit.PicowattPerCubicFoot)] + [InlineData("pW/in³", PowerDensityUnit.PicowattPerCubicInch)] + [InlineData("pW/m³", PowerDensityUnit.PicowattPerCubicMeter)] + [InlineData("pW/l", PowerDensityUnit.PicowattPerLiter)] + [InlineData("TW/ft³", PowerDensityUnit.TerawattPerCubicFoot)] + [InlineData("TW/in³", PowerDensityUnit.TerawattPerCubicInch)] + [InlineData("TW/m³", PowerDensityUnit.TerawattPerCubicMeter)] + [InlineData("TW/l", PowerDensityUnit.TerawattPerLiter)] + [InlineData("W/ft³", PowerDensityUnit.WattPerCubicFoot)] + [InlineData("W/in³", PowerDensityUnit.WattPerCubicInch)] + [InlineData("W/m³", PowerDensityUnit.WattPerCubicMeter)] + [InlineData("W/l", PowerDensityUnit.WattPerLiter)] + public void TryParseUnit(string abbreviation, PowerDensityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(PowerDensity.TryParseUnit(abbreviation, out PowerDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "daW/ft³", PowerDensityUnit.DecawattPerCubicFoot)] + [InlineData("en-US", "daW/in³", PowerDensityUnit.DecawattPerCubicInch)] + [InlineData("en-US", "daW/m³", PowerDensityUnit.DecawattPerCubicMeter)] + [InlineData("en-US", "daW/l", PowerDensityUnit.DecawattPerLiter)] + [InlineData("en-US", "dW/ft³", PowerDensityUnit.DeciwattPerCubicFoot)] + [InlineData("en-US", "dW/in³", PowerDensityUnit.DeciwattPerCubicInch)] + [InlineData("en-US", "dW/m³", PowerDensityUnit.DeciwattPerCubicMeter)] + [InlineData("en-US", "dW/l", PowerDensityUnit.DeciwattPerLiter)] + [InlineData("en-US", "GW/ft³", PowerDensityUnit.GigawattPerCubicFoot)] + [InlineData("en-US", "GW/in³", PowerDensityUnit.GigawattPerCubicInch)] + [InlineData("en-US", "GW/m³", PowerDensityUnit.GigawattPerCubicMeter)] + [InlineData("en-US", "GW/l", PowerDensityUnit.GigawattPerLiter)] + [InlineData("en-US", "kW/ft³", PowerDensityUnit.KilowattPerCubicFoot)] + [InlineData("en-US", "kW/in³", PowerDensityUnit.KilowattPerCubicInch)] + [InlineData("en-US", "kW/m³", PowerDensityUnit.KilowattPerCubicMeter)] + [InlineData("en-US", "kW/l", PowerDensityUnit.KilowattPerLiter)] + [InlineData("en-US", "MW/ft³", PowerDensityUnit.MegawattPerCubicFoot)] + [InlineData("en-US", "MW/in³", PowerDensityUnit.MegawattPerCubicInch)] + [InlineData("en-US", "MW/m³", PowerDensityUnit.MegawattPerCubicMeter)] + [InlineData("en-US", "MW/l", PowerDensityUnit.MegawattPerLiter)] + [InlineData("en-US", "µW/ft³", PowerDensityUnit.MicrowattPerCubicFoot)] + [InlineData("en-US", "µW/in³", PowerDensityUnit.MicrowattPerCubicInch)] + [InlineData("en-US", "µW/m³", PowerDensityUnit.MicrowattPerCubicMeter)] + [InlineData("en-US", "µW/l", PowerDensityUnit.MicrowattPerLiter)] + [InlineData("en-US", "mW/ft³", PowerDensityUnit.MilliwattPerCubicFoot)] + [InlineData("en-US", "mW/in³", PowerDensityUnit.MilliwattPerCubicInch)] + [InlineData("en-US", "mW/m³", PowerDensityUnit.MilliwattPerCubicMeter)] + [InlineData("en-US", "mW/l", PowerDensityUnit.MilliwattPerLiter)] + [InlineData("en-US", "nW/ft³", PowerDensityUnit.NanowattPerCubicFoot)] + [InlineData("en-US", "nW/in³", PowerDensityUnit.NanowattPerCubicInch)] + [InlineData("en-US", "nW/m³", PowerDensityUnit.NanowattPerCubicMeter)] + [InlineData("en-US", "nW/l", PowerDensityUnit.NanowattPerLiter)] + [InlineData("en-US", "pW/ft³", PowerDensityUnit.PicowattPerCubicFoot)] + [InlineData("en-US", "pW/in³", PowerDensityUnit.PicowattPerCubicInch)] + [InlineData("en-US", "pW/m³", PowerDensityUnit.PicowattPerCubicMeter)] + [InlineData("en-US", "pW/l", PowerDensityUnit.PicowattPerLiter)] + [InlineData("en-US", "TW/ft³", PowerDensityUnit.TerawattPerCubicFoot)] + [InlineData("en-US", "TW/in³", PowerDensityUnit.TerawattPerCubicInch)] + [InlineData("en-US", "TW/m³", PowerDensityUnit.TerawattPerCubicMeter)] + [InlineData("en-US", "TW/l", PowerDensityUnit.TerawattPerLiter)] + [InlineData("en-US", "W/ft³", PowerDensityUnit.WattPerCubicFoot)] + [InlineData("en-US", "W/in³", PowerDensityUnit.WattPerCubicInch)] + [InlineData("en-US", "W/m³", PowerDensityUnit.WattPerCubicMeter)] + [InlineData("en-US", "W/l", PowerDensityUnit.WattPerLiter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, PowerDensityUnit expectedUnit) + { + Assert.True(PowerDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PowerDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs index 487cef81b9..2006e16671 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs @@ -236,47 +236,46 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("dBmW", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("dBm", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("dBW", PowerRatioUnit.DecibelWatt)] + public void ParseUnit(string abbreviation, PowerRatioUnit expectedUnit) { - try - { - var parsedUnit = PowerRatio.ParseUnit("dBmW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerRatioUnit.DecibelMilliwatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerRatio.ParseUnit("dBm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerRatioUnit.DecibelMilliwatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PowerRatio.ParseUnit("dBW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerRatioUnit.DecibelWatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + PowerRatioUnit parsedUnit = PowerRatio.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "dBmW", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("en-US", "dBm", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("en-US", "dBW", PowerRatioUnit.DecibelWatt)] + public void ParseUnitWithCulture(string culture, string abbreviation, PowerRatioUnit expectedUnit) { - { - Assert.True(PowerRatio.TryParseUnit("dBmW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerRatioUnit.DecibelMilliwatt, parsedUnit); - } - - { - Assert.True(PowerRatio.TryParseUnit("dBm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerRatioUnit.DecibelMilliwatt, parsedUnit); - } + PowerRatioUnit parsedUnit = PowerRatio.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(PowerRatio.TryParseUnit("dBW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerRatioUnit.DecibelWatt, parsedUnit); - } + [Theory] + [InlineData("dBmW", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("dBm", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("dBW", PowerRatioUnit.DecibelWatt)] + public void TryParseUnit(string abbreviation, PowerRatioUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(PowerRatio.TryParseUnit(abbreviation, out PowerRatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "dBmW", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("en-US", "dBm", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("en-US", "dBW", PowerRatioUnit.DecibelWatt)] + public void TryParseUnitWithCulture(string culture, string abbreviation, PowerRatioUnit expectedUnit) + { + Assert.True(PowerRatio.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PowerRatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs index 067dbaa694..dec2afc552 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs @@ -801,314 +801,154 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Power.ParseUnit("hp(S)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.BoilerHorsepower, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("Btu/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.BritishThermalUnitPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("Btu/hr", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.BritishThermalUnitPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("daW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Decawatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("dW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Deciwatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("hp(E)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.ElectricalHorsepower, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("fW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Femtowatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("GJ/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.GigajoulePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("GW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Gigawatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("hp(H)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.HydraulicHorsepower, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("J/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.JoulePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("kBtu/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.KilobritishThermalUnitPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("kBtu/hr", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.KilobritishThermalUnitPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("kJ/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.KilojoulePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("kW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Kilowatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("hp(I)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.MechanicalHorsepower, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("MBtu/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.MegabritishThermalUnitPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("MBtu/hr", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.MegabritishThermalUnitPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("MJ/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.MegajoulePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("MW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Megawatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("hp(M)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.MetricHorsepower, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("µW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Microwatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("mJ/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.MillijoulePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("mW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Milliwatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("nW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Nanowatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("PW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Petawatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("pW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Picowatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("TW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Terawatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("TR", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.TonOfRefrigeration, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Power.ParseUnit("W", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PowerUnit.Watt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("hp(S)", PowerUnit.BoilerHorsepower)] + [InlineData("Btu/h", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("Btu/hr", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("daW", PowerUnit.Decawatt)] + [InlineData("dW", PowerUnit.Deciwatt)] + [InlineData("hp(E)", PowerUnit.ElectricalHorsepower)] + [InlineData("fW", PowerUnit.Femtowatt)] + [InlineData("GJ/h", PowerUnit.GigajoulePerHour)] + [InlineData("GW", PowerUnit.Gigawatt)] + [InlineData("hp(H)", PowerUnit.HydraulicHorsepower)] + [InlineData("J/h", PowerUnit.JoulePerHour)] + [InlineData("kBtu/h", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("kBtu/hr", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("kJ/h", PowerUnit.KilojoulePerHour)] + [InlineData("kW", PowerUnit.Kilowatt)] + [InlineData("hp(I)", PowerUnit.MechanicalHorsepower)] + [InlineData("MBtu/h", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("MBtu/hr", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("MJ/h", PowerUnit.MegajoulePerHour)] + [InlineData("MW", PowerUnit.Megawatt)] + [InlineData("hp(M)", PowerUnit.MetricHorsepower)] + [InlineData("µW", PowerUnit.Microwatt)] + [InlineData("mJ/h", PowerUnit.MillijoulePerHour)] + [InlineData("mW", PowerUnit.Milliwatt)] + [InlineData("nW", PowerUnit.Nanowatt)] + [InlineData("PW", PowerUnit.Petawatt)] + [InlineData("pW", PowerUnit.Picowatt)] + [InlineData("TW", PowerUnit.Terawatt)] + [InlineData("TR", PowerUnit.TonOfRefrigeration)] + [InlineData("W", PowerUnit.Watt)] + public void ParseUnit(string abbreviation, PowerUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + PowerUnit parsedUnit = Power.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Power.TryParseUnit("hp(S)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.BoilerHorsepower, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("Btu/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.BritishThermalUnitPerHour, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("Btu/hr", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.BritishThermalUnitPerHour, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("daW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.Decawatt, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("dW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.Deciwatt, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("hp(E)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.ElectricalHorsepower, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("fW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.Femtowatt, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("GJ/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.GigajoulePerHour, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("GW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.Gigawatt, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("hp(H)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.HydraulicHorsepower, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("J/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.JoulePerHour, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("kBtu/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.KilobritishThermalUnitPerHour, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("kBtu/hr", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.KilobritishThermalUnitPerHour, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("kJ/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.KilojoulePerHour, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("kW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.Kilowatt, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("hp(I)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.MechanicalHorsepower, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("MBtu/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.MegabritishThermalUnitPerHour, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("MBtu/hr", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.MegabritishThermalUnitPerHour, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("hp(M)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.MetricHorsepower, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("µW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.Microwatt, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("nW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.Nanowatt, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("TW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.Terawatt, parsedUnit); - } - - { - Assert.True(Power.TryParseUnit("TR", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.TonOfRefrigeration, parsedUnit); - } + [Theory] + [InlineData("en-US", "hp(S)", PowerUnit.BoilerHorsepower)] + [InlineData("en-US", "Btu/h", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("en-US", "Btu/hr", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("en-US", "daW", PowerUnit.Decawatt)] + [InlineData("en-US", "dW", PowerUnit.Deciwatt)] + [InlineData("en-US", "hp(E)", PowerUnit.ElectricalHorsepower)] + [InlineData("en-US", "fW", PowerUnit.Femtowatt)] + [InlineData("en-US", "GJ/h", PowerUnit.GigajoulePerHour)] + [InlineData("en-US", "GW", PowerUnit.Gigawatt)] + [InlineData("en-US", "hp(H)", PowerUnit.HydraulicHorsepower)] + [InlineData("en-US", "J/h", PowerUnit.JoulePerHour)] + [InlineData("en-US", "kBtu/h", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("en-US", "kBtu/hr", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("en-US", "kJ/h", PowerUnit.KilojoulePerHour)] + [InlineData("en-US", "kW", PowerUnit.Kilowatt)] + [InlineData("en-US", "hp(I)", PowerUnit.MechanicalHorsepower)] + [InlineData("en-US", "MBtu/h", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("en-US", "MBtu/hr", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("en-US", "MJ/h", PowerUnit.MegajoulePerHour)] + [InlineData("en-US", "MW", PowerUnit.Megawatt)] + [InlineData("en-US", "hp(M)", PowerUnit.MetricHorsepower)] + [InlineData("en-US", "µW", PowerUnit.Microwatt)] + [InlineData("en-US", "mJ/h", PowerUnit.MillijoulePerHour)] + [InlineData("en-US", "mW", PowerUnit.Milliwatt)] + [InlineData("en-US", "nW", PowerUnit.Nanowatt)] + [InlineData("en-US", "PW", PowerUnit.Petawatt)] + [InlineData("en-US", "pW", PowerUnit.Picowatt)] + [InlineData("en-US", "TW", PowerUnit.Terawatt)] + [InlineData("en-US", "TR", PowerUnit.TonOfRefrigeration)] + [InlineData("en-US", "W", PowerUnit.Watt)] + public void ParseUnitWithCulture(string culture, string abbreviation, PowerUnit expectedUnit) + { + PowerUnit parsedUnit = Power.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Power.TryParseUnit("W", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PowerUnit.Watt, parsedUnit); - } + [Theory] + [InlineData("hp(S)", PowerUnit.BoilerHorsepower)] + [InlineData("Btu/h", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("Btu/hr", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("daW", PowerUnit.Decawatt)] + [InlineData("dW", PowerUnit.Deciwatt)] + [InlineData("hp(E)", PowerUnit.ElectricalHorsepower)] + [InlineData("fW", PowerUnit.Femtowatt)] + [InlineData("GJ/h", PowerUnit.GigajoulePerHour)] + [InlineData("GW", PowerUnit.Gigawatt)] + [InlineData("hp(H)", PowerUnit.HydraulicHorsepower)] + [InlineData("J/h", PowerUnit.JoulePerHour)] + [InlineData("kBtu/h", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("kBtu/hr", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("kJ/h", PowerUnit.KilojoulePerHour)] + [InlineData("kW", PowerUnit.Kilowatt)] + [InlineData("hp(I)", PowerUnit.MechanicalHorsepower)] + [InlineData("MBtu/h", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("MBtu/hr", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("MJ/h", PowerUnit.MegajoulePerHour)] + [InlineData("MW", PowerUnit.Megawatt)] + [InlineData("hp(M)", PowerUnit.MetricHorsepower)] + [InlineData("µW", PowerUnit.Microwatt)] + [InlineData("mJ/h", PowerUnit.MillijoulePerHour)] + [InlineData("mW", PowerUnit.Milliwatt)] + [InlineData("nW", PowerUnit.Nanowatt)] + [InlineData("PW", PowerUnit.Petawatt)] + [InlineData("pW", PowerUnit.Picowatt)] + [InlineData("TW", PowerUnit.Terawatt)] + [InlineData("TR", PowerUnit.TonOfRefrigeration)] + [InlineData("W", PowerUnit.Watt)] + public void TryParseUnit(string abbreviation, PowerUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Power.TryParseUnit(abbreviation, out PowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "hp(S)", PowerUnit.BoilerHorsepower)] + [InlineData("en-US", "Btu/h", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("en-US", "Btu/hr", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("en-US", "daW", PowerUnit.Decawatt)] + [InlineData("en-US", "dW", PowerUnit.Deciwatt)] + [InlineData("en-US", "hp(E)", PowerUnit.ElectricalHorsepower)] + [InlineData("en-US", "fW", PowerUnit.Femtowatt)] + [InlineData("en-US", "GJ/h", PowerUnit.GigajoulePerHour)] + [InlineData("en-US", "GW", PowerUnit.Gigawatt)] + [InlineData("en-US", "hp(H)", PowerUnit.HydraulicHorsepower)] + [InlineData("en-US", "J/h", PowerUnit.JoulePerHour)] + [InlineData("en-US", "kBtu/h", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("en-US", "kBtu/hr", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("en-US", "kJ/h", PowerUnit.KilojoulePerHour)] + [InlineData("en-US", "kW", PowerUnit.Kilowatt)] + [InlineData("en-US", "hp(I)", PowerUnit.MechanicalHorsepower)] + [InlineData("en-US", "MBtu/h", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("en-US", "MBtu/hr", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("en-US", "MJ/h", PowerUnit.MegajoulePerHour)] + [InlineData("en-US", "MW", PowerUnit.Megawatt)] + [InlineData("en-US", "hp(M)", PowerUnit.MetricHorsepower)] + [InlineData("en-US", "µW", PowerUnit.Microwatt)] + [InlineData("en-US", "mJ/h", PowerUnit.MillijoulePerHour)] + [InlineData("en-US", "mW", PowerUnit.Milliwatt)] + [InlineData("en-US", "nW", PowerUnit.Nanowatt)] + [InlineData("en-US", "PW", PowerUnit.Petawatt)] + [InlineData("en-US", "pW", PowerUnit.Picowatt)] + [InlineData("en-US", "TW", PowerUnit.Terawatt)] + [InlineData("en-US", "TR", PowerUnit.TonOfRefrigeration)] + [InlineData("en-US", "W", PowerUnit.Watt)] + public void TryParseUnitWithCulture(string culture, string abbreviation, PowerUnit expectedUnit) + { + Assert.True(Power.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs index 457e34fb0b..c95e405394 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs @@ -981,542 +981,178 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = PressureChangeRate.ParseUnit("atm/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.AtmospherePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("атм/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.AtmospherePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("bar/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.BarPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("бар/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.BarPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("bar/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.BarPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("бар/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.BarPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("kPa/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.KilopascalPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("кПа/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.KilopascalPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("kPa/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.KilopascalPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("кПа/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.KilopascalPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("ksi/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("kipf/in²/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("ksi/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("kipf/in²/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("ksi/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("kipf/in²/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("ksi/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("kipf/in²/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("MPa/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.MegapascalPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("МПа/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.MegapascalPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("MPa/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.MegapascalPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("МПа/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.MegapascalPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Mpsi/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Mlb/in²/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Мpsi/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Мlb/in²/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Mpsi/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Mlb/in²/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Мpsi/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Мlb/in²/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("mbar/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.MillibarPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("мбар/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.MillibarPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("mbar/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.MillibarPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("мбар/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.MillibarPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("mmHg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.MillimeterOfMercuryPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("mmHg/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.MillimeterOfMercuryPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Pa/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.PascalPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Па/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.PascalPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Pa/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.PascalPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("Па/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.PascalPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("psi/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("lb/in²/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("psi/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("lb/in²/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("psi/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("lb/in²/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("psi/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = PressureChangeRate.ParseUnit("lb/in²/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("atm/s", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("bar/min", PressureChangeRateUnit.BarPerMinute)] + [InlineData("bar/s", PressureChangeRateUnit.BarPerSecond)] + [InlineData("kPa/min", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("kPa/s", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("ksi/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("kipf/in²/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ksi/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("kipf/in²/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("MPa/min", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("MPa/s", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("Mpsi/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("Mlb/in²/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("Mpsi/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("Mlb/in²/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("mbar/min", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("mbar/s", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("mmHg/s", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("Pa/min", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("Pa/s", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("psi/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + public void ParseUnit(string abbreviation, PressureChangeRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + PressureChangeRateUnit parsedUnit = PressureChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(PressureChangeRate.TryParseUnit("atm/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.AtmospherePerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("атм/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.AtmospherePerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("bar/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.BarPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("бар/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.BarPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("bar/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.BarPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("бар/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.BarPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("kPa/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopascalPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("кПа/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopascalPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("kPa/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopascalPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("кПа/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopascalPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("ksi/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("kipf/in²/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("ksi/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("kipf/in²/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("ksi/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("kipf/in²/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("ksi/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("kipf/in²/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("MPa/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapascalPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("МПа/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapascalPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("MPa/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapascalPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("МПа/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapascalPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Mpsi/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Mlb/in²/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Мpsi/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Мlb/in²/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Mpsi/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Mlb/in²/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Мpsi/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Мlb/in²/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("mbar/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MillibarPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("мбар/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MillibarPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("mbar/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MillibarPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("мбар/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MillibarPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("mmHg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MillimeterOfMercuryPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("mmHg/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.MillimeterOfMercuryPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Pa/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PascalPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Па/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PascalPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Pa/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PascalPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("Па/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PascalPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("psi/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("lb/in²/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("psi/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("lb/in²/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerMinute, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("psi/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("lb/in²/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsedUnit); - } - - { - Assert.True(PressureChangeRate.TryParseUnit("psi/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsedUnit); - } + [Theory] + [InlineData("en-US", "atm/s", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("en-US", "bar/min", PressureChangeRateUnit.BarPerMinute)] + [InlineData("en-US", "bar/s", PressureChangeRateUnit.BarPerSecond)] + [InlineData("en-US", "kPa/min", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("en-US", "kPa/s", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("en-US", "ksi/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "kipf/in²/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "ksi/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "kipf/in²/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "MPa/min", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("en-US", "MPa/s", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("en-US", "Mpsi/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "Mlb/in²/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "Mpsi/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "Mlb/in²/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "mbar/min", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("en-US", "mbar/s", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("en-US", "mmHg/s", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("en-US", "Pa/min", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("en-US", "Pa/s", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("en-US", "psi/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "атм/с", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("ru-RU", "бар/мин", PressureChangeRateUnit.BarPerMinute)] + [InlineData("ru-RU", "бар/с", PressureChangeRateUnit.BarPerSecond)] + [InlineData("ru-RU", "кПа/мин", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("ru-RU", "кПа/с", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("ru-RU", "ksi/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "kipf/in²/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "ksi/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "kipf/in²/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "МПа/мин", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("ru-RU", "МПа/с", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("ru-RU", "Мpsi/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "Мlb/in²/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "Мpsi/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "Мlb/in²/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "мбар/мин", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("ru-RU", "мбар/с", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("ru-RU", "mmHg/с", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("ru-RU", "Па/мин", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("ru-RU", "Па/с", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("ru-RU", "psi/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "lb/in²/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "psi/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "lb/in²/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, PressureChangeRateUnit expectedUnit) + { + PressureChangeRateUnit parsedUnit = PressureChangeRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(PressureChangeRate.TryParseUnit("lb/in²/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureChangeRateUnit.PoundForcePerSquareInchPerSecond, parsedUnit); - } + [Theory] + [InlineData("atm/s", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("bar/min", PressureChangeRateUnit.BarPerMinute)] + [InlineData("bar/s", PressureChangeRateUnit.BarPerSecond)] + [InlineData("kPa/min", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("kPa/s", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("ksi/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("kipf/in²/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ksi/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("kipf/in²/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("MPa/min", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("MPa/s", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("Mpsi/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("Mlb/in²/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("Mpsi/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("Mlb/in²/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("mbar/min", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("mbar/s", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("mmHg/s", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("Pa/min", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("Pa/s", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("psi/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + public void TryParseUnit(string abbreviation, PressureChangeRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(PressureChangeRate.TryParseUnit(abbreviation, out PressureChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "atm/s", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("en-US", "bar/min", PressureChangeRateUnit.BarPerMinute)] + [InlineData("en-US", "bar/s", PressureChangeRateUnit.BarPerSecond)] + [InlineData("en-US", "kPa/min", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("en-US", "kPa/s", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("en-US", "ksi/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "kipf/in²/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "ksi/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "kipf/in²/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "MPa/min", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("en-US", "MPa/s", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("en-US", "Mpsi/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "Mlb/in²/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "Mpsi/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "Mlb/in²/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "mbar/min", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("en-US", "mbar/s", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("en-US", "mmHg/s", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("en-US", "Pa/min", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("en-US", "Pa/s", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("en-US", "psi/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "атм/с", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("ru-RU", "бар/мин", PressureChangeRateUnit.BarPerMinute)] + [InlineData("ru-RU", "бар/с", PressureChangeRateUnit.BarPerSecond)] + [InlineData("ru-RU", "кПа/мин", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("ru-RU", "кПа/с", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("ru-RU", "ksi/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "kipf/in²/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "ksi/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "kipf/in²/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "МПа/мин", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("ru-RU", "МПа/с", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("ru-RU", "Мpsi/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "Мlb/in²/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "Мpsi/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "Мlb/in²/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "мбар/мин", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("ru-RU", "мбар/с", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("ru-RU", "mmHg/с", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("ru-RU", "Па/мин", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("ru-RU", "Па/с", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("ru-RU", "psi/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "lb/in²/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "psi/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "lb/in²/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, PressureChangeRateUnit expectedUnit) + { + Assert.True(PressureChangeRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PressureChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs index 597fba7dfc..0653b58774 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs @@ -1868,1031 +1868,356 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Pressure.ParseUnit("atm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Atmosphere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("атм", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Atmosphere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("bar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Bar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("бар", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Bar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("cbar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Centibar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("сбар", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Centibar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("cmH₂O", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("cmH2O", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("cm wc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("cm wg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("daPa", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Decapascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("даПа", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Decapascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("dbar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Decibar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("дбар", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Decibar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("dyn/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.DynePerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("ft of elevation", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.FootOfElevation, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("ft of head", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.FootOfHead, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("GPa", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Gigapascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("ГПа", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Gigapascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("hPa", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Hectopascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("гПа", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Hectopascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("inHg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.InchOfMercury, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("inH2O", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("inch wc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("wc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kbar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Kilobar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("кбар", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Kilobar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kgf/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.KilogramForcePerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("кгс/см²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.KilogramForcePerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kgf/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.KilogramForcePerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("кгс/м²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.KilogramForcePerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kgf/mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.KilogramForcePerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("кгс/мм²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.KilogramForcePerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kN/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.KilonewtonPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("кН/см²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.KilonewtonPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kN/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.KilonewtonPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("кН/м²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.KilonewtonPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kN/mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.KilonewtonPerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("кН/мм²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.KilonewtonPerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kPa", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Kilopascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("кПа", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Kilopascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kipf/ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.KilopoundForcePerSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("ksi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kipf/in²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("ksi", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kipf/in²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("kipf/mil²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.KilopoundForcePerSquareMil, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("Mbar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Megabar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("Мбар", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Megabar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("MN/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MeganewtonPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("МН/м²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.MeganewtonPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("MPa", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Megapascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("МПа", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Megapascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("m of elevation", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MeterOfElevation, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("m of head", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MeterOfHead, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("mH₂O", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("mH2O", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("m wc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("m wg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("µbar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Microbar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("мкбар", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Microbar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("µPa", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Micropascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("мкПа", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Micropascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("mbar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Millibar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("мбар", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Millibar, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("mmHg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MillimeterOfMercury, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("мм рт.ст.", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.MillimeterOfMercury, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("mmH₂O", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("mmH2O", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("mm wc", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("mm wg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("mPa", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Millipascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("мПа", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Millipascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("N/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.NewtonPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("Н/см²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.NewtonPerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("N/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.NewtonPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("Н/м²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.NewtonPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("N/mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.NewtonPerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("Н/мм²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.NewtonPerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("Pa", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Pascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("Па", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Pascal, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("lb/ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.PoundForcePerSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("psi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("lb/in²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("psi", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("lb/in²", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("lb/mil²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.PoundForcePerSquareMil, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("lbs/mil²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.PoundForcePerSquareMil, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("lbm/(in·s²)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.PoundPerInchSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("lb/(in·s²)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.PoundPerInchSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("at", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.TechnicalAtmosphere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("ат", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.TechnicalAtmosphere, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("tf/cm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.TonneForcePerSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("tf/m²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.TonneForcePerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("tf/mm²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.TonneForcePerSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("torr", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(PressureUnit.Torr, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Pressure.ParseUnit("торр", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(PressureUnit.Torr, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParseUnit() - { - { - Assert.True(Pressure.TryParseUnit("atm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Atmosphere, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("атм", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.Atmosphere, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("bar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Bar, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("бар", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.Bar, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("cbar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Centibar, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("сбар", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.Centibar, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("cmH₂O", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("cmH2O", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("cm wc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("cm wg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.CentimeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("daPa", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Decapascal, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("даПа", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.Decapascal, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("dbar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Decibar, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("дбар", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.Decibar, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("dyn/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.DynePerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("ft of elevation", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.FootOfElevation, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("ft of head", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.FootOfHead, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("GPa", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Gigapascal, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("hPa", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Hectopascal, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("inHg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.InchOfMercury, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("inH2O", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("inch wc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("wc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.InchOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kbar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Kilobar, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("кбар", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.Kilobar, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kgf/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilogramForcePerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("кгс/см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilogramForcePerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kgf/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilogramForcePerSquareMeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("кгс/м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilogramForcePerSquareMeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kgf/mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilogramForcePerSquareMillimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("кгс/мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilogramForcePerSquareMillimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kN/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilonewtonPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("кН/см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilonewtonPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kN/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilonewtonPerSquareMeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("кН/м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilonewtonPerSquareMeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kN/mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilonewtonPerSquareMillimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("кН/мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilonewtonPerSquareMillimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kPa", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Kilopascal, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("кПа", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.Kilopascal, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kipf/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilopoundForcePerSquareFoot, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("ksi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kipf/in²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("ksi", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kipf/in²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilopoundForcePerSquareInch, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("kipf/mil²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.KilopoundForcePerSquareMil, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("MN/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MeganewtonPerSquareMeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("МН/м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.MeganewtonPerSquareMeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("m of elevation", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MeterOfElevation, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("m of head", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MeterOfHead, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("mH₂O", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("mH2O", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("m wc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("m wg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("µbar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Microbar, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("мкбар", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.Microbar, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("µPa", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Micropascal, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("мкПа", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.Micropascal, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("mmHg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MillimeterOfMercury, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("мм рт.ст.", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.MillimeterOfMercury, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("mmH₂O", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("mmH2O", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("mm wc", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("mm wg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.MillimeterOfWaterColumn, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("N/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.NewtonPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("Н/см²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.NewtonPerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("N/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.NewtonPerSquareMeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("Н/м²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.NewtonPerSquareMeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("N/mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.NewtonPerSquareMillimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("Н/мм²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.NewtonPerSquareMillimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("Pa", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Pascal, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("Па", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.Pascal, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("lb/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.PoundForcePerSquareFoot, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("psi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("lb/in²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("psi", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("lb/in²", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.PoundForcePerSquareInch, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("lb/mil²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.PoundForcePerSquareMil, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("lbs/mil²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.PoundForcePerSquareMil, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("lbm/(in·s²)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.PoundPerInchSecondSquared, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("lb/(in·s²)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.PoundPerInchSecondSquared, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("at", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.TechnicalAtmosphere, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("ат", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.TechnicalAtmosphere, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("tf/cm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.TonneForcePerSquareCentimeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("tf/m²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.TonneForcePerSquareMeter, parsedUnit); - } - - { - Assert.True(Pressure.TryParseUnit("tf/mm²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.TonneForcePerSquareMillimeter, parsedUnit); - } + [Theory] + [InlineData("atm", PressureUnit.Atmosphere)] + [InlineData("bar", PressureUnit.Bar)] + [InlineData("cbar", PressureUnit.Centibar)] + [InlineData("cmH₂O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cmH2O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cm wc", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cm wg", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("daPa", PressureUnit.Decapascal)] + [InlineData("dbar", PressureUnit.Decibar)] + [InlineData("dyn/cm²", PressureUnit.DynePerSquareCentimeter)] + [InlineData("ft of elevation", PressureUnit.FootOfElevation)] + [InlineData("ft of head", PressureUnit.FootOfHead)] + [InlineData("GPa", PressureUnit.Gigapascal)] + [InlineData("hPa", PressureUnit.Hectopascal)] + [InlineData("inHg", PressureUnit.InchOfMercury)] + [InlineData("inH2O", PressureUnit.InchOfWaterColumn)] + [InlineData("inch wc", PressureUnit.InchOfWaterColumn)] + [InlineData("wc", PressureUnit.InchOfWaterColumn)] + [InlineData("kbar", PressureUnit.Kilobar)] + [InlineData("kgf/cm²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("kgf/m²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("kgf/mm²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("kN/cm²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("kN/m²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("kN/mm²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("kPa", PressureUnit.Kilopascal)] + [InlineData("kipf/ft²", PressureUnit.KilopoundForcePerSquareFoot)] + [InlineData("ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("kipf/mil²", PressureUnit.KilopoundForcePerSquareMil)] + [InlineData("Mbar", PressureUnit.Megabar)] + [InlineData("MN/m²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("MPa", PressureUnit.Megapascal)] + [InlineData("m of elevation", PressureUnit.MeterOfElevation)] + [InlineData("m of head", PressureUnit.MeterOfHead)] + [InlineData("mH₂O", PressureUnit.MeterOfWaterColumn)] + [InlineData("mH2O", PressureUnit.MeterOfWaterColumn)] + [InlineData("m wc", PressureUnit.MeterOfWaterColumn)] + [InlineData("m wg", PressureUnit.MeterOfWaterColumn)] + [InlineData("µbar", PressureUnit.Microbar)] + [InlineData("µPa", PressureUnit.Micropascal)] + [InlineData("mbar", PressureUnit.Millibar)] + [InlineData("mmHg", PressureUnit.MillimeterOfMercury)] + [InlineData("mmH₂O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mmH2O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mm wc", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mm wg", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mPa", PressureUnit.Millipascal)] + [InlineData("N/cm²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("N/m²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("N/mm²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("Pa", PressureUnit.Pascal)] + [InlineData("lb/ft²", PressureUnit.PoundForcePerSquareFoot)] + [InlineData("psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("lb/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("lbs/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("lbm/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("lb/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("at", PressureUnit.TechnicalAtmosphere)] + [InlineData("tf/cm²", PressureUnit.TonneForcePerSquareCentimeter)] + [InlineData("tf/m²", PressureUnit.TonneForcePerSquareMeter)] + [InlineData("tf/mm²", PressureUnit.TonneForcePerSquareMillimeter)] + [InlineData("torr", PressureUnit.Torr)] + public void ParseUnit(string abbreviation, PressureUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + PressureUnit parsedUnit = Pressure.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Pressure.TryParseUnit("torr", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(PressureUnit.Torr, parsedUnit); - } + [Theory] + [InlineData("en-US", "atm", PressureUnit.Atmosphere)] + [InlineData("en-US", "bar", PressureUnit.Bar)] + [InlineData("en-US", "cbar", PressureUnit.Centibar)] + [InlineData("en-US", "cmH₂O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cmH2O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cm wc", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cm wg", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "daPa", PressureUnit.Decapascal)] + [InlineData("en-US", "dbar", PressureUnit.Decibar)] + [InlineData("en-US", "dyn/cm²", PressureUnit.DynePerSquareCentimeter)] + [InlineData("en-US", "ft of elevation", PressureUnit.FootOfElevation)] + [InlineData("en-US", "ft of head", PressureUnit.FootOfHead)] + [InlineData("en-US", "GPa", PressureUnit.Gigapascal)] + [InlineData("en-US", "hPa", PressureUnit.Hectopascal)] + [InlineData("en-US", "inHg", PressureUnit.InchOfMercury)] + [InlineData("en-US", "inH2O", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "inch wc", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "wc", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "kbar", PressureUnit.Kilobar)] + [InlineData("en-US", "kgf/cm²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("en-US", "kgf/m²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("en-US", "kgf/mm²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("en-US", "kN/cm²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("en-US", "kN/m²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("en-US", "kN/mm²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("en-US", "kPa", PressureUnit.Kilopascal)] + [InlineData("en-US", "kipf/ft²", PressureUnit.KilopoundForcePerSquareFoot)] + [InlineData("en-US", "ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("en-US", "kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("en-US", "kipf/mil²", PressureUnit.KilopoundForcePerSquareMil)] + [InlineData("en-US", "Mbar", PressureUnit.Megabar)] + [InlineData("en-US", "MN/m²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("en-US", "MPa", PressureUnit.Megapascal)] + [InlineData("en-US", "m of elevation", PressureUnit.MeterOfElevation)] + [InlineData("en-US", "m of head", PressureUnit.MeterOfHead)] + [InlineData("en-US", "mH₂O", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "mH2O", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "m wc", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "m wg", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "µbar", PressureUnit.Microbar)] + [InlineData("en-US", "µPa", PressureUnit.Micropascal)] + [InlineData("en-US", "mbar", PressureUnit.Millibar)] + [InlineData("en-US", "mmHg", PressureUnit.MillimeterOfMercury)] + [InlineData("en-US", "mmH₂O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mmH2O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mm wc", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mm wg", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mPa", PressureUnit.Millipascal)] + [InlineData("en-US", "N/cm²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("en-US", "N/m²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("en-US", "N/mm²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("en-US", "Pa", PressureUnit.Pascal)] + [InlineData("en-US", "lb/ft²", PressureUnit.PoundForcePerSquareFoot)] + [InlineData("en-US", "psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("en-US", "lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("en-US", "lb/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("en-US", "lbs/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("en-US", "lbm/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("en-US", "lb/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("en-US", "at", PressureUnit.TechnicalAtmosphere)] + [InlineData("en-US", "tf/cm²", PressureUnit.TonneForcePerSquareCentimeter)] + [InlineData("en-US", "tf/m²", PressureUnit.TonneForcePerSquareMeter)] + [InlineData("en-US", "tf/mm²", PressureUnit.TonneForcePerSquareMillimeter)] + [InlineData("en-US", "torr", PressureUnit.Torr)] + [InlineData("ru-RU", "атм", PressureUnit.Atmosphere)] + [InlineData("ru-RU", "бар", PressureUnit.Bar)] + [InlineData("ru-RU", "сбар", PressureUnit.Centibar)] + [InlineData("ru-RU", "даПа", PressureUnit.Decapascal)] + [InlineData("ru-RU", "дбар", PressureUnit.Decibar)] + [InlineData("ru-RU", "ГПа", PressureUnit.Gigapascal)] + [InlineData("ru-RU", "гПа", PressureUnit.Hectopascal)] + [InlineData("ru-RU", "кбар", PressureUnit.Kilobar)] + [InlineData("ru-RU", "кгс/см²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("ru-RU", "кгс/м²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("ru-RU", "кгс/мм²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("ru-RU", "кН/см²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("ru-RU", "кН/м²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("ru-RU", "кН/мм²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("ru-RU", "кПа", PressureUnit.Kilopascal)] + [InlineData("ru-RU", "ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("ru-RU", "kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("ru-RU", "Мбар", PressureUnit.Megabar)] + [InlineData("ru-RU", "МН/м²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("ru-RU", "МПа", PressureUnit.Megapascal)] + [InlineData("ru-RU", "мкбар", PressureUnit.Microbar)] + [InlineData("ru-RU", "мкПа", PressureUnit.Micropascal)] + [InlineData("ru-RU", "мбар", PressureUnit.Millibar)] + [InlineData("ru-RU", "мм рт.ст.", PressureUnit.MillimeterOfMercury)] + [InlineData("ru-RU", "мПа", PressureUnit.Millipascal)] + [InlineData("ru-RU", "Н/см²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("ru-RU", "Н/м²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("ru-RU", "Н/мм²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("ru-RU", "Па", PressureUnit.Pascal)] + [InlineData("ru-RU", "psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("ru-RU", "lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("ru-RU", "ат", PressureUnit.TechnicalAtmosphere)] + [InlineData("ru-RU", "торр", PressureUnit.Torr)] + public void ParseUnitWithCulture(string culture, string abbreviation, PressureUnit expectedUnit) + { + PressureUnit parsedUnit = Pressure.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Pressure.TryParseUnit("торр", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(PressureUnit.Torr, parsedUnit); - } + [Theory] + [InlineData("atm", PressureUnit.Atmosphere)] + [InlineData("bar", PressureUnit.Bar)] + [InlineData("cbar", PressureUnit.Centibar)] + [InlineData("cmH₂O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cmH2O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cm wc", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cm wg", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("daPa", PressureUnit.Decapascal)] + [InlineData("dbar", PressureUnit.Decibar)] + [InlineData("dyn/cm²", PressureUnit.DynePerSquareCentimeter)] + [InlineData("ft of elevation", PressureUnit.FootOfElevation)] + [InlineData("ft of head", PressureUnit.FootOfHead)] + [InlineData("GPa", PressureUnit.Gigapascal)] + [InlineData("hPa", PressureUnit.Hectopascal)] + [InlineData("inHg", PressureUnit.InchOfMercury)] + [InlineData("inH2O", PressureUnit.InchOfWaterColumn)] + [InlineData("inch wc", PressureUnit.InchOfWaterColumn)] + [InlineData("wc", PressureUnit.InchOfWaterColumn)] + [InlineData("kbar", PressureUnit.Kilobar)] + [InlineData("kgf/cm²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("kgf/m²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("kgf/mm²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("kN/cm²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("kN/m²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("kN/mm²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("kPa", PressureUnit.Kilopascal)] + [InlineData("kipf/ft²", PressureUnit.KilopoundForcePerSquareFoot)] + [InlineData("ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("kipf/mil²", PressureUnit.KilopoundForcePerSquareMil)] + [InlineData("Mbar", PressureUnit.Megabar)] + [InlineData("MN/m²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("MPa", PressureUnit.Megapascal)] + [InlineData("m of elevation", PressureUnit.MeterOfElevation)] + [InlineData("m of head", PressureUnit.MeterOfHead)] + [InlineData("mH₂O", PressureUnit.MeterOfWaterColumn)] + [InlineData("mH2O", PressureUnit.MeterOfWaterColumn)] + [InlineData("m wc", PressureUnit.MeterOfWaterColumn)] + [InlineData("m wg", PressureUnit.MeterOfWaterColumn)] + [InlineData("µbar", PressureUnit.Microbar)] + [InlineData("µPa", PressureUnit.Micropascal)] + [InlineData("mbar", PressureUnit.Millibar)] + [InlineData("mmHg", PressureUnit.MillimeterOfMercury)] + [InlineData("mmH₂O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mmH2O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mm wc", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mm wg", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mPa", PressureUnit.Millipascal)] + [InlineData("N/cm²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("N/m²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("N/mm²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("Pa", PressureUnit.Pascal)] + [InlineData("lb/ft²", PressureUnit.PoundForcePerSquareFoot)] + [InlineData("psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("lb/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("lbs/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("lbm/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("lb/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("at", PressureUnit.TechnicalAtmosphere)] + [InlineData("tf/cm²", PressureUnit.TonneForcePerSquareCentimeter)] + [InlineData("tf/m²", PressureUnit.TonneForcePerSquareMeter)] + [InlineData("tf/mm²", PressureUnit.TonneForcePerSquareMillimeter)] + [InlineData("torr", PressureUnit.Torr)] + public void TryParseUnit(string abbreviation, PressureUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Pressure.TryParseUnit(abbreviation, out PressureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "atm", PressureUnit.Atmosphere)] + [InlineData("en-US", "bar", PressureUnit.Bar)] + [InlineData("en-US", "cbar", PressureUnit.Centibar)] + [InlineData("en-US", "cmH₂O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cmH2O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cm wc", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cm wg", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "daPa", PressureUnit.Decapascal)] + [InlineData("en-US", "dbar", PressureUnit.Decibar)] + [InlineData("en-US", "dyn/cm²", PressureUnit.DynePerSquareCentimeter)] + [InlineData("en-US", "ft of elevation", PressureUnit.FootOfElevation)] + [InlineData("en-US", "ft of head", PressureUnit.FootOfHead)] + [InlineData("en-US", "GPa", PressureUnit.Gigapascal)] + [InlineData("en-US", "hPa", PressureUnit.Hectopascal)] + [InlineData("en-US", "inHg", PressureUnit.InchOfMercury)] + [InlineData("en-US", "inH2O", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "inch wc", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "wc", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "kbar", PressureUnit.Kilobar)] + [InlineData("en-US", "kgf/cm²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("en-US", "kgf/m²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("en-US", "kgf/mm²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("en-US", "kN/cm²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("en-US", "kN/m²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("en-US", "kN/mm²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("en-US", "kPa", PressureUnit.Kilopascal)] + [InlineData("en-US", "kipf/ft²", PressureUnit.KilopoundForcePerSquareFoot)] + [InlineData("en-US", "ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("en-US", "kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("en-US", "kipf/mil²", PressureUnit.KilopoundForcePerSquareMil)] + [InlineData("en-US", "Mbar", PressureUnit.Megabar)] + [InlineData("en-US", "MN/m²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("en-US", "MPa", PressureUnit.Megapascal)] + [InlineData("en-US", "m of elevation", PressureUnit.MeterOfElevation)] + [InlineData("en-US", "m of head", PressureUnit.MeterOfHead)] + [InlineData("en-US", "mH₂O", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "mH2O", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "m wc", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "m wg", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "µbar", PressureUnit.Microbar)] + [InlineData("en-US", "µPa", PressureUnit.Micropascal)] + [InlineData("en-US", "mbar", PressureUnit.Millibar)] + [InlineData("en-US", "mmHg", PressureUnit.MillimeterOfMercury)] + [InlineData("en-US", "mmH₂O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mmH2O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mm wc", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mm wg", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mPa", PressureUnit.Millipascal)] + [InlineData("en-US", "N/cm²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("en-US", "N/m²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("en-US", "N/mm²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("en-US", "Pa", PressureUnit.Pascal)] + [InlineData("en-US", "lb/ft²", PressureUnit.PoundForcePerSquareFoot)] + [InlineData("en-US", "psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("en-US", "lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("en-US", "lb/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("en-US", "lbs/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("en-US", "lbm/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("en-US", "lb/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("en-US", "at", PressureUnit.TechnicalAtmosphere)] + [InlineData("en-US", "tf/cm²", PressureUnit.TonneForcePerSquareCentimeter)] + [InlineData("en-US", "tf/m²", PressureUnit.TonneForcePerSquareMeter)] + [InlineData("en-US", "tf/mm²", PressureUnit.TonneForcePerSquareMillimeter)] + [InlineData("en-US", "torr", PressureUnit.Torr)] + [InlineData("ru-RU", "атм", PressureUnit.Atmosphere)] + [InlineData("ru-RU", "бар", PressureUnit.Bar)] + [InlineData("ru-RU", "сбар", PressureUnit.Centibar)] + [InlineData("ru-RU", "даПа", PressureUnit.Decapascal)] + [InlineData("ru-RU", "дбар", PressureUnit.Decibar)] + [InlineData("ru-RU", "ГПа", PressureUnit.Gigapascal)] + [InlineData("ru-RU", "гПа", PressureUnit.Hectopascal)] + [InlineData("ru-RU", "кбар", PressureUnit.Kilobar)] + [InlineData("ru-RU", "кгс/см²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("ru-RU", "кгс/м²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("ru-RU", "кгс/мм²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("ru-RU", "кН/см²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("ru-RU", "кН/м²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("ru-RU", "кН/мм²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("ru-RU", "кПа", PressureUnit.Kilopascal)] + [InlineData("ru-RU", "ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("ru-RU", "kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("ru-RU", "Мбар", PressureUnit.Megabar)] + [InlineData("ru-RU", "МН/м²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("ru-RU", "МПа", PressureUnit.Megapascal)] + [InlineData("ru-RU", "мкбар", PressureUnit.Microbar)] + [InlineData("ru-RU", "мкПа", PressureUnit.Micropascal)] + [InlineData("ru-RU", "мбар", PressureUnit.Millibar)] + [InlineData("ru-RU", "мм рт.ст.", PressureUnit.MillimeterOfMercury)] + [InlineData("ru-RU", "мПа", PressureUnit.Millipascal)] + [InlineData("ru-RU", "Н/см²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("ru-RU", "Н/м²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("ru-RU", "Н/мм²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("ru-RU", "Па", PressureUnit.Pascal)] + [InlineData("ru-RU", "psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("ru-RU", "lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("ru-RU", "ат", PressureUnit.TechnicalAtmosphere)] + [InlineData("ru-RU", "торр", PressureUnit.Torr)] + public void TryParseUnitWithCulture(string culture, string abbreviation, PressureUnit expectedUnit) + { + Assert.True(Pressure.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PressureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs index a88920680a..6bd1b755d9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs @@ -367,124 +367,66 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("µSv", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("mrem", RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan)] + [InlineData("mSv", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("nSv", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan)] + [InlineData("Sv", RadiationEquivalentDoseUnit.Sievert)] + public void ParseUnit(string abbreviation, RadiationEquivalentDoseUnit expectedUnit) { - try - { - var parsedUnit = RadiationEquivalentDose.ParseUnit("µSv", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationEquivalentDoseUnit.Microsievert, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationEquivalentDose.ParseUnit("мкЗв", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadiationEquivalentDoseUnit.Microsievert, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationEquivalentDose.ParseUnit("mrem", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationEquivalentDose.ParseUnit("mSv", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationEquivalentDoseUnit.Millisievert, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationEquivalentDose.ParseUnit("мЗв", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadiationEquivalentDoseUnit.Millisievert, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationEquivalentDose.ParseUnit("nSv", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationEquivalentDoseUnit.Nanosievert, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationEquivalentDose.ParseUnit("нЗв", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadiationEquivalentDoseUnit.Nanosievert, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationEquivalentDose.ParseUnit("rem", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationEquivalentDoseUnit.RoentgenEquivalentMan, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationEquivalentDose.ParseUnit("Sv", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationEquivalentDoseUnit.Sievert, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationEquivalentDose.ParseUnit("Зв", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadiationEquivalentDoseUnit.Sievert, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + RadiationEquivalentDoseUnit parsedUnit = RadiationEquivalentDose.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "µSv", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("en-US", "mrem", RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan)] + [InlineData("en-US", "mSv", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("en-US", "nSv", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("en-US", "rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan)] + [InlineData("en-US", "Sv", RadiationEquivalentDoseUnit.Sievert)] + [InlineData("ru-RU", "мкЗв", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("ru-RU", "мЗв", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("ru-RU", "нЗв", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("ru-RU", "Зв", RadiationEquivalentDoseUnit.Sievert)] + public void ParseUnitWithCulture(string culture, string abbreviation, RadiationEquivalentDoseUnit expectedUnit) + { + RadiationEquivalentDoseUnit parsedUnit = RadiationEquivalentDose.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("µSv", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("mrem", RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan)] + [InlineData("mSv", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("nSv", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan)] + [InlineData("Sv", RadiationEquivalentDoseUnit.Sievert)] + public void TryParseUnit(string abbreviation, RadiationEquivalentDoseUnit expectedUnit) { - { - Assert.True(RadiationEquivalentDose.TryParseUnit("µSv", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationEquivalentDoseUnit.Microsievert, parsedUnit); - } - - { - Assert.True(RadiationEquivalentDose.TryParseUnit("мкЗв", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadiationEquivalentDoseUnit.Microsievert, parsedUnit); - } - - { - Assert.True(RadiationEquivalentDose.TryParseUnit("mrem", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan, parsedUnit); - } - - { - Assert.True(RadiationEquivalentDose.TryParseUnit("mSv", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationEquivalentDoseUnit.Millisievert, parsedUnit); - } - - { - Assert.True(RadiationEquivalentDose.TryParseUnit("мЗв", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadiationEquivalentDoseUnit.Millisievert, parsedUnit); - } - - { - Assert.True(RadiationEquivalentDose.TryParseUnit("nSv", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationEquivalentDoseUnit.Nanosievert, parsedUnit); - } - - { - Assert.True(RadiationEquivalentDose.TryParseUnit("нЗв", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadiationEquivalentDoseUnit.Nanosievert, parsedUnit); - } - - { - Assert.True(RadiationEquivalentDose.TryParseUnit("rem", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationEquivalentDoseUnit.RoentgenEquivalentMan, parsedUnit); - } - - { - Assert.True(RadiationEquivalentDose.TryParseUnit("Sv", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationEquivalentDoseUnit.Sievert, parsedUnit); - } - - { - Assert.True(RadiationEquivalentDose.TryParseUnit("Зв", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadiationEquivalentDoseUnit.Sievert, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(RadiationEquivalentDose.TryParseUnit(abbreviation, out RadiationEquivalentDoseUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "µSv", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("en-US", "mrem", RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan)] + [InlineData("en-US", "mSv", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("en-US", "nSv", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("en-US", "rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan)] + [InlineData("en-US", "Sv", RadiationEquivalentDoseUnit.Sievert)] + [InlineData("ru-RU", "мкЗв", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("ru-RU", "мЗв", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("ru-RU", "нЗв", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("ru-RU", "Зв", RadiationEquivalentDoseUnit.Sievert)] + public void TryParseUnitWithCulture(string culture, string abbreviation, RadiationEquivalentDoseUnit expectedUnit) + { + Assert.True(RadiationEquivalentDose.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RadiationEquivalentDoseUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs index 89242ef3a3..a0d36bdc80 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs @@ -361,102 +361,66 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("C/kg", RadiationExposureUnit.CoulombPerKilogram)] + [InlineData("µC/kg", RadiationExposureUnit.MicrocoulombPerKilogram)] + [InlineData("µR", RadiationExposureUnit.Microroentgen)] + [InlineData("mC/kg", RadiationExposureUnit.MillicoulombPerKilogram)] + [InlineData("mR", RadiationExposureUnit.Milliroentgen)] + [InlineData("nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] + [InlineData("pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] + [InlineData("R", RadiationExposureUnit.Roentgen)] + public void ParseUnit(string abbreviation, RadiationExposureUnit expectedUnit) { - try - { - var parsedUnit = RadiationExposure.ParseUnit("C/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationExposureUnit.CoulombPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationExposure.ParseUnit("µC/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationExposure.ParseUnit("µR", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationExposureUnit.Microroentgen, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationExposure.ParseUnit("mC/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationExposure.ParseUnit("mR", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationExposureUnit.Milliroentgen, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationExposure.ParseUnit("nC/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationExposure.ParseUnit("pC/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationExposureUnit.PicocoulombPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RadiationExposure.ParseUnit("R", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadiationExposureUnit.Roentgen, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + RadiationExposureUnit parsedUnit = RadiationExposure.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "C/kg", RadiationExposureUnit.CoulombPerKilogram)] + [InlineData("en-US", "µC/kg", RadiationExposureUnit.MicrocoulombPerKilogram)] + [InlineData("en-US", "µR", RadiationExposureUnit.Microroentgen)] + [InlineData("en-US", "mC/kg", RadiationExposureUnit.MillicoulombPerKilogram)] + [InlineData("en-US", "mR", RadiationExposureUnit.Milliroentgen)] + [InlineData("en-US", "nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] + [InlineData("en-US", "pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] + [InlineData("en-US", "R", RadiationExposureUnit.Roentgen)] + public void ParseUnitWithCulture(string culture, string abbreviation, RadiationExposureUnit expectedUnit) { - { - Assert.True(RadiationExposure.TryParseUnit("C/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationExposureUnit.CoulombPerKilogram, parsedUnit); - } - - { - Assert.True(RadiationExposure.TryParseUnit("µC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationExposureUnit.MicrocoulombPerKilogram, parsedUnit); - } - - { - Assert.True(RadiationExposure.TryParseUnit("µR", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationExposureUnit.Microroentgen, parsedUnit); - } - - { - Assert.True(RadiationExposure.TryParseUnit("mC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationExposureUnit.MillicoulombPerKilogram, parsedUnit); - } - - { - Assert.True(RadiationExposure.TryParseUnit("mR", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationExposureUnit.Milliroentgen, parsedUnit); - } - - { - Assert.True(RadiationExposure.TryParseUnit("nC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationExposureUnit.NanocoulombPerKilogram, parsedUnit); - } - - { - Assert.True(RadiationExposure.TryParseUnit("pC/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationExposureUnit.PicocoulombPerKilogram, parsedUnit); - } + RadiationExposureUnit parsedUnit = RadiationExposure.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(RadiationExposure.TryParseUnit("R", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadiationExposureUnit.Roentgen, parsedUnit); - } + [Theory] + [InlineData("C/kg", RadiationExposureUnit.CoulombPerKilogram)] + [InlineData("µC/kg", RadiationExposureUnit.MicrocoulombPerKilogram)] + [InlineData("µR", RadiationExposureUnit.Microroentgen)] + [InlineData("mC/kg", RadiationExposureUnit.MillicoulombPerKilogram)] + [InlineData("mR", RadiationExposureUnit.Milliroentgen)] + [InlineData("nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] + [InlineData("pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] + [InlineData("R", RadiationExposureUnit.Roentgen)] + public void TryParseUnit(string abbreviation, RadiationExposureUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(RadiationExposure.TryParseUnit(abbreviation, out RadiationExposureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "C/kg", RadiationExposureUnit.CoulombPerKilogram)] + [InlineData("en-US", "µC/kg", RadiationExposureUnit.MicrocoulombPerKilogram)] + [InlineData("en-US", "µR", RadiationExposureUnit.Microroentgen)] + [InlineData("en-US", "mC/kg", RadiationExposureUnit.MillicoulombPerKilogram)] + [InlineData("en-US", "mR", RadiationExposureUnit.Milliroentgen)] + [InlineData("en-US", "nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] + [InlineData("en-US", "pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] + [InlineData("en-US", "R", RadiationExposureUnit.Roentgen)] + public void TryParseUnitWithCulture(string culture, string abbreviation, RadiationExposureUnit expectedUnit) + { + Assert.True(RadiationExposure.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RadiationExposureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs index ee3b3ef0bd..ddb230ffc5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs @@ -1125,572 +1125,208 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Radioactivity.ParseUnit("Bq", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Becquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("Бк", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Becquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("Ci", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Curie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("Ки", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Curie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("EBq", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Exabecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("ЭБк", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Exabecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("GBq", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Gigabecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("ГБк", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Gigabecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("GCi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Gigacurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("ГКи", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Gigacurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("GRd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Gigarutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("ГРд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Gigarutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("kBq", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Kilobecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("кБк", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Kilobecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("kCi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Kilocurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("кКи", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Kilocurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("kRd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Kilorutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("кРд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Kilorutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("MBq", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Megabecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("МБк", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Megabecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("MCi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Megacurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("МКи", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Megacurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("MRd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Megarutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("МРд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Megarutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("µBq", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Microbecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("мкБк", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Microbecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("µCi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Microcurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("мкКи", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Microcurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("µRd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Microrutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("мкРд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Microrutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("mBq", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Millibecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("мБк", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Millibecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("mCi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Millicurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("мКи", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Millicurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("mRd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Millirutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("мРд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Millirutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("nBq", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Nanobecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("нБк", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Nanobecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("nCi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Nanocurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("нКи", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Nanocurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("nRd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Nanorutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("нРд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Nanorutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("PBq", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Petabecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("ПБк", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Petabecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("pBq", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Picobecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("пБк", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Picobecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("pCi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Picocurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("пКи", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Picocurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("pRd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Picorutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("пРд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Picorutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("Rd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Rutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("Рд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Rutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("TBq", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Terabecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("ТБк", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Terabecquerel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("TCi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Teracurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("ТКи", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Teracurie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("TRd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RadioactivityUnit.Terarutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Radioactivity.ParseUnit("ТРд", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RadioactivityUnit.Terarutherford, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("Bq", RadioactivityUnit.Becquerel)] + [InlineData("Ci", RadioactivityUnit.Curie)] + [InlineData("EBq", RadioactivityUnit.Exabecquerel)] + [InlineData("GBq", RadioactivityUnit.Gigabecquerel)] + [InlineData("GCi", RadioactivityUnit.Gigacurie)] + [InlineData("GRd", RadioactivityUnit.Gigarutherford)] + [InlineData("kBq", RadioactivityUnit.Kilobecquerel)] + [InlineData("kCi", RadioactivityUnit.Kilocurie)] + [InlineData("kRd", RadioactivityUnit.Kilorutherford)] + [InlineData("MBq", RadioactivityUnit.Megabecquerel)] + [InlineData("MCi", RadioactivityUnit.Megacurie)] + [InlineData("MRd", RadioactivityUnit.Megarutherford)] + [InlineData("µBq", RadioactivityUnit.Microbecquerel)] + [InlineData("µCi", RadioactivityUnit.Microcurie)] + [InlineData("µRd", RadioactivityUnit.Microrutherford)] + [InlineData("mBq", RadioactivityUnit.Millibecquerel)] + [InlineData("mCi", RadioactivityUnit.Millicurie)] + [InlineData("mRd", RadioactivityUnit.Millirutherford)] + [InlineData("nBq", RadioactivityUnit.Nanobecquerel)] + [InlineData("nCi", RadioactivityUnit.Nanocurie)] + [InlineData("nRd", RadioactivityUnit.Nanorutherford)] + [InlineData("PBq", RadioactivityUnit.Petabecquerel)] + [InlineData("pBq", RadioactivityUnit.Picobecquerel)] + [InlineData("pCi", RadioactivityUnit.Picocurie)] + [InlineData("pRd", RadioactivityUnit.Picorutherford)] + [InlineData("Rd", RadioactivityUnit.Rutherford)] + [InlineData("TBq", RadioactivityUnit.Terabecquerel)] + [InlineData("TCi", RadioactivityUnit.Teracurie)] + [InlineData("TRd", RadioactivityUnit.Terarutherford)] + public void ParseUnit(string abbreviation, RadioactivityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + RadioactivityUnit parsedUnit = Radioactivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Radioactivity.TryParseUnit("Bq", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Becquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("Бк", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Becquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("Ci", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Curie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("Ки", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Curie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("EBq", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Exabecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("ЭБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Exabecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("GBq", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Gigabecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("ГБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Gigabecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("GCi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Gigacurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("ГКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Gigacurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("GRd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Gigarutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("ГРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Gigarutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("kBq", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Kilobecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("кБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Kilobecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("kCi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Kilocurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("кКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Kilocurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("kRd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Kilorutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("кРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Kilorutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("µBq", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Microbecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("мкБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Microbecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("µCi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Microcurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("мкКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Microcurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("µRd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Microrutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("мкРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Microrutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("nBq", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Nanobecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("нБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Nanobecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("nCi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Nanocurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("нКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Nanocurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("nRd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Nanorutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("нРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Nanorutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("pCi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Picocurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("пКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Picocurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("pRd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Picorutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("пРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Picorutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("Rd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Rutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("Рд", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Rutherford, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("TBq", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Terabecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("ТБк", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Terabecquerel, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("TCi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Teracurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("ТКи", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Teracurie, parsedUnit); - } - - { - Assert.True(Radioactivity.TryParseUnit("TRd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Terarutherford, parsedUnit); - } + [Theory] + [InlineData("en-US", "Bq", RadioactivityUnit.Becquerel)] + [InlineData("en-US", "Ci", RadioactivityUnit.Curie)] + [InlineData("en-US", "EBq", RadioactivityUnit.Exabecquerel)] + [InlineData("en-US", "GBq", RadioactivityUnit.Gigabecquerel)] + [InlineData("en-US", "GCi", RadioactivityUnit.Gigacurie)] + [InlineData("en-US", "GRd", RadioactivityUnit.Gigarutherford)] + [InlineData("en-US", "kBq", RadioactivityUnit.Kilobecquerel)] + [InlineData("en-US", "kCi", RadioactivityUnit.Kilocurie)] + [InlineData("en-US", "kRd", RadioactivityUnit.Kilorutherford)] + [InlineData("en-US", "MBq", RadioactivityUnit.Megabecquerel)] + [InlineData("en-US", "MCi", RadioactivityUnit.Megacurie)] + [InlineData("en-US", "MRd", RadioactivityUnit.Megarutherford)] + [InlineData("en-US", "µBq", RadioactivityUnit.Microbecquerel)] + [InlineData("en-US", "µCi", RadioactivityUnit.Microcurie)] + [InlineData("en-US", "µRd", RadioactivityUnit.Microrutherford)] + [InlineData("en-US", "mBq", RadioactivityUnit.Millibecquerel)] + [InlineData("en-US", "mCi", RadioactivityUnit.Millicurie)] + [InlineData("en-US", "mRd", RadioactivityUnit.Millirutherford)] + [InlineData("en-US", "nBq", RadioactivityUnit.Nanobecquerel)] + [InlineData("en-US", "nCi", RadioactivityUnit.Nanocurie)] + [InlineData("en-US", "nRd", RadioactivityUnit.Nanorutherford)] + [InlineData("en-US", "PBq", RadioactivityUnit.Petabecquerel)] + [InlineData("en-US", "pBq", RadioactivityUnit.Picobecquerel)] + [InlineData("en-US", "pCi", RadioactivityUnit.Picocurie)] + [InlineData("en-US", "pRd", RadioactivityUnit.Picorutherford)] + [InlineData("en-US", "Rd", RadioactivityUnit.Rutherford)] + [InlineData("en-US", "TBq", RadioactivityUnit.Terabecquerel)] + [InlineData("en-US", "TCi", RadioactivityUnit.Teracurie)] + [InlineData("en-US", "TRd", RadioactivityUnit.Terarutherford)] + [InlineData("ru-RU", "Бк", RadioactivityUnit.Becquerel)] + [InlineData("ru-RU", "Ки", RadioactivityUnit.Curie)] + [InlineData("ru-RU", "ЭБк", RadioactivityUnit.Exabecquerel)] + [InlineData("ru-RU", "ГБк", RadioactivityUnit.Gigabecquerel)] + [InlineData("ru-RU", "ГКи", RadioactivityUnit.Gigacurie)] + [InlineData("ru-RU", "ГРд", RadioactivityUnit.Gigarutherford)] + [InlineData("ru-RU", "кБк", RadioactivityUnit.Kilobecquerel)] + [InlineData("ru-RU", "кКи", RadioactivityUnit.Kilocurie)] + [InlineData("ru-RU", "кРд", RadioactivityUnit.Kilorutherford)] + [InlineData("ru-RU", "МБк", RadioactivityUnit.Megabecquerel)] + [InlineData("ru-RU", "МКи", RadioactivityUnit.Megacurie)] + [InlineData("ru-RU", "МРд", RadioactivityUnit.Megarutherford)] + [InlineData("ru-RU", "мкБк", RadioactivityUnit.Microbecquerel)] + [InlineData("ru-RU", "мкКи", RadioactivityUnit.Microcurie)] + [InlineData("ru-RU", "мкРд", RadioactivityUnit.Microrutherford)] + [InlineData("ru-RU", "мБк", RadioactivityUnit.Millibecquerel)] + [InlineData("ru-RU", "мКи", RadioactivityUnit.Millicurie)] + [InlineData("ru-RU", "мРд", RadioactivityUnit.Millirutherford)] + [InlineData("ru-RU", "нБк", RadioactivityUnit.Nanobecquerel)] + [InlineData("ru-RU", "нКи", RadioactivityUnit.Nanocurie)] + [InlineData("ru-RU", "нРд", RadioactivityUnit.Nanorutherford)] + [InlineData("ru-RU", "ПБк", RadioactivityUnit.Petabecquerel)] + [InlineData("ru-RU", "пБк", RadioactivityUnit.Picobecquerel)] + [InlineData("ru-RU", "пКи", RadioactivityUnit.Picocurie)] + [InlineData("ru-RU", "пРд", RadioactivityUnit.Picorutherford)] + [InlineData("ru-RU", "Рд", RadioactivityUnit.Rutherford)] + [InlineData("ru-RU", "ТБк", RadioactivityUnit.Terabecquerel)] + [InlineData("ru-RU", "ТКи", RadioactivityUnit.Teracurie)] + [InlineData("ru-RU", "ТРд", RadioactivityUnit.Terarutherford)] + public void ParseUnitWithCulture(string culture, string abbreviation, RadioactivityUnit expectedUnit) + { + RadioactivityUnit parsedUnit = Radioactivity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Radioactivity.TryParseUnit("ТРд", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RadioactivityUnit.Terarutherford, parsedUnit); - } + [Theory] + [InlineData("Bq", RadioactivityUnit.Becquerel)] + [InlineData("Ci", RadioactivityUnit.Curie)] + [InlineData("EBq", RadioactivityUnit.Exabecquerel)] + [InlineData("GBq", RadioactivityUnit.Gigabecquerel)] + [InlineData("GCi", RadioactivityUnit.Gigacurie)] + [InlineData("GRd", RadioactivityUnit.Gigarutherford)] + [InlineData("kBq", RadioactivityUnit.Kilobecquerel)] + [InlineData("kCi", RadioactivityUnit.Kilocurie)] + [InlineData("kRd", RadioactivityUnit.Kilorutherford)] + [InlineData("MBq", RadioactivityUnit.Megabecquerel)] + [InlineData("MCi", RadioactivityUnit.Megacurie)] + [InlineData("MRd", RadioactivityUnit.Megarutherford)] + [InlineData("µBq", RadioactivityUnit.Microbecquerel)] + [InlineData("µCi", RadioactivityUnit.Microcurie)] + [InlineData("µRd", RadioactivityUnit.Microrutherford)] + [InlineData("mBq", RadioactivityUnit.Millibecquerel)] + [InlineData("mCi", RadioactivityUnit.Millicurie)] + [InlineData("mRd", RadioactivityUnit.Millirutherford)] + [InlineData("nBq", RadioactivityUnit.Nanobecquerel)] + [InlineData("nCi", RadioactivityUnit.Nanocurie)] + [InlineData("nRd", RadioactivityUnit.Nanorutherford)] + [InlineData("PBq", RadioactivityUnit.Petabecquerel)] + [InlineData("pBq", RadioactivityUnit.Picobecquerel)] + [InlineData("pCi", RadioactivityUnit.Picocurie)] + [InlineData("pRd", RadioactivityUnit.Picorutherford)] + [InlineData("Rd", RadioactivityUnit.Rutherford)] + [InlineData("TBq", RadioactivityUnit.Terabecquerel)] + [InlineData("TCi", RadioactivityUnit.Teracurie)] + [InlineData("TRd", RadioactivityUnit.Terarutherford)] + public void TryParseUnit(string abbreviation, RadioactivityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Radioactivity.TryParseUnit(abbreviation, out RadioactivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "Bq", RadioactivityUnit.Becquerel)] + [InlineData("en-US", "Ci", RadioactivityUnit.Curie)] + [InlineData("en-US", "EBq", RadioactivityUnit.Exabecquerel)] + [InlineData("en-US", "GBq", RadioactivityUnit.Gigabecquerel)] + [InlineData("en-US", "GCi", RadioactivityUnit.Gigacurie)] + [InlineData("en-US", "GRd", RadioactivityUnit.Gigarutherford)] + [InlineData("en-US", "kBq", RadioactivityUnit.Kilobecquerel)] + [InlineData("en-US", "kCi", RadioactivityUnit.Kilocurie)] + [InlineData("en-US", "kRd", RadioactivityUnit.Kilorutherford)] + [InlineData("en-US", "MBq", RadioactivityUnit.Megabecquerel)] + [InlineData("en-US", "MCi", RadioactivityUnit.Megacurie)] + [InlineData("en-US", "MRd", RadioactivityUnit.Megarutherford)] + [InlineData("en-US", "µBq", RadioactivityUnit.Microbecquerel)] + [InlineData("en-US", "µCi", RadioactivityUnit.Microcurie)] + [InlineData("en-US", "µRd", RadioactivityUnit.Microrutherford)] + [InlineData("en-US", "mBq", RadioactivityUnit.Millibecquerel)] + [InlineData("en-US", "mCi", RadioactivityUnit.Millicurie)] + [InlineData("en-US", "mRd", RadioactivityUnit.Millirutherford)] + [InlineData("en-US", "nBq", RadioactivityUnit.Nanobecquerel)] + [InlineData("en-US", "nCi", RadioactivityUnit.Nanocurie)] + [InlineData("en-US", "nRd", RadioactivityUnit.Nanorutherford)] + [InlineData("en-US", "PBq", RadioactivityUnit.Petabecquerel)] + [InlineData("en-US", "pBq", RadioactivityUnit.Picobecquerel)] + [InlineData("en-US", "pCi", RadioactivityUnit.Picocurie)] + [InlineData("en-US", "pRd", RadioactivityUnit.Picorutherford)] + [InlineData("en-US", "Rd", RadioactivityUnit.Rutherford)] + [InlineData("en-US", "TBq", RadioactivityUnit.Terabecquerel)] + [InlineData("en-US", "TCi", RadioactivityUnit.Teracurie)] + [InlineData("en-US", "TRd", RadioactivityUnit.Terarutherford)] + [InlineData("ru-RU", "Бк", RadioactivityUnit.Becquerel)] + [InlineData("ru-RU", "Ки", RadioactivityUnit.Curie)] + [InlineData("ru-RU", "ЭБк", RadioactivityUnit.Exabecquerel)] + [InlineData("ru-RU", "ГБк", RadioactivityUnit.Gigabecquerel)] + [InlineData("ru-RU", "ГКи", RadioactivityUnit.Gigacurie)] + [InlineData("ru-RU", "ГРд", RadioactivityUnit.Gigarutherford)] + [InlineData("ru-RU", "кБк", RadioactivityUnit.Kilobecquerel)] + [InlineData("ru-RU", "кКи", RadioactivityUnit.Kilocurie)] + [InlineData("ru-RU", "кРд", RadioactivityUnit.Kilorutherford)] + [InlineData("ru-RU", "МБк", RadioactivityUnit.Megabecquerel)] + [InlineData("ru-RU", "МКи", RadioactivityUnit.Megacurie)] + [InlineData("ru-RU", "МРд", RadioactivityUnit.Megarutherford)] + [InlineData("ru-RU", "мкБк", RadioactivityUnit.Microbecquerel)] + [InlineData("ru-RU", "мкКи", RadioactivityUnit.Microcurie)] + [InlineData("ru-RU", "мкРд", RadioactivityUnit.Microrutherford)] + [InlineData("ru-RU", "мБк", RadioactivityUnit.Millibecquerel)] + [InlineData("ru-RU", "мКи", RadioactivityUnit.Millicurie)] + [InlineData("ru-RU", "мРд", RadioactivityUnit.Millirutherford)] + [InlineData("ru-RU", "нБк", RadioactivityUnit.Nanobecquerel)] + [InlineData("ru-RU", "нКи", RadioactivityUnit.Nanocurie)] + [InlineData("ru-RU", "нРд", RadioactivityUnit.Nanorutherford)] + [InlineData("ru-RU", "ПБк", RadioactivityUnit.Petabecquerel)] + [InlineData("ru-RU", "пБк", RadioactivityUnit.Picobecquerel)] + [InlineData("ru-RU", "пКи", RadioactivityUnit.Picocurie)] + [InlineData("ru-RU", "пРд", RadioactivityUnit.Picorutherford)] + [InlineData("ru-RU", "Рд", RadioactivityUnit.Rutherford)] + [InlineData("ru-RU", "ТБк", RadioactivityUnit.Terabecquerel)] + [InlineData("ru-RU", "ТКи", RadioactivityUnit.Teracurie)] + [InlineData("ru-RU", "ТРд", RadioactivityUnit.Terarutherford)] + public void TryParseUnitWithCulture(string culture, string abbreviation, RadioactivityUnit expectedUnit) + { + Assert.True(Radioactivity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RadioactivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs index 7358d83fc4..8d19b404f6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs @@ -223,36 +223,42 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("/s", RatioChangeRateUnit.DecimalFractionPerSecond)] + [InlineData("%/s", RatioChangeRateUnit.PercentPerSecond)] + public void ParseUnit(string abbreviation, RatioChangeRateUnit expectedUnit) { - try - { - var parsedUnit = RatioChangeRate.ParseUnit("/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RatioChangeRateUnit.DecimalFractionPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RatioChangeRate.ParseUnit("%/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RatioChangeRateUnit.PercentPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + RatioChangeRateUnit parsedUnit = RatioChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "/s", RatioChangeRateUnit.DecimalFractionPerSecond)] + [InlineData("en-US", "%/s", RatioChangeRateUnit.PercentPerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, RatioChangeRateUnit expectedUnit) { - { - Assert.True(RatioChangeRate.TryParseUnit("/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RatioChangeRateUnit.DecimalFractionPerSecond, parsedUnit); - } + RatioChangeRateUnit parsedUnit = RatioChangeRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(RatioChangeRate.TryParseUnit("%/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RatioChangeRateUnit.PercentPerSecond, parsedUnit); - } + [Theory] + [InlineData("/s", RatioChangeRateUnit.DecimalFractionPerSecond)] + [InlineData("%/s", RatioChangeRateUnit.PercentPerSecond)] + public void TryParseUnit(string abbreviation, RatioChangeRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(RatioChangeRate.TryParseUnit(abbreviation, out RatioChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "/s", RatioChangeRateUnit.DecimalFractionPerSecond)] + [InlineData("en-US", "%/s", RatioChangeRateUnit.PercentPerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, RatioChangeRateUnit expectedUnit) + { + Assert.True(RatioChangeRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RatioChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs index 27b61e39ca..805a3cb5d0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs @@ -315,80 +315,58 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("", RatioUnit.DecimalFraction)] + [InlineData("ppb", RatioUnit.PartPerBillion)] + [InlineData("ppm", RatioUnit.PartPerMillion)] + [InlineData("‰", RatioUnit.PartPerThousand)] + [InlineData("ppt", RatioUnit.PartPerTrillion)] + [InlineData("%", RatioUnit.Percent)] + public void ParseUnit(string abbreviation, RatioUnit expectedUnit) { - try - { - var parsedUnit = Ratio.ParseUnit("", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RatioUnit.DecimalFraction, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Ratio.ParseUnit("ppb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RatioUnit.PartPerBillion, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Ratio.ParseUnit("ppm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RatioUnit.PartPerMillion, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Ratio.ParseUnit("‰", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RatioUnit.PartPerThousand, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Ratio.ParseUnit("ppt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RatioUnit.PartPerTrillion, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Ratio.ParseUnit("%", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RatioUnit.Percent, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + RatioUnit parsedUnit = Ratio.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "", RatioUnit.DecimalFraction)] + [InlineData("en-US", "ppb", RatioUnit.PartPerBillion)] + [InlineData("en-US", "ppm", RatioUnit.PartPerMillion)] + [InlineData("en-US", "‰", RatioUnit.PartPerThousand)] + [InlineData("en-US", "ppt", RatioUnit.PartPerTrillion)] + [InlineData("en-US", "%", RatioUnit.Percent)] + public void ParseUnitWithCulture(string culture, string abbreviation, RatioUnit expectedUnit) { - { - Assert.True(Ratio.TryParseUnit("", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RatioUnit.DecimalFraction, parsedUnit); - } - - { - Assert.True(Ratio.TryParseUnit("ppb", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RatioUnit.PartPerBillion, parsedUnit); - } - - { - Assert.True(Ratio.TryParseUnit("ppm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RatioUnit.PartPerMillion, parsedUnit); - } - - { - Assert.True(Ratio.TryParseUnit("‰", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RatioUnit.PartPerThousand, parsedUnit); - } - - { - Assert.True(Ratio.TryParseUnit("ppt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RatioUnit.PartPerTrillion, parsedUnit); - } + RatioUnit parsedUnit = Ratio.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Ratio.TryParseUnit("%", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RatioUnit.Percent, parsedUnit); - } + [Theory] + [InlineData("", RatioUnit.DecimalFraction)] + [InlineData("ppb", RatioUnit.PartPerBillion)] + [InlineData("ppm", RatioUnit.PartPerMillion)] + [InlineData("‰", RatioUnit.PartPerThousand)] + [InlineData("ppt", RatioUnit.PartPerTrillion)] + [InlineData("%", RatioUnit.Percent)] + public void TryParseUnit(string abbreviation, RatioUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Ratio.TryParseUnit(abbreviation, out RatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "", RatioUnit.DecimalFraction)] + [InlineData("en-US", "ppb", RatioUnit.PartPerBillion)] + [InlineData("en-US", "ppm", RatioUnit.PartPerMillion)] + [InlineData("en-US", "‰", RatioUnit.PartPerThousand)] + [InlineData("en-US", "ppt", RatioUnit.PartPerTrillion)] + [InlineData("en-US", "%", RatioUnit.Percent)] + public void TryParseUnitWithCulture(string culture, string abbreviation, RatioUnit expectedUnit) + { + Assert.True(Ratio.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs index be2c080f51..d1b37c0393 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs @@ -246,47 +246,46 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] + [InlineData("Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] + [InlineData("varh", ReactiveEnergyUnit.VoltampereReactiveHour)] + public void ParseUnit(string abbreviation, ReactiveEnergyUnit expectedUnit) { - try - { - var parsedUnit = ReactiveEnergy.ParseUnit("kvarh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReactiveEnergyUnit.KilovoltampereReactiveHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReactiveEnergy.ParseUnit("Mvarh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReactiveEnergyUnit.MegavoltampereReactiveHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReactiveEnergy.ParseUnit("varh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReactiveEnergyUnit.VoltampereReactiveHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ReactiveEnergyUnit parsedUnit = ReactiveEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] + [InlineData("en-US", "Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] + [InlineData("en-US", "varh", ReactiveEnergyUnit.VoltampereReactiveHour)] + public void ParseUnitWithCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) { - { - Assert.True(ReactiveEnergy.TryParseUnit("kvarh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReactiveEnergyUnit.KilovoltampereReactiveHour, parsedUnit); - } - - { - Assert.True(ReactiveEnergy.TryParseUnit("Mvarh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReactiveEnergyUnit.MegavoltampereReactiveHour, parsedUnit); - } + ReactiveEnergyUnit parsedUnit = ReactiveEnergy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ReactiveEnergy.TryParseUnit("varh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReactiveEnergyUnit.VoltampereReactiveHour, parsedUnit); - } + [Theory] + [InlineData("kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] + [InlineData("Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] + [InlineData("varh", ReactiveEnergyUnit.VoltampereReactiveHour)] + public void TryParseUnit(string abbreviation, ReactiveEnergyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ReactiveEnergy.TryParseUnit(abbreviation, out ReactiveEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] + [InlineData("en-US", "Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] + [InlineData("en-US", "varh", ReactiveEnergyUnit.VoltampereReactiveHour)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) + { + Assert.True(ReactiveEnergy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ReactiveEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs index d80cf6c21e..667e941bc1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs @@ -269,58 +269,50 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("Gvar", ReactivePowerUnit.GigavoltampereReactive)] + [InlineData("kvar", ReactivePowerUnit.KilovoltampereReactive)] + [InlineData("Mvar", ReactivePowerUnit.MegavoltampereReactive)] + [InlineData("var", ReactivePowerUnit.VoltampereReactive)] + public void ParseUnit(string abbreviation, ReactivePowerUnit expectedUnit) { - try - { - var parsedUnit = ReactivePower.ParseUnit("Gvar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReactivePowerUnit.GigavoltampereReactive, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReactivePower.ParseUnit("kvar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReactivePowerUnit.KilovoltampereReactive, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReactivePower.ParseUnit("Mvar", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReactivePowerUnit.MegavoltampereReactive, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReactivePower.ParseUnit("var", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReactivePowerUnit.VoltampereReactive, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ReactivePowerUnit parsedUnit = ReactivePower.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "Gvar", ReactivePowerUnit.GigavoltampereReactive)] + [InlineData("en-US", "kvar", ReactivePowerUnit.KilovoltampereReactive)] + [InlineData("en-US", "Mvar", ReactivePowerUnit.MegavoltampereReactive)] + [InlineData("en-US", "var", ReactivePowerUnit.VoltampereReactive)] + public void ParseUnitWithCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) { - { - Assert.True(ReactivePower.TryParseUnit("Gvar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReactivePowerUnit.GigavoltampereReactive, parsedUnit); - } - - { - Assert.True(ReactivePower.TryParseUnit("kvar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReactivePowerUnit.KilovoltampereReactive, parsedUnit); - } - - { - Assert.True(ReactivePower.TryParseUnit("Mvar", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReactivePowerUnit.MegavoltampereReactive, parsedUnit); - } + ReactivePowerUnit parsedUnit = ReactivePower.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ReactivePower.TryParseUnit("var", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReactivePowerUnit.VoltampereReactive, parsedUnit); - } + [Theory] + [InlineData("Gvar", ReactivePowerUnit.GigavoltampereReactive)] + [InlineData("kvar", ReactivePowerUnit.KilovoltampereReactive)] + [InlineData("Mvar", ReactivePowerUnit.MegavoltampereReactive)] + [InlineData("var", ReactivePowerUnit.VoltampereReactive)] + public void TryParseUnit(string abbreviation, ReactivePowerUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ReactivePower.TryParseUnit(abbreviation, out ReactivePowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "Gvar", ReactivePowerUnit.GigavoltampereReactive)] + [InlineData("en-US", "kvar", ReactivePowerUnit.KilovoltampereReactive)] + [InlineData("en-US", "Mvar", ReactivePowerUnit.MegavoltampereReactive)] + [InlineData("en-US", "var", ReactivePowerUnit.VoltampereReactive)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) + { + Assert.True(ReactivePower.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ReactivePowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs index 2ec2be8b40..40540610c6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs @@ -430,135 +430,78 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = ReciprocalArea.ParseUnit("cm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalAreaUnit.InverseSquareCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalArea.ParseUnit("dm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalAreaUnit.InverseSquareDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalArea.ParseUnit("ft⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalAreaUnit.InverseSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalArea.ParseUnit("in⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalAreaUnit.InverseSquareInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalArea.ParseUnit("km⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalAreaUnit.InverseSquareKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalArea.ParseUnit("m⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalArea.ParseUnit("µm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMicrometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalArea.ParseUnit("mi⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalArea.ParseUnit("mm⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalArea.ParseUnit("yd⁻²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalAreaUnit.InverseSquareYard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalArea.ParseUnit("ft⁻² (US)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalAreaUnit.InverseUsSurveySquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cm⁻²", ReciprocalAreaUnit.InverseSquareCentimeter)] + [InlineData("dm⁻²", ReciprocalAreaUnit.InverseSquareDecimeter)] + [InlineData("ft⁻²", ReciprocalAreaUnit.InverseSquareFoot)] + [InlineData("in⁻²", ReciprocalAreaUnit.InverseSquareInch)] + [InlineData("km⁻²", ReciprocalAreaUnit.InverseSquareKilometer)] + [InlineData("m⁻²", ReciprocalAreaUnit.InverseSquareMeter)] + [InlineData("µm⁻²", ReciprocalAreaUnit.InverseSquareMicrometer)] + [InlineData("mi⁻²", ReciprocalAreaUnit.InverseSquareMile)] + [InlineData("mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] + [InlineData("yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] + [InlineData("ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] + public void ParseUnit(string abbreviation, ReciprocalAreaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ReciprocalAreaUnit parsedUnit = ReciprocalArea.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(ReciprocalArea.TryParseUnit("cm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalAreaUnit.InverseSquareCentimeter, parsedUnit); - } - - { - Assert.True(ReciprocalArea.TryParseUnit("dm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalAreaUnit.InverseSquareDecimeter, parsedUnit); - } - - { - Assert.True(ReciprocalArea.TryParseUnit("ft⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalAreaUnit.InverseSquareFoot, parsedUnit); - } - - { - Assert.True(ReciprocalArea.TryParseUnit("in⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalAreaUnit.InverseSquareInch, parsedUnit); - } - - { - Assert.True(ReciprocalArea.TryParseUnit("km⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalAreaUnit.InverseSquareKilometer, parsedUnit); - } - - { - Assert.True(ReciprocalArea.TryParseUnit("m⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMeter, parsedUnit); - } - - { - Assert.True(ReciprocalArea.TryParseUnit("µm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMicrometer, parsedUnit); - } - - { - Assert.True(ReciprocalArea.TryParseUnit("mi⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMile, parsedUnit); - } - - { - Assert.True(ReciprocalArea.TryParseUnit("mm⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalAreaUnit.InverseSquareMillimeter, parsedUnit); - } - - { - Assert.True(ReciprocalArea.TryParseUnit("yd⁻²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalAreaUnit.InverseSquareYard, parsedUnit); - } + [Theory] + [InlineData("en-US", "cm⁻²", ReciprocalAreaUnit.InverseSquareCentimeter)] + [InlineData("en-US", "dm⁻²", ReciprocalAreaUnit.InverseSquareDecimeter)] + [InlineData("en-US", "ft⁻²", ReciprocalAreaUnit.InverseSquareFoot)] + [InlineData("en-US", "in⁻²", ReciprocalAreaUnit.InverseSquareInch)] + [InlineData("en-US", "km⁻²", ReciprocalAreaUnit.InverseSquareKilometer)] + [InlineData("en-US", "m⁻²", ReciprocalAreaUnit.InverseSquareMeter)] + [InlineData("en-US", "µm⁻²", ReciprocalAreaUnit.InverseSquareMicrometer)] + [InlineData("en-US", "mi⁻²", ReciprocalAreaUnit.InverseSquareMile)] + [InlineData("en-US", "mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] + [InlineData("en-US", "yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] + [InlineData("en-US", "ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] + public void ParseUnitWithCulture(string culture, string abbreviation, ReciprocalAreaUnit expectedUnit) + { + ReciprocalAreaUnit parsedUnit = ReciprocalArea.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ReciprocalArea.TryParseUnit("ft⁻² (US)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalAreaUnit.InverseUsSurveySquareFoot, parsedUnit); - } + [Theory] + [InlineData("cm⁻²", ReciprocalAreaUnit.InverseSquareCentimeter)] + [InlineData("dm⁻²", ReciprocalAreaUnit.InverseSquareDecimeter)] + [InlineData("ft⁻²", ReciprocalAreaUnit.InverseSquareFoot)] + [InlineData("in⁻²", ReciprocalAreaUnit.InverseSquareInch)] + [InlineData("km⁻²", ReciprocalAreaUnit.InverseSquareKilometer)] + [InlineData("m⁻²", ReciprocalAreaUnit.InverseSquareMeter)] + [InlineData("µm⁻²", ReciprocalAreaUnit.InverseSquareMicrometer)] + [InlineData("mi⁻²", ReciprocalAreaUnit.InverseSquareMile)] + [InlineData("mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] + [InlineData("yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] + [InlineData("ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] + public void TryParseUnit(string abbreviation, ReciprocalAreaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ReciprocalArea.TryParseUnit(abbreviation, out ReciprocalAreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cm⁻²", ReciprocalAreaUnit.InverseSquareCentimeter)] + [InlineData("en-US", "dm⁻²", ReciprocalAreaUnit.InverseSquareDecimeter)] + [InlineData("en-US", "ft⁻²", ReciprocalAreaUnit.InverseSquareFoot)] + [InlineData("en-US", "in⁻²", ReciprocalAreaUnit.InverseSquareInch)] + [InlineData("en-US", "km⁻²", ReciprocalAreaUnit.InverseSquareKilometer)] + [InlineData("en-US", "m⁻²", ReciprocalAreaUnit.InverseSquareMeter)] + [InlineData("en-US", "µm⁻²", ReciprocalAreaUnit.InverseSquareMicrometer)] + [InlineData("en-US", "mi⁻²", ReciprocalAreaUnit.InverseSquareMile)] + [InlineData("en-US", "mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] + [InlineData("en-US", "yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] + [InlineData("en-US", "ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ReciprocalAreaUnit expectedUnit) + { + Assert.True(ReciprocalArea.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ReciprocalAreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs index 05c77e6c60..7d78a86264 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs @@ -537,234 +537,114 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = ReciprocalLength.ParseUnit("cm⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("1/cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("ft⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("1/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("in⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("1/in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("m⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("1/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("µin⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("1/µin", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("mil⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseMil, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("1/mil", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseMil, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("mi⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("1/mi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("mm⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("1/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("ftUS⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("1/ftUS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("yd⁻¹", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseYard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ReciprocalLength.ParseUnit("1/yd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ReciprocalLengthUnit.InverseYard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cm⁻¹", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("1/cm", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("ft⁻¹", ReciprocalLengthUnit.InverseFoot)] + [InlineData("1/ft", ReciprocalLengthUnit.InverseFoot)] + [InlineData("in⁻¹", ReciprocalLengthUnit.InverseInch)] + [InlineData("1/in", ReciprocalLengthUnit.InverseInch)] + [InlineData("m⁻¹", ReciprocalLengthUnit.InverseMeter)] + [InlineData("1/m", ReciprocalLengthUnit.InverseMeter)] + [InlineData("µin⁻¹", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("1/µin", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("mil⁻¹", ReciprocalLengthUnit.InverseMil)] + [InlineData("1/mil", ReciprocalLengthUnit.InverseMil)] + [InlineData("mi⁻¹", ReciprocalLengthUnit.InverseMile)] + [InlineData("1/mi", ReciprocalLengthUnit.InverseMile)] + [InlineData("mm⁻¹", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("1/mm", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("ftUS⁻¹", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("yd⁻¹", ReciprocalLengthUnit.InverseYard)] + [InlineData("1/yd", ReciprocalLengthUnit.InverseYard)] + public void ParseUnit(string abbreviation, ReciprocalLengthUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ReciprocalLengthUnit parsedUnit = ReciprocalLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(ReciprocalLength.TryParseUnit("cm⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("1/cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseCentimeter, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("ft⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseFoot, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("1/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseFoot, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("in⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseInch, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("1/in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseInch, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("m⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseMeter, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("1/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseMeter, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("µin⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("1/µin", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseMicroinch, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("mil⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseMil, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("1/mil", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseMil, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("mi⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseMile, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("1/mi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseMile, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("mm⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("1/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseMillimeter, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("ftUS⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("1/ftUS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseUsSurveyFoot, parsedUnit); - } - - { - Assert.True(ReciprocalLength.TryParseUnit("yd⁻¹", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseYard, parsedUnit); - } + [Theory] + [InlineData("en-US", "cm⁻¹", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("en-US", "1/cm", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("en-US", "ft⁻¹", ReciprocalLengthUnit.InverseFoot)] + [InlineData("en-US", "1/ft", ReciprocalLengthUnit.InverseFoot)] + [InlineData("en-US", "in⁻¹", ReciprocalLengthUnit.InverseInch)] + [InlineData("en-US", "1/in", ReciprocalLengthUnit.InverseInch)] + [InlineData("en-US", "m⁻¹", ReciprocalLengthUnit.InverseMeter)] + [InlineData("en-US", "1/m", ReciprocalLengthUnit.InverseMeter)] + [InlineData("en-US", "µin⁻¹", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("en-US", "1/µin", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("en-US", "mil⁻¹", ReciprocalLengthUnit.InverseMil)] + [InlineData("en-US", "1/mil", ReciprocalLengthUnit.InverseMil)] + [InlineData("en-US", "mi⁻¹", ReciprocalLengthUnit.InverseMile)] + [InlineData("en-US", "1/mi", ReciprocalLengthUnit.InverseMile)] + [InlineData("en-US", "mm⁻¹", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("en-US", "1/mm", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("en-US", "ftUS⁻¹", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("en-US", "1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("en-US", "yd⁻¹", ReciprocalLengthUnit.InverseYard)] + [InlineData("en-US", "1/yd", ReciprocalLengthUnit.InverseYard)] + public void ParseUnitWithCulture(string culture, string abbreviation, ReciprocalLengthUnit expectedUnit) + { + ReciprocalLengthUnit parsedUnit = ReciprocalLength.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ReciprocalLength.TryParseUnit("1/yd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ReciprocalLengthUnit.InverseYard, parsedUnit); - } + [Theory] + [InlineData("cm⁻¹", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("1/cm", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("ft⁻¹", ReciprocalLengthUnit.InverseFoot)] + [InlineData("1/ft", ReciprocalLengthUnit.InverseFoot)] + [InlineData("in⁻¹", ReciprocalLengthUnit.InverseInch)] + [InlineData("1/in", ReciprocalLengthUnit.InverseInch)] + [InlineData("m⁻¹", ReciprocalLengthUnit.InverseMeter)] + [InlineData("1/m", ReciprocalLengthUnit.InverseMeter)] + [InlineData("µin⁻¹", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("1/µin", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("mil⁻¹", ReciprocalLengthUnit.InverseMil)] + [InlineData("1/mil", ReciprocalLengthUnit.InverseMil)] + [InlineData("mi⁻¹", ReciprocalLengthUnit.InverseMile)] + [InlineData("1/mi", ReciprocalLengthUnit.InverseMile)] + [InlineData("mm⁻¹", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("1/mm", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("ftUS⁻¹", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("yd⁻¹", ReciprocalLengthUnit.InverseYard)] + [InlineData("1/yd", ReciprocalLengthUnit.InverseYard)] + public void TryParseUnit(string abbreviation, ReciprocalLengthUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ReciprocalLength.TryParseUnit(abbreviation, out ReciprocalLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cm⁻¹", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("en-US", "1/cm", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("en-US", "ft⁻¹", ReciprocalLengthUnit.InverseFoot)] + [InlineData("en-US", "1/ft", ReciprocalLengthUnit.InverseFoot)] + [InlineData("en-US", "in⁻¹", ReciprocalLengthUnit.InverseInch)] + [InlineData("en-US", "1/in", ReciprocalLengthUnit.InverseInch)] + [InlineData("en-US", "m⁻¹", ReciprocalLengthUnit.InverseMeter)] + [InlineData("en-US", "1/m", ReciprocalLengthUnit.InverseMeter)] + [InlineData("en-US", "µin⁻¹", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("en-US", "1/µin", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("en-US", "mil⁻¹", ReciprocalLengthUnit.InverseMil)] + [InlineData("en-US", "1/mil", ReciprocalLengthUnit.InverseMil)] + [InlineData("en-US", "mi⁻¹", ReciprocalLengthUnit.InverseMile)] + [InlineData("en-US", "1/mi", ReciprocalLengthUnit.InverseMile)] + [InlineData("en-US", "mm⁻¹", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("en-US", "1/mm", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("en-US", "ftUS⁻¹", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("en-US", "1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("en-US", "yd⁻¹", ReciprocalLengthUnit.InverseYard)] + [InlineData("en-US", "1/yd", ReciprocalLengthUnit.InverseYard)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ReciprocalLengthUnit expectedUnit) + { + Assert.True(ReciprocalLength.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ReciprocalLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs index 9770a3da60..84732905bc 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("%RH", RelativeHumidityUnit.Percent)] + public void ParseUnit(string abbreviation, RelativeHumidityUnit expectedUnit) { - try - { - var parsedUnit = RelativeHumidity.ParseUnit("%RH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RelativeHumidityUnit.Percent, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + RelativeHumidityUnit parsedUnit = RelativeHumidity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "%RH", RelativeHumidityUnit.Percent)] + public void ParseUnitWithCulture(string culture, string abbreviation, RelativeHumidityUnit expectedUnit) + { + RelativeHumidityUnit parsedUnit = RelativeHumidity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("%RH", RelativeHumidityUnit.Percent)] + public void TryParseUnit(string abbreviation, RelativeHumidityUnit expectedUnit) { - { - Assert.True(RelativeHumidity.TryParseUnit("%RH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RelativeHumidityUnit.Percent, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(RelativeHumidity.TryParseUnit(abbreviation, out RelativeHumidityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "%RH", RelativeHumidityUnit.Percent)] + public void TryParseUnitWithCulture(string culture, string abbreviation, RelativeHumidityUnit expectedUnit) + { + Assert.True(RelativeHumidity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RelativeHumidityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs index 63853e9a90..be6348c482 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs @@ -282,69 +282,54 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("°/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("deg/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] + [InlineData("rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] + [InlineData("r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] + public void ParseUnit(string abbreviation, RotationalAccelerationUnit expectedUnit) { - try - { - var parsedUnit = RotationalAcceleration.ParseUnit("°/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalAccelerationUnit.DegreePerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalAcceleration.ParseUnit("deg/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalAccelerationUnit.DegreePerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalAcceleration.ParseUnit("rad/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalAccelerationUnit.RadianPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalAcceleration.ParseUnit("rpm/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalAccelerationUnit.RevolutionPerMinutePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalAcceleration.ParseUnit("r/s²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalAccelerationUnit.RevolutionPerSecondSquared, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + RotationalAccelerationUnit parsedUnit = RotationalAcceleration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "°/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("en-US", "deg/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("en-US", "rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] + [InlineData("en-US", "rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] + [InlineData("en-US", "r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] + public void ParseUnitWithCulture(string culture, string abbreviation, RotationalAccelerationUnit expectedUnit) { - { - Assert.True(RotationalAcceleration.TryParseUnit("°/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalAccelerationUnit.DegreePerSecondSquared, parsedUnit); - } - - { - Assert.True(RotationalAcceleration.TryParseUnit("deg/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalAccelerationUnit.DegreePerSecondSquared, parsedUnit); - } - - { - Assert.True(RotationalAcceleration.TryParseUnit("rad/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalAccelerationUnit.RadianPerSecondSquared, parsedUnit); - } - - { - Assert.True(RotationalAcceleration.TryParseUnit("rpm/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalAccelerationUnit.RevolutionPerMinutePerSecond, parsedUnit); - } + RotationalAccelerationUnit parsedUnit = RotationalAcceleration.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(RotationalAcceleration.TryParseUnit("r/s²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalAccelerationUnit.RevolutionPerSecondSquared, parsedUnit); - } + [Theory] + [InlineData("°/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("deg/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] + [InlineData("rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] + [InlineData("r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] + public void TryParseUnit(string abbreviation, RotationalAccelerationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(RotationalAcceleration.TryParseUnit(abbreviation, out RotationalAccelerationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "°/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("en-US", "deg/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("en-US", "rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] + [InlineData("en-US", "rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] + [InlineData("en-US", "r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] + public void TryParseUnitWithCulture(string culture, string abbreviation, RotationalAccelerationUnit expectedUnit) + { + Assert.True(RotationalAcceleration.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RotationalAccelerationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs index 1c0cde6889..398a81aead 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs @@ -710,355 +710,134 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = RotationalSpeed.ParseUnit("crad/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.CentiradianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("срад/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.CentiradianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("drad/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.DeciradianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("драд/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.DeciradianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("°/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.DegreePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("deg/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.DegreePerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("°/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("deg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("°/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("µ°/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("µdeg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("мк°/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("µrad/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.MicroradianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("мкрад/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.MicroradianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("m°/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("mdeg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("м°/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("mrad/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.MilliradianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("мрад/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.MilliradianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("n°/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("ndeg/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("н°/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("nrad/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.NanoradianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("нрад/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.NanoradianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("rad/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.RadianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("рад/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.RadianPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("rpm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("r/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("об/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("r/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalSpeedUnit.RevolutionPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalSpeed.ParseUnit("об/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(RotationalSpeedUnit.RevolutionPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("crad/s", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("drad/s", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("°/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("deg/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("°/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("deg/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("µ°/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("µdeg/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("µrad/s", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("m°/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("mdeg/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("mrad/s", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("n°/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("ndeg/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("nrad/s", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("rad/s", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("rpm", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("r/min", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("r/s", RotationalSpeedUnit.RevolutionPerSecond)] + public void ParseUnit(string abbreviation, RotationalSpeedUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + RotationalSpeedUnit parsedUnit = RotationalSpeed.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(RotationalSpeed.TryParseUnit("crad/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.CentiradianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("срад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.CentiradianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("drad/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.DeciradianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("драд/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.DeciradianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("°/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.DegreePerMinute, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("deg/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.DegreePerMinute, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("°/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("deg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("°/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.DegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("µ°/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("µdeg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("мк°/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.MicrodegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("µrad/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.MicroradianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("мкрад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.MicroradianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("m°/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("mdeg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("м°/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.MillidegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("mrad/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.MilliradianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("мрад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.MilliradianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("n°/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("ndeg/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("н°/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.NanodegreePerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("nrad/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.NanoradianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("нрад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.NanoradianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("rad/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.RadianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("рад/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.RadianPerSecond, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("rpm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("r/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("об/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.RevolutionPerMinute, parsedUnit); - } - - { - Assert.True(RotationalSpeed.TryParseUnit("r/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.RevolutionPerSecond, parsedUnit); - } + [Theory] + [InlineData("en-US", "crad/s", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("en-US", "drad/s", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("en-US", "°/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("en-US", "deg/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("en-US", "°/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("en-US", "deg/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("en-US", "µ°/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("en-US", "µdeg/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("en-US", "µrad/s", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("en-US", "m°/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("en-US", "mdeg/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("en-US", "mrad/s", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("en-US", "n°/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("en-US", "ndeg/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("en-US", "nrad/s", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("en-US", "rad/s", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("en-US", "rpm", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("en-US", "r/min", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("en-US", "r/s", RotationalSpeedUnit.RevolutionPerSecond)] + [InlineData("ru-RU", "срад/с", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("ru-RU", "драд/с", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("ru-RU", "°/с", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("ru-RU", "мк°/с", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("ru-RU", "мкрад/с", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("ru-RU", "м°/с", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("ru-RU", "мрад/с", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("ru-RU", "н°/с", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("ru-RU", "нрад/с", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("ru-RU", "рад/с", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("ru-RU", "об/мин", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("ru-RU", "об/с", RotationalSpeedUnit.RevolutionPerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, RotationalSpeedUnit expectedUnit) + { + RotationalSpeedUnit parsedUnit = RotationalSpeed.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(RotationalSpeed.TryParseUnit("об/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(RotationalSpeedUnit.RevolutionPerSecond, parsedUnit); - } + [Theory] + [InlineData("crad/s", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("drad/s", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("°/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("deg/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("°/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("deg/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("µ°/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("µdeg/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("µrad/s", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("m°/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("mdeg/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("mrad/s", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("n°/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("ndeg/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("nrad/s", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("rad/s", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("rpm", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("r/min", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("r/s", RotationalSpeedUnit.RevolutionPerSecond)] + public void TryParseUnit(string abbreviation, RotationalSpeedUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(RotationalSpeed.TryParseUnit(abbreviation, out RotationalSpeedUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "crad/s", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("en-US", "drad/s", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("en-US", "°/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("en-US", "deg/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("en-US", "°/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("en-US", "deg/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("en-US", "µ°/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("en-US", "µdeg/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("en-US", "µrad/s", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("en-US", "m°/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("en-US", "mdeg/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("en-US", "mrad/s", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("en-US", "n°/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("en-US", "ndeg/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("en-US", "nrad/s", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("en-US", "rad/s", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("en-US", "rpm", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("en-US", "r/min", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("en-US", "r/s", RotationalSpeedUnit.RevolutionPerSecond)] + [InlineData("ru-RU", "срад/с", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("ru-RU", "драд/с", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("ru-RU", "°/с", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("ru-RU", "мк°/с", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("ru-RU", "мкрад/с", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("ru-RU", "м°/с", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("ru-RU", "мрад/с", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("ru-RU", "н°/с", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("ru-RU", "нрад/с", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("ru-RU", "рад/с", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("ru-RU", "об/мин", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("ru-RU", "об/с", RotationalSpeedUnit.RevolutionPerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, RotationalSpeedUnit expectedUnit) + { + Assert.True(RotationalSpeed.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RotationalSpeedUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs index b9149031fb..feb5b06327 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs @@ -396,157 +396,86 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("kN·m/rad/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("kNm/rad/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("kipf·ft/°/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("kip·ft/°/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("k·ft/°/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("kipf·ft/deg/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("kip·ft/deg/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("k·ft/deg/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("MN·m/rad/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("MNm/rad/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("N·m/rad/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("Nm/rad/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffnessPerLength.ParseUnit("lbf·ft/deg/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("kN·m/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("kNm/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("kipf·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kip·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("k·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kipf·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kip·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("k·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("MN·m/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("MNm/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] + public void ParseUnit(string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + RotationalStiffnessPerLengthUnit parsedUnit = RotationalStiffnessPerLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("kN·m/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, parsedUnit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("kNm/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter, parsedUnit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("kipf·ft/°/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("kip·ft/°/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("k·ft/°/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("kipf·ft/deg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("kip·ft/deg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("k·ft/deg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot, parsedUnit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("MN·m/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, parsedUnit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("MNm/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter, parsedUnit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("N·m/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, parsedUnit); - } - - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("Nm/rad/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "kN·m/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "kNm/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "kipf·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kip·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "k·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kipf·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kip·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "k·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "MN·m/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "MNm/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] + public void ParseUnitWithCulture(string culture, string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + { + RotationalStiffnessPerLengthUnit parsedUnit = RotationalStiffnessPerLength.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(RotationalStiffnessPerLength.TryParseUnit("lbf·ft/deg/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot, parsedUnit); - } + [Theory] + [InlineData("kN·m/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("kNm/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("kipf·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kip·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("k·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kipf·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kip·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("k·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("MN·m/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("MNm/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] + public void TryParseUnit(string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(RotationalStiffnessPerLength.TryParseUnit(abbreviation, out RotationalStiffnessPerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kN·m/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "kNm/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "kipf·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kip·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "k·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kipf·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kip·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "k·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "MN·m/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "MNm/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] + public void TryParseUnitWithCulture(string culture, string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + { + Assert.True(RotationalStiffnessPerLength.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RotationalStiffnessPerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs index e0294fc5fe..d111880091 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs @@ -1739,1058 +1739,450 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = RotationalStiffness.ParseUnit("cN·m/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("cNm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("cN·m/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("cNm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("cN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("cNmm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("cN·mm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("cNmm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("cN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("cNmm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("daN·m/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("daNm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("daN·m/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("daNm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("daN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("daNmm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("daN·mm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("daNmm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("daN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("daNmm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("dN·m/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("dNm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("dN·m/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("dNm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("dN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("dNmm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("dN·mm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("dNmm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("dN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("dNmm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kN·m/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kNm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kN·m/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kNm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kN·m/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kNm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kNmm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kN·mm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kNmm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kNmm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kipf·ft/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kip·ft/°g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("k·ft/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kipf·ft/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("kip·ft/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("k·ft/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MN·m/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MNm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MN·m/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MNm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MN·m/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MNm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MNmm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MN·mm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MNmm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("MNmm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("µN·m/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("µNm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("µN·m/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("µNm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("µN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("µNmm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("µN·mm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("µNmm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("µN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("µNmm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("mN·m/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("mNm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("mN·m/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("mNm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("mN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("mNmm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("mN·mm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("mNmm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("mN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("mNmm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.MillinewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("nN·m/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("nNm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("nN·m/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("nNm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("nN·mm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("nNmm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("nN·mm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("nNmm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("nN·mm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("nNmm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("N·m/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("Nm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("N·m/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("Nm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("N·m/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("Nm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("N·mm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("Nmm/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("N·mm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("Nmm/°", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("N·mm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("Nmm/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("lbf·ft/rad", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.PoundForceFeetPerRadian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = RotationalStiffness.ParseUnit("lbf·ft/deg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(RotationalStiffnessUnit.PoundForceFootPerDegrees, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParseUnit() - { - { - Assert.True(RotationalStiffness.TryParseUnit("cN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("cNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("cN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("cNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("cN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("cNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("cN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("cNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("cN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("cNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.CentinewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("daN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("daNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("daN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("daNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("daN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("daNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("daN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("daNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("daN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("daNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecanewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("dN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("dNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("dN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("dNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("dN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("dNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("dN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("dNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("dN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("dNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.DecinewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kN·m/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kNm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilonewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kipf·ft/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kip·ft/°g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("k·ft/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kipf·ft/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("kip·ft/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("k·ft/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.KilopoundForceFootPerDegrees, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("MN·m/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("MNm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MeganewtonMeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("µN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("µNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("µN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("µNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("µN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("µNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("µN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("µNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("µN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("µNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.MicronewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("nN·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("nNm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("nN·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("nNm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("nN·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("nNmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("nN·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("nNmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("nN·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("nNmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NanonewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("N·m/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("Nm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("N·m/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("Nm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("N·m/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("Nm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("N·mm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("Nmm/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("N·mm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("Nmm/°", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerDegree, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("N·mm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerRadian, parsedUnit); - } - - { - Assert.True(RotationalStiffness.TryParseUnit("Nmm/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.NewtonMillimeterPerRadian, parsedUnit); - } + [Theory] + [InlineData("cN·m/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cNm/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cN·m/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cNm/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cN·mm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cNmm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cN·mm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cNmm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cN·mm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("cNmm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("daN·m/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daNm/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daN·m/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daNm/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daN·mm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daNmm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daN·mm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daNmm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daN·mm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("daNmm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("dN·m/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dNm/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dN·m/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dNm/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dN·mm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dNmm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dN·mm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dNmm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dN·mm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("dNmm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("kN·m/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kNm/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kN·m/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kNm/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kN·m/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("kNm/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("kN·mm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kNmm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kN·mm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kNmm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kN·mm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("kNmm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("kipf·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kip·ft/°g", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("k·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kipf·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kip·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("k·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("MN·m/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MNm/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MN·m/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MNm/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MN·m/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("MNm/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("MN·mm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MNmm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MN·mm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MNmm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MN·mm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("MNmm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("µN·m/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µNm/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µN·m/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µNm/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µN·mm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µNmm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µN·mm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µNmm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µN·mm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("µNmm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("mN·m/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mNm/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mN·m/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mNm/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mN·mm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mNmm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mN·mm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mNmm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mN·mm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("mNmm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("nN·m/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nNm/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nN·m/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nNm/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nN·mm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nNmm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nN·mm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nNmm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nN·mm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("nNmm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("N·m/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("Nm/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("N·m/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("Nm/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("N·m/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("Nm/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("N·mm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("Nmm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("N·mm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("Nmm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("N·mm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] + [InlineData("lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] + public void ParseUnit(string abbreviation, RotationalStiffnessUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + RotationalStiffnessUnit parsedUnit = RotationalStiffness.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(RotationalStiffness.TryParseUnit("lbf·ft/rad", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.PoundForceFeetPerRadian, parsedUnit); - } + [Theory] + [InlineData("en-US", "cN·m/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cNm/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cN·m/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cNm/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cN·mm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cNmm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cN·mm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cNmm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cN·mm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("en-US", "cNmm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("en-US", "daN·m/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daNm/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daN·m/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daNm/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daN·mm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daNmm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daN·mm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daNmm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daN·mm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("en-US", "daNmm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("en-US", "dN·m/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dNm/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dN·m/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dNm/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dN·mm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dNmm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dN·mm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dNmm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dN·mm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("en-US", "dNmm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("en-US", "kN·m/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kNm/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kN·m/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kNm/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kN·m/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("en-US", "kNm/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("en-US", "kN·mm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kNmm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kN·mm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kNmm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kN·mm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("en-US", "kNmm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("en-US", "kipf·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kip·ft/°g", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "k·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kipf·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kip·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "k·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "MN·m/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MNm/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MN·m/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MNm/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MN·m/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("en-US", "MNm/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("en-US", "MN·mm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MNmm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MN·mm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MNmm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MN·mm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("en-US", "MNmm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("en-US", "µN·m/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µNm/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µN·m/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µNm/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µN·mm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µNmm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µN·mm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µNmm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µN·mm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("en-US", "µNmm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("en-US", "mN·m/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mNm/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mN·m/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mNm/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mN·mm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mNmm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mN·mm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mNmm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mN·mm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("en-US", "mNmm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("en-US", "nN·m/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nNm/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nN·m/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nNm/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nN·mm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nNmm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nN·mm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nNmm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nN·mm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("en-US", "nNmm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("en-US", "N·m/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "Nm/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "N·m/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "Nm/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "N·m/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("en-US", "Nm/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("en-US", "N·mm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "Nmm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "N·mm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "Nmm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "N·mm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("en-US", "Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("en-US", "lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] + [InlineData("en-US", "lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] + public void ParseUnitWithCulture(string culture, string abbreviation, RotationalStiffnessUnit expectedUnit) + { + RotationalStiffnessUnit parsedUnit = RotationalStiffness.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(RotationalStiffness.TryParseUnit("lbf·ft/deg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(RotationalStiffnessUnit.PoundForceFootPerDegrees, parsedUnit); - } + [Theory] + [InlineData("cN·m/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cNm/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cN·m/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cNm/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cN·mm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cNmm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cN·mm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cNmm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cN·mm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("cNmm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("daN·m/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daNm/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daN·m/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daNm/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daN·mm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daNmm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daN·mm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daNmm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daN·mm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("daNmm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("dN·m/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dNm/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dN·m/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dNm/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dN·mm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dNmm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dN·mm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dNmm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dN·mm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("dNmm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("kN·m/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kNm/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kN·m/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kNm/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kN·m/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("kNm/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("kN·mm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kNmm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kN·mm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kNmm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kN·mm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("kNmm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("kipf·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kip·ft/°g", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("k·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kipf·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kip·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("k·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("MN·m/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MNm/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MN·m/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MNm/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MN·m/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("MNm/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("MN·mm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MNmm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MN·mm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MNmm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MN·mm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("MNmm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("µN·m/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µNm/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µN·m/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µNm/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µN·mm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µNmm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µN·mm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µNmm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µN·mm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("µNmm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("mN·m/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mNm/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mN·m/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mNm/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mN·mm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mNmm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mN·mm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mNmm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mN·mm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("mNmm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("nN·m/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nNm/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nN·m/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nNm/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nN·mm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nNmm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nN·mm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nNmm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nN·mm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("nNmm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("N·m/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("Nm/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("N·m/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("Nm/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("N·m/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("Nm/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("N·mm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("Nmm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("N·mm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("Nmm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("N·mm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] + [InlineData("lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] + public void TryParseUnit(string abbreviation, RotationalStiffnessUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(RotationalStiffness.TryParseUnit(abbreviation, out RotationalStiffnessUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cN·m/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cNm/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cN·m/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cNm/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cN·mm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cNmm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cN·mm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cNmm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cN·mm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("en-US", "cNmm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("en-US", "daN·m/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daNm/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daN·m/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daNm/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daN·mm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daNmm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daN·mm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daNmm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daN·mm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("en-US", "daNmm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("en-US", "dN·m/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dNm/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dN·m/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dNm/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dN·mm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dNmm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dN·mm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dNmm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dN·mm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("en-US", "dNmm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("en-US", "kN·m/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kNm/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kN·m/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kNm/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kN·m/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("en-US", "kNm/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("en-US", "kN·mm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kNmm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kN·mm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kNmm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kN·mm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("en-US", "kNmm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("en-US", "kipf·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kip·ft/°g", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "k·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kipf·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kip·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "k·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "MN·m/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MNm/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MN·m/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MNm/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MN·m/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("en-US", "MNm/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("en-US", "MN·mm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MNmm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MN·mm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MNmm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MN·mm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("en-US", "MNmm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("en-US", "µN·m/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µNm/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µN·m/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µNm/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µN·mm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µNmm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µN·mm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µNmm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µN·mm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("en-US", "µNmm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("en-US", "mN·m/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mNm/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mN·m/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mNm/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mN·mm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mNmm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mN·mm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mNmm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mN·mm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("en-US", "mNmm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("en-US", "nN·m/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nNm/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nN·m/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nNm/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nN·mm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nNmm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nN·mm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nNmm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nN·mm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("en-US", "nNmm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("en-US", "N·m/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "Nm/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "N·m/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "Nm/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "N·m/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("en-US", "Nm/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("en-US", "N·mm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "Nmm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "N·mm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "Nmm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "N·mm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("en-US", "Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("en-US", "lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] + [InlineData("en-US", "lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] + public void TryParseUnitWithCulture(string culture, string abbreviation, RotationalStiffnessUnit expectedUnit) + { + Assert.True(RotationalStiffness.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RotationalStiffnessUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs index 552bf04f6a..b2161b1f66 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("", ScalarUnit.Amount)] + public void ParseUnit(string abbreviation, ScalarUnit expectedUnit) { - try - { - var parsedUnit = Scalar.ParseUnit("", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ScalarUnit.Amount, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ScalarUnit parsedUnit = Scalar.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "", ScalarUnit.Amount)] + public void ParseUnitWithCulture(string culture, string abbreviation, ScalarUnit expectedUnit) + { + ScalarUnit parsedUnit = Scalar.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("", ScalarUnit.Amount)] + public void TryParseUnit(string abbreviation, ScalarUnit expectedUnit) { - { - Assert.True(Scalar.TryParseUnit("", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ScalarUnit.Amount, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Scalar.TryParseUnit(abbreviation, out ScalarUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "", ScalarUnit.Amount)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ScalarUnit expectedUnit) + { + Assert.True(Scalar.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ScalarUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs index f156035f35..e81b52c804 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("sr", SolidAngleUnit.Steradian)] + public void ParseUnit(string abbreviation, SolidAngleUnit expectedUnit) { - try - { - var parsedUnit = SolidAngle.ParseUnit("sr", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SolidAngleUnit.Steradian, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + SolidAngleUnit parsedUnit = SolidAngle.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "sr", SolidAngleUnit.Steradian)] + public void ParseUnitWithCulture(string culture, string abbreviation, SolidAngleUnit expectedUnit) + { + SolidAngleUnit parsedUnit = SolidAngle.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("sr", SolidAngleUnit.Steradian)] + public void TryParseUnit(string abbreviation, SolidAngleUnit expectedUnit) { - { - Assert.True(SolidAngle.TryParseUnit("sr", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SolidAngleUnit.Steradian, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(SolidAngle.TryParseUnit(abbreviation, out SolidAngleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "sr", SolidAngleUnit.Steradian)] + public void TryParseUnitWithCulture(string culture, string abbreviation, SolidAngleUnit expectedUnit) + { + Assert.True(SolidAngle.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SolidAngleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs index 5009f7f1ca..adca56a795 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs @@ -867,344 +867,154 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = SpecificEnergy.ParseUnit("btu/lb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.BtuPerPound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("cal/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.CaloriePerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("GWd/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("GWd/ST", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerShortTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("GWd/t", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerTonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("GWh/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.GigawattHourPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("GWh/lbs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.GigawattHourPerPound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("J/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.JoulePerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("kcal/g", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.KilocaloriePerGram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("kJ/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.KilojoulePerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("kWd/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("kWd/ST", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerShortTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("kWd/t", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerTonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("kWh/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.KilowattHourPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("kWh/lbs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.KilowattHourPerPound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("MJ/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.MegajoulePerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("MJ/t", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.MegaJoulePerTonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("MWd/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("MWd/ST", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerShortTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("MWd/t", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerTonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("MWh/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.MegawattHourPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("MWh/lbs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.MegawattHourPerPound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("TWd/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("TWd/ST", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerShortTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("TWd/t", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerTonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("Wd/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.WattDayPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("Wd/ST", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.WattDayPerShortTon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("Wd/t", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.WattDayPerTonne, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("Wh/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.WattHourPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEnergy.ParseUnit("Wh/lbs", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEnergyUnit.WattHourPerPound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("btu/lb", SpecificEnergyUnit.BtuPerPound)] + [InlineData("cal/g", SpecificEnergyUnit.CaloriePerGram)] + [InlineData("GWd/kg", SpecificEnergyUnit.GigawattDayPerKilogram)] + [InlineData("GWd/ST", SpecificEnergyUnit.GigawattDayPerShortTon)] + [InlineData("GWd/t", SpecificEnergyUnit.GigawattDayPerTonne)] + [InlineData("GWh/kg", SpecificEnergyUnit.GigawattHourPerKilogram)] + [InlineData("GWh/lbs", SpecificEnergyUnit.GigawattHourPerPound)] + [InlineData("J/kg", SpecificEnergyUnit.JoulePerKilogram)] + [InlineData("kcal/g", SpecificEnergyUnit.KilocaloriePerGram)] + [InlineData("kJ/kg", SpecificEnergyUnit.KilojoulePerKilogram)] + [InlineData("kWd/kg", SpecificEnergyUnit.KilowattDayPerKilogram)] + [InlineData("kWd/ST", SpecificEnergyUnit.KilowattDayPerShortTon)] + [InlineData("kWd/t", SpecificEnergyUnit.KilowattDayPerTonne)] + [InlineData("kWh/kg", SpecificEnergyUnit.KilowattHourPerKilogram)] + [InlineData("kWh/lbs", SpecificEnergyUnit.KilowattHourPerPound)] + [InlineData("MJ/kg", SpecificEnergyUnit.MegajoulePerKilogram)] + [InlineData("MJ/t", SpecificEnergyUnit.MegaJoulePerTonne)] + [InlineData("MWd/kg", SpecificEnergyUnit.MegawattDayPerKilogram)] + [InlineData("MWd/ST", SpecificEnergyUnit.MegawattDayPerShortTon)] + [InlineData("MWd/t", SpecificEnergyUnit.MegawattDayPerTonne)] + [InlineData("MWh/kg", SpecificEnergyUnit.MegawattHourPerKilogram)] + [InlineData("MWh/lbs", SpecificEnergyUnit.MegawattHourPerPound)] + [InlineData("TWd/kg", SpecificEnergyUnit.TerawattDayPerKilogram)] + [InlineData("TWd/ST", SpecificEnergyUnit.TerawattDayPerShortTon)] + [InlineData("TWd/t", SpecificEnergyUnit.TerawattDayPerTonne)] + [InlineData("Wd/kg", SpecificEnergyUnit.WattDayPerKilogram)] + [InlineData("Wd/ST", SpecificEnergyUnit.WattDayPerShortTon)] + [InlineData("Wd/t", SpecificEnergyUnit.WattDayPerTonne)] + [InlineData("Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] + [InlineData("Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] + public void ParseUnit(string abbreviation, SpecificEnergyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + SpecificEnergyUnit parsedUnit = SpecificEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(SpecificEnergy.TryParseUnit("btu/lb", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.BtuPerPound, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("cal/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.CaloriePerGram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("GWd/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerKilogram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("GWd/ST", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerShortTon, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("GWd/t", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.GigawattDayPerTonne, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("GWh/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.GigawattHourPerKilogram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("GWh/lbs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.GigawattHourPerPound, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("J/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.JoulePerKilogram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("kcal/g", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.KilocaloriePerGram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("kJ/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.KilojoulePerKilogram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("kWd/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerKilogram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("kWd/ST", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerShortTon, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("kWd/t", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.KilowattDayPerTonne, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("kWh/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.KilowattHourPerKilogram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("kWh/lbs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.KilowattHourPerPound, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("MJ/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.MegajoulePerKilogram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("MJ/t", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.MegaJoulePerTonne, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("MWd/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerKilogram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("MWd/ST", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerShortTon, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("MWd/t", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.MegawattDayPerTonne, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("MWh/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.MegawattHourPerKilogram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("MWh/lbs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.MegawattHourPerPound, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("TWd/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerKilogram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("TWd/ST", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerShortTon, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("TWd/t", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.TerawattDayPerTonne, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("Wd/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.WattDayPerKilogram, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("Wd/ST", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.WattDayPerShortTon, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("Wd/t", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.WattDayPerTonne, parsedUnit); - } - - { - Assert.True(SpecificEnergy.TryParseUnit("Wh/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.WattHourPerKilogram, parsedUnit); - } + [Theory] + [InlineData("en-US", "btu/lb", SpecificEnergyUnit.BtuPerPound)] + [InlineData("en-US", "cal/g", SpecificEnergyUnit.CaloriePerGram)] + [InlineData("en-US", "GWd/kg", SpecificEnergyUnit.GigawattDayPerKilogram)] + [InlineData("en-US", "GWd/ST", SpecificEnergyUnit.GigawattDayPerShortTon)] + [InlineData("en-US", "GWd/t", SpecificEnergyUnit.GigawattDayPerTonne)] + [InlineData("en-US", "GWh/kg", SpecificEnergyUnit.GigawattHourPerKilogram)] + [InlineData("en-US", "GWh/lbs", SpecificEnergyUnit.GigawattHourPerPound)] + [InlineData("en-US", "J/kg", SpecificEnergyUnit.JoulePerKilogram)] + [InlineData("en-US", "kcal/g", SpecificEnergyUnit.KilocaloriePerGram)] + [InlineData("en-US", "kJ/kg", SpecificEnergyUnit.KilojoulePerKilogram)] + [InlineData("en-US", "kWd/kg", SpecificEnergyUnit.KilowattDayPerKilogram)] + [InlineData("en-US", "kWd/ST", SpecificEnergyUnit.KilowattDayPerShortTon)] + [InlineData("en-US", "kWd/t", SpecificEnergyUnit.KilowattDayPerTonne)] + [InlineData("en-US", "kWh/kg", SpecificEnergyUnit.KilowattHourPerKilogram)] + [InlineData("en-US", "kWh/lbs", SpecificEnergyUnit.KilowattHourPerPound)] + [InlineData("en-US", "MJ/kg", SpecificEnergyUnit.MegajoulePerKilogram)] + [InlineData("en-US", "MJ/t", SpecificEnergyUnit.MegaJoulePerTonne)] + [InlineData("en-US", "MWd/kg", SpecificEnergyUnit.MegawattDayPerKilogram)] + [InlineData("en-US", "MWd/ST", SpecificEnergyUnit.MegawattDayPerShortTon)] + [InlineData("en-US", "MWd/t", SpecificEnergyUnit.MegawattDayPerTonne)] + [InlineData("en-US", "MWh/kg", SpecificEnergyUnit.MegawattHourPerKilogram)] + [InlineData("en-US", "MWh/lbs", SpecificEnergyUnit.MegawattHourPerPound)] + [InlineData("en-US", "TWd/kg", SpecificEnergyUnit.TerawattDayPerKilogram)] + [InlineData("en-US", "TWd/ST", SpecificEnergyUnit.TerawattDayPerShortTon)] + [InlineData("en-US", "TWd/t", SpecificEnergyUnit.TerawattDayPerTonne)] + [InlineData("en-US", "Wd/kg", SpecificEnergyUnit.WattDayPerKilogram)] + [InlineData("en-US", "Wd/ST", SpecificEnergyUnit.WattDayPerShortTon)] + [InlineData("en-US", "Wd/t", SpecificEnergyUnit.WattDayPerTonne)] + [InlineData("en-US", "Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] + [InlineData("en-US", "Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] + public void ParseUnitWithCulture(string culture, string abbreviation, SpecificEnergyUnit expectedUnit) + { + SpecificEnergyUnit parsedUnit = SpecificEnergy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(SpecificEnergy.TryParseUnit("Wh/lbs", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEnergyUnit.WattHourPerPound, parsedUnit); - } + [Theory] + [InlineData("btu/lb", SpecificEnergyUnit.BtuPerPound)] + [InlineData("cal/g", SpecificEnergyUnit.CaloriePerGram)] + [InlineData("GWd/kg", SpecificEnergyUnit.GigawattDayPerKilogram)] + [InlineData("GWd/ST", SpecificEnergyUnit.GigawattDayPerShortTon)] + [InlineData("GWd/t", SpecificEnergyUnit.GigawattDayPerTonne)] + [InlineData("GWh/kg", SpecificEnergyUnit.GigawattHourPerKilogram)] + [InlineData("GWh/lbs", SpecificEnergyUnit.GigawattHourPerPound)] + [InlineData("J/kg", SpecificEnergyUnit.JoulePerKilogram)] + [InlineData("kcal/g", SpecificEnergyUnit.KilocaloriePerGram)] + [InlineData("kJ/kg", SpecificEnergyUnit.KilojoulePerKilogram)] + [InlineData("kWd/kg", SpecificEnergyUnit.KilowattDayPerKilogram)] + [InlineData("kWd/ST", SpecificEnergyUnit.KilowattDayPerShortTon)] + [InlineData("kWd/t", SpecificEnergyUnit.KilowattDayPerTonne)] + [InlineData("kWh/kg", SpecificEnergyUnit.KilowattHourPerKilogram)] + [InlineData("kWh/lbs", SpecificEnergyUnit.KilowattHourPerPound)] + [InlineData("MJ/kg", SpecificEnergyUnit.MegajoulePerKilogram)] + [InlineData("MJ/t", SpecificEnergyUnit.MegaJoulePerTonne)] + [InlineData("MWd/kg", SpecificEnergyUnit.MegawattDayPerKilogram)] + [InlineData("MWd/ST", SpecificEnergyUnit.MegawattDayPerShortTon)] + [InlineData("MWd/t", SpecificEnergyUnit.MegawattDayPerTonne)] + [InlineData("MWh/kg", SpecificEnergyUnit.MegawattHourPerKilogram)] + [InlineData("MWh/lbs", SpecificEnergyUnit.MegawattHourPerPound)] + [InlineData("TWd/kg", SpecificEnergyUnit.TerawattDayPerKilogram)] + [InlineData("TWd/ST", SpecificEnergyUnit.TerawattDayPerShortTon)] + [InlineData("TWd/t", SpecificEnergyUnit.TerawattDayPerTonne)] + [InlineData("Wd/kg", SpecificEnergyUnit.WattDayPerKilogram)] + [InlineData("Wd/ST", SpecificEnergyUnit.WattDayPerShortTon)] + [InlineData("Wd/t", SpecificEnergyUnit.WattDayPerTonne)] + [InlineData("Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] + [InlineData("Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] + public void TryParseUnit(string abbreviation, SpecificEnergyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(SpecificEnergy.TryParseUnit(abbreviation, out SpecificEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "btu/lb", SpecificEnergyUnit.BtuPerPound)] + [InlineData("en-US", "cal/g", SpecificEnergyUnit.CaloriePerGram)] + [InlineData("en-US", "GWd/kg", SpecificEnergyUnit.GigawattDayPerKilogram)] + [InlineData("en-US", "GWd/ST", SpecificEnergyUnit.GigawattDayPerShortTon)] + [InlineData("en-US", "GWd/t", SpecificEnergyUnit.GigawattDayPerTonne)] + [InlineData("en-US", "GWh/kg", SpecificEnergyUnit.GigawattHourPerKilogram)] + [InlineData("en-US", "GWh/lbs", SpecificEnergyUnit.GigawattHourPerPound)] + [InlineData("en-US", "J/kg", SpecificEnergyUnit.JoulePerKilogram)] + [InlineData("en-US", "kcal/g", SpecificEnergyUnit.KilocaloriePerGram)] + [InlineData("en-US", "kJ/kg", SpecificEnergyUnit.KilojoulePerKilogram)] + [InlineData("en-US", "kWd/kg", SpecificEnergyUnit.KilowattDayPerKilogram)] + [InlineData("en-US", "kWd/ST", SpecificEnergyUnit.KilowattDayPerShortTon)] + [InlineData("en-US", "kWd/t", SpecificEnergyUnit.KilowattDayPerTonne)] + [InlineData("en-US", "kWh/kg", SpecificEnergyUnit.KilowattHourPerKilogram)] + [InlineData("en-US", "kWh/lbs", SpecificEnergyUnit.KilowattHourPerPound)] + [InlineData("en-US", "MJ/kg", SpecificEnergyUnit.MegajoulePerKilogram)] + [InlineData("en-US", "MJ/t", SpecificEnergyUnit.MegaJoulePerTonne)] + [InlineData("en-US", "MWd/kg", SpecificEnergyUnit.MegawattDayPerKilogram)] + [InlineData("en-US", "MWd/ST", SpecificEnergyUnit.MegawattDayPerShortTon)] + [InlineData("en-US", "MWd/t", SpecificEnergyUnit.MegawattDayPerTonne)] + [InlineData("en-US", "MWh/kg", SpecificEnergyUnit.MegawattHourPerKilogram)] + [InlineData("en-US", "MWh/lbs", SpecificEnergyUnit.MegawattHourPerPound)] + [InlineData("en-US", "TWd/kg", SpecificEnergyUnit.TerawattDayPerKilogram)] + [InlineData("en-US", "TWd/ST", SpecificEnergyUnit.TerawattDayPerShortTon)] + [InlineData("en-US", "TWd/t", SpecificEnergyUnit.TerawattDayPerTonne)] + [InlineData("en-US", "Wd/kg", SpecificEnergyUnit.WattDayPerKilogram)] + [InlineData("en-US", "Wd/ST", SpecificEnergyUnit.WattDayPerShortTon)] + [InlineData("en-US", "Wd/t", SpecificEnergyUnit.WattDayPerTonne)] + [InlineData("en-US", "Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] + [InlineData("en-US", "Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] + public void TryParseUnitWithCulture(string culture, string abbreviation, SpecificEnergyUnit expectedUnit) + { + Assert.True(SpecificEnergy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpecificEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs index 96a28d5348..14d9560161 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs @@ -397,124 +397,74 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = SpecificEntropy.ParseUnit("BTU/(lb·°F)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEntropyUnit.BtuPerPoundFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEntropy.ParseUnit("BTU/(lbm·°F)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEntropyUnit.BtuPerPoundFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEntropy.ParseUnit("cal/g.K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEntropyUnit.CaloriePerGramKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEntropy.ParseUnit("J/kg.C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEntropy.ParseUnit("J/kg.K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEntropyUnit.JoulePerKilogramKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEntropy.ParseUnit("kcal/g.K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEntropyUnit.KilocaloriePerGramKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEntropy.ParseUnit("kJ/kg.C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEntropy.ParseUnit("kJ/kg.K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEntropyUnit.KilojoulePerKilogramKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEntropy.ParseUnit("MJ/kg.C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificEntropy.ParseUnit("MJ/kg.K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificEntropyUnit.MegajoulePerKilogramKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("BTU/(lb·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("BTU/(lbm·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("cal/g.K", SpecificEntropyUnit.CaloriePerGramKelvin)] + [InlineData("J/kg.C", SpecificEntropyUnit.JoulePerKilogramDegreeCelsius)] + [InlineData("J/kg.K", SpecificEntropyUnit.JoulePerKilogramKelvin)] + [InlineData("kcal/g.K", SpecificEntropyUnit.KilocaloriePerGramKelvin)] + [InlineData("kJ/kg.C", SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius)] + [InlineData("kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] + [InlineData("MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] + [InlineData("MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] + public void ParseUnit(string abbreviation, SpecificEntropyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + SpecificEntropyUnit parsedUnit = SpecificEntropy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(SpecificEntropy.TryParseUnit("BTU/(lb·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEntropyUnit.BtuPerPoundFahrenheit, parsedUnit); - } - - { - Assert.True(SpecificEntropy.TryParseUnit("BTU/(lbm·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEntropyUnit.BtuPerPoundFahrenheit, parsedUnit); - } - - { - Assert.True(SpecificEntropy.TryParseUnit("cal/g.K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEntropyUnit.CaloriePerGramKelvin, parsedUnit); - } - - { - Assert.True(SpecificEntropy.TryParseUnit("J/kg.C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEntropyUnit.JoulePerKilogramDegreeCelsius, parsedUnit); - } - - { - Assert.True(SpecificEntropy.TryParseUnit("J/kg.K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEntropyUnit.JoulePerKilogramKelvin, parsedUnit); - } - - { - Assert.True(SpecificEntropy.TryParseUnit("kcal/g.K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEntropyUnit.KilocaloriePerGramKelvin, parsedUnit); - } - - { - Assert.True(SpecificEntropy.TryParseUnit("kJ/kg.C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius, parsedUnit); - } - - { - Assert.True(SpecificEntropy.TryParseUnit("kJ/kg.K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEntropyUnit.KilojoulePerKilogramKelvin, parsedUnit); - } - - { - Assert.True(SpecificEntropy.TryParseUnit("MJ/kg.C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius, parsedUnit); - } + [Theory] + [InlineData("en-US", "BTU/(lb·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("en-US", "BTU/(lbm·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("en-US", "cal/g.K", SpecificEntropyUnit.CaloriePerGramKelvin)] + [InlineData("en-US", "J/kg.C", SpecificEntropyUnit.JoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "J/kg.K", SpecificEntropyUnit.JoulePerKilogramKelvin)] + [InlineData("en-US", "kcal/g.K", SpecificEntropyUnit.KilocaloriePerGramKelvin)] + [InlineData("en-US", "kJ/kg.C", SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] + [InlineData("en-US", "MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] + public void ParseUnitWithCulture(string culture, string abbreviation, SpecificEntropyUnit expectedUnit) + { + SpecificEntropyUnit parsedUnit = SpecificEntropy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(SpecificEntropy.TryParseUnit("MJ/kg.K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificEntropyUnit.MegajoulePerKilogramKelvin, parsedUnit); - } + [Theory] + [InlineData("BTU/(lb·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("BTU/(lbm·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("cal/g.K", SpecificEntropyUnit.CaloriePerGramKelvin)] + [InlineData("J/kg.C", SpecificEntropyUnit.JoulePerKilogramDegreeCelsius)] + [InlineData("J/kg.K", SpecificEntropyUnit.JoulePerKilogramKelvin)] + [InlineData("kcal/g.K", SpecificEntropyUnit.KilocaloriePerGramKelvin)] + [InlineData("kJ/kg.C", SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius)] + [InlineData("kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] + [InlineData("MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] + [InlineData("MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] + public void TryParseUnit(string abbreviation, SpecificEntropyUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(SpecificEntropy.TryParseUnit(abbreviation, out SpecificEntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "BTU/(lb·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("en-US", "BTU/(lbm·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("en-US", "cal/g.K", SpecificEntropyUnit.CaloriePerGramKelvin)] + [InlineData("en-US", "J/kg.C", SpecificEntropyUnit.JoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "J/kg.K", SpecificEntropyUnit.JoulePerKilogramKelvin)] + [InlineData("en-US", "kcal/g.K", SpecificEntropyUnit.KilocaloriePerGramKelvin)] + [InlineData("en-US", "kJ/kg.C", SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] + [InlineData("en-US", "MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] + public void TryParseUnitWithCulture(string culture, string abbreviation, SpecificEntropyUnit expectedUnit) + { + Assert.True(SpecificEntropy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpecificEntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs index 36cca7e80e..43e90b7fd4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs @@ -269,58 +269,50 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("g/(kN�s)", SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond)] + [InlineData("kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] + [InlineData("kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] + [InlineData("lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] + public void ParseUnit(string abbreviation, SpecificFuelConsumptionUnit expectedUnit) { - try - { - var parsedUnit = SpecificFuelConsumption.ParseUnit("g/(kN�s)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificFuelConsumption.ParseUnit("kg/(kgf�h)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificFuelConsumption.ParseUnit("kg/(kN�s)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificFuelConsumption.ParseUnit("lb/(lbf·h)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + SpecificFuelConsumptionUnit parsedUnit = SpecificFuelConsumption.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "g/(kN�s)", SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond)] + [InlineData("en-US", "kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] + [InlineData("en-US", "kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] + [InlineData("en-US", "lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] + public void ParseUnitWithCulture(string culture, string abbreviation, SpecificFuelConsumptionUnit expectedUnit) { - { - Assert.True(SpecificFuelConsumption.TryParseUnit("g/(kN�s)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond, parsedUnit); - } - - { - Assert.True(SpecificFuelConsumption.TryParseUnit("kg/(kgf�h)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour, parsedUnit); - } - - { - Assert.True(SpecificFuelConsumption.TryParseUnit("kg/(kN�s)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond, parsedUnit); - } + SpecificFuelConsumptionUnit parsedUnit = SpecificFuelConsumption.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(SpecificFuelConsumption.TryParseUnit("lb/(lbf·h)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour, parsedUnit); - } + [Theory] + [InlineData("g/(kN�s)", SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond)] + [InlineData("kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] + [InlineData("kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] + [InlineData("lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] + public void TryParseUnit(string abbreviation, SpecificFuelConsumptionUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(SpecificFuelConsumption.TryParseUnit(abbreviation, out SpecificFuelConsumptionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "g/(kN�s)", SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond)] + [InlineData("en-US", "kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] + [InlineData("en-US", "kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] + [InlineData("en-US", "lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] + public void TryParseUnitWithCulture(string culture, string abbreviation, SpecificFuelConsumptionUnit expectedUnit) + { + Assert.True(SpecificFuelConsumption.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpecificFuelConsumptionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs index 7bcbfef68c..2a360fc1ee 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs @@ -246,47 +246,46 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] + [InlineData("m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] + [InlineData("mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] + public void ParseUnit(string abbreviation, SpecificVolumeUnit expectedUnit) { - try - { - var parsedUnit = SpecificVolume.ParseUnit("ft³/lb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificVolumeUnit.CubicFootPerPound, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificVolume.ParseUnit("m³/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificVolumeUnit.CubicMeterPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificVolume.ParseUnit("mm³/kg", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificVolumeUnit.MillicubicMeterPerKilogram, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + SpecificVolumeUnit parsedUnit = SpecificVolume.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] + [InlineData("en-US", "m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] + [InlineData("en-US", "mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] + public void ParseUnitWithCulture(string culture, string abbreviation, SpecificVolumeUnit expectedUnit) { - { - Assert.True(SpecificVolume.TryParseUnit("ft³/lb", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificVolumeUnit.CubicFootPerPound, parsedUnit); - } - - { - Assert.True(SpecificVolume.TryParseUnit("m³/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificVolumeUnit.CubicMeterPerKilogram, parsedUnit); - } + SpecificVolumeUnit parsedUnit = SpecificVolume.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(SpecificVolume.TryParseUnit("mm³/kg", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificVolumeUnit.MillicubicMeterPerKilogram, parsedUnit); - } + [Theory] + [InlineData("ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] + [InlineData("m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] + [InlineData("mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] + public void TryParseUnit(string abbreviation, SpecificVolumeUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(SpecificVolume.TryParseUnit(abbreviation, out SpecificVolumeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] + [InlineData("en-US", "m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] + [InlineData("en-US", "mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] + public void TryParseUnitWithCulture(string culture, string abbreviation, SpecificVolumeUnit expectedUnit) + { + Assert.True(SpecificVolume.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpecificVolumeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs index 9eae6be49e..09cccfe14c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs @@ -568,201 +568,102 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = SpecificWeight.ParseUnit("kgf/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("kgf/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("kgf/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("kN/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("kN/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("kN/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("kipf/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.KilopoundForcePerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("kipf/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.KilopoundForcePerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("MN/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.MeganewtonPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("N/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("N/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("N/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("lbf/ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.PoundForcePerCubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("lbf/in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.PoundForcePerCubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("tf/cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("tf/m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = SpecificWeight.ParseUnit("tf/mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("kgf/cm³", SpecificWeightUnit.KilogramForcePerCubicCentimeter)] + [InlineData("kgf/m³", SpecificWeightUnit.KilogramForcePerCubicMeter)] + [InlineData("kgf/mm³", SpecificWeightUnit.KilogramForcePerCubicMillimeter)] + [InlineData("kN/cm³", SpecificWeightUnit.KilonewtonPerCubicCentimeter)] + [InlineData("kN/m³", SpecificWeightUnit.KilonewtonPerCubicMeter)] + [InlineData("kN/mm³", SpecificWeightUnit.KilonewtonPerCubicMillimeter)] + [InlineData("kipf/ft³", SpecificWeightUnit.KilopoundForcePerCubicFoot)] + [InlineData("kipf/in³", SpecificWeightUnit.KilopoundForcePerCubicInch)] + [InlineData("MN/m³", SpecificWeightUnit.MeganewtonPerCubicMeter)] + [InlineData("N/cm³", SpecificWeightUnit.NewtonPerCubicCentimeter)] + [InlineData("N/m³", SpecificWeightUnit.NewtonPerCubicMeter)] + [InlineData("N/mm³", SpecificWeightUnit.NewtonPerCubicMillimeter)] + [InlineData("lbf/ft³", SpecificWeightUnit.PoundForcePerCubicFoot)] + [InlineData("lbf/in³", SpecificWeightUnit.PoundForcePerCubicInch)] + [InlineData("tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] + [InlineData("tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] + [InlineData("tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] + public void ParseUnit(string abbreviation, SpecificWeightUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + SpecificWeightUnit parsedUnit = SpecificWeight.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(SpecificWeight.TryParseUnit("kgf/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicCentimeter, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("kgf/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicMeter, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("kgf/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.KilogramForcePerCubicMillimeter, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("kN/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicCentimeter, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("kN/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicMeter, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("kN/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.KilonewtonPerCubicMillimeter, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("kipf/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.KilopoundForcePerCubicFoot, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("kipf/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.KilopoundForcePerCubicInch, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("MN/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.MeganewtonPerCubicMeter, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("N/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicCentimeter, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("N/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicMeter, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("N/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.NewtonPerCubicMillimeter, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("lbf/ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.PoundForcePerCubicFoot, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("lbf/in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.PoundForcePerCubicInch, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("tf/cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicCentimeter, parsedUnit); - } - - { - Assert.True(SpecificWeight.TryParseUnit("tf/m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicMeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "kgf/cm³", SpecificWeightUnit.KilogramForcePerCubicCentimeter)] + [InlineData("en-US", "kgf/m³", SpecificWeightUnit.KilogramForcePerCubicMeter)] + [InlineData("en-US", "kgf/mm³", SpecificWeightUnit.KilogramForcePerCubicMillimeter)] + [InlineData("en-US", "kN/cm³", SpecificWeightUnit.KilonewtonPerCubicCentimeter)] + [InlineData("en-US", "kN/m³", SpecificWeightUnit.KilonewtonPerCubicMeter)] + [InlineData("en-US", "kN/mm³", SpecificWeightUnit.KilonewtonPerCubicMillimeter)] + [InlineData("en-US", "kipf/ft³", SpecificWeightUnit.KilopoundForcePerCubicFoot)] + [InlineData("en-US", "kipf/in³", SpecificWeightUnit.KilopoundForcePerCubicInch)] + [InlineData("en-US", "MN/m³", SpecificWeightUnit.MeganewtonPerCubicMeter)] + [InlineData("en-US", "N/cm³", SpecificWeightUnit.NewtonPerCubicCentimeter)] + [InlineData("en-US", "N/m³", SpecificWeightUnit.NewtonPerCubicMeter)] + [InlineData("en-US", "N/mm³", SpecificWeightUnit.NewtonPerCubicMillimeter)] + [InlineData("en-US", "lbf/ft³", SpecificWeightUnit.PoundForcePerCubicFoot)] + [InlineData("en-US", "lbf/in³", SpecificWeightUnit.PoundForcePerCubicInch)] + [InlineData("en-US", "tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] + [InlineData("en-US", "tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] + [InlineData("en-US", "tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, SpecificWeightUnit expectedUnit) + { + SpecificWeightUnit parsedUnit = SpecificWeight.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(SpecificWeight.TryParseUnit("tf/mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpecificWeightUnit.TonneForcePerCubicMillimeter, parsedUnit); - } + [Theory] + [InlineData("kgf/cm³", SpecificWeightUnit.KilogramForcePerCubicCentimeter)] + [InlineData("kgf/m³", SpecificWeightUnit.KilogramForcePerCubicMeter)] + [InlineData("kgf/mm³", SpecificWeightUnit.KilogramForcePerCubicMillimeter)] + [InlineData("kN/cm³", SpecificWeightUnit.KilonewtonPerCubicCentimeter)] + [InlineData("kN/m³", SpecificWeightUnit.KilonewtonPerCubicMeter)] + [InlineData("kN/mm³", SpecificWeightUnit.KilonewtonPerCubicMillimeter)] + [InlineData("kipf/ft³", SpecificWeightUnit.KilopoundForcePerCubicFoot)] + [InlineData("kipf/in³", SpecificWeightUnit.KilopoundForcePerCubicInch)] + [InlineData("MN/m³", SpecificWeightUnit.MeganewtonPerCubicMeter)] + [InlineData("N/cm³", SpecificWeightUnit.NewtonPerCubicCentimeter)] + [InlineData("N/m³", SpecificWeightUnit.NewtonPerCubicMeter)] + [InlineData("N/mm³", SpecificWeightUnit.NewtonPerCubicMillimeter)] + [InlineData("lbf/ft³", SpecificWeightUnit.PoundForcePerCubicFoot)] + [InlineData("lbf/in³", SpecificWeightUnit.PoundForcePerCubicInch)] + [InlineData("tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] + [InlineData("tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] + [InlineData("tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] + public void TryParseUnit(string abbreviation, SpecificWeightUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(SpecificWeight.TryParseUnit(abbreviation, out SpecificWeightUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "kgf/cm³", SpecificWeightUnit.KilogramForcePerCubicCentimeter)] + [InlineData("en-US", "kgf/m³", SpecificWeightUnit.KilogramForcePerCubicMeter)] + [InlineData("en-US", "kgf/mm³", SpecificWeightUnit.KilogramForcePerCubicMillimeter)] + [InlineData("en-US", "kN/cm³", SpecificWeightUnit.KilonewtonPerCubicCentimeter)] + [InlineData("en-US", "kN/m³", SpecificWeightUnit.KilonewtonPerCubicMeter)] + [InlineData("en-US", "kN/mm³", SpecificWeightUnit.KilonewtonPerCubicMillimeter)] + [InlineData("en-US", "kipf/ft³", SpecificWeightUnit.KilopoundForcePerCubicFoot)] + [InlineData("en-US", "kipf/in³", SpecificWeightUnit.KilopoundForcePerCubicInch)] + [InlineData("en-US", "MN/m³", SpecificWeightUnit.MeganewtonPerCubicMeter)] + [InlineData("en-US", "N/cm³", SpecificWeightUnit.NewtonPerCubicCentimeter)] + [InlineData("en-US", "N/m³", SpecificWeightUnit.NewtonPerCubicMeter)] + [InlineData("en-US", "N/mm³", SpecificWeightUnit.NewtonPerCubicMillimeter)] + [InlineData("en-US", "lbf/ft³", SpecificWeightUnit.PoundForcePerCubicFoot)] + [InlineData("en-US", "lbf/in³", SpecificWeightUnit.PoundForcePerCubicInch)] + [InlineData("en-US", "tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] + [InlineData("en-US", "tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] + [InlineData("en-US", "tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, SpecificWeightUnit expectedUnit) + { + Assert.True(SpecificWeight.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpecificWeightUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs index b9380bd41d..48603f84c3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs @@ -1326,707 +1326,238 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Speed.ParseUnit("cm/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.CentimeterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("см/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.CentimeterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("cm/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.CentimeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("см/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.CentimeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("cm/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.CentimeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("см/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.CentimeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("dm/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.DecimeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("дм/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.DecimeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("dm/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.DecimeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("дм/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.DecimeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("ft/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.FootPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("фут/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.FootPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("ft/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.FootPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("фут/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.FootPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("ft/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.FootPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("фут/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.FootPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("in/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.InchPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("in/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.InchPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("in/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.InchPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("km/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.KilometerPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("км/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.KilometerPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("km/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.KilometerPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("км/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.KilometerPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("km/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.KilometerPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("км/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.KilometerPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("kn", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.Knot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("kt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.Knot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("knot", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.Knot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("knots", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.Knot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("уз.", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.Knot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("M", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.Mach, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("Ma", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.Mach, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("MN", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.Mach, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("MACH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.Mach, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("мах", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.Mach, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("m/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.MeterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("м/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.MeterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("m/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.MeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("м/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.MeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("m/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.MeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("м/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.MeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("µm/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.MicrometerPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("мкм/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.MicrometerPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("µm/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.MicrometerPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("мкм/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.MicrometerPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("mph", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.MilePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("миль/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.MilePerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("mm/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.MillimeterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("мм/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.MillimeterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("mm/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.MillimeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("мм/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.MillimeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("mm/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.MillimeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("мм/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.MillimeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("nm/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.NanometerPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("нм/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.NanometerPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("nm/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.NanometerPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("нм/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(SpeedUnit.NanometerPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("ftUS/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.UsSurveyFootPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("ftUS/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.UsSurveyFootPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("ftUS/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.UsSurveyFootPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("yd/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.YardPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("yd/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.YardPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Speed.ParseUnit("yd/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(SpeedUnit.YardPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cm/h", SpeedUnit.CentimeterPerHour)] + [InlineData("cm/min", SpeedUnit.CentimeterPerMinute)] + [InlineData("cm/s", SpeedUnit.CentimeterPerSecond)] + [InlineData("dm/min", SpeedUnit.DecimeterPerMinute)] + [InlineData("dm/s", SpeedUnit.DecimeterPerSecond)] + [InlineData("ft/h", SpeedUnit.FootPerHour)] + [InlineData("ft/min", SpeedUnit.FootPerMinute)] + [InlineData("ft/s", SpeedUnit.FootPerSecond)] + [InlineData("in/h", SpeedUnit.InchPerHour)] + [InlineData("in/min", SpeedUnit.InchPerMinute)] + [InlineData("in/s", SpeedUnit.InchPerSecond)] + [InlineData("km/h", SpeedUnit.KilometerPerHour)] + [InlineData("km/min", SpeedUnit.KilometerPerMinute)] + [InlineData("km/s", SpeedUnit.KilometerPerSecond)] + [InlineData("kn", SpeedUnit.Knot)] + [InlineData("kt", SpeedUnit.Knot)] + [InlineData("knot", SpeedUnit.Knot)] + [InlineData("knots", SpeedUnit.Knot)] + [InlineData("M", SpeedUnit.Mach)] + [InlineData("Ma", SpeedUnit.Mach)] + [InlineData("MN", SpeedUnit.Mach)] + [InlineData("MACH", SpeedUnit.Mach)] + [InlineData("m/h", SpeedUnit.MeterPerHour)] + [InlineData("m/min", SpeedUnit.MeterPerMinute)] + [InlineData("m/s", SpeedUnit.MeterPerSecond)] + [InlineData("µm/min", SpeedUnit.MicrometerPerMinute)] + [InlineData("µm/s", SpeedUnit.MicrometerPerSecond)] + [InlineData("mph", SpeedUnit.MilePerHour)] + [InlineData("mm/h", SpeedUnit.MillimeterPerHour)] + [InlineData("mm/min", SpeedUnit.MillimeterPerMinute)] + [InlineData("mm/s", SpeedUnit.MillimeterPerSecond)] + [InlineData("nm/min", SpeedUnit.NanometerPerMinute)] + [InlineData("nm/s", SpeedUnit.NanometerPerSecond)] + [InlineData("ftUS/h", SpeedUnit.UsSurveyFootPerHour)] + [InlineData("ftUS/min", SpeedUnit.UsSurveyFootPerMinute)] + [InlineData("ftUS/s", SpeedUnit.UsSurveyFootPerSecond)] + [InlineData("yd/h", SpeedUnit.YardPerHour)] + [InlineData("yd/min", SpeedUnit.YardPerMinute)] + [InlineData("yd/s", SpeedUnit.YardPerSecond)] + public void ParseUnit(string abbreviation, SpeedUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + SpeedUnit parsedUnit = Speed.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Speed.TryParseUnit("cm/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.CentimeterPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("см/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.CentimeterPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("cm/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.CentimeterPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("см/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.CentimeterPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("cm/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.CentimeterPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("см/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.CentimeterPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("dm/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.DecimeterPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("дм/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.DecimeterPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("dm/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.DecimeterPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("дм/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.DecimeterPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("ft/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.FootPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("фут/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.FootPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("ft/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.FootPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("фут/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.FootPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("ft/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.FootPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("фут/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.FootPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("in/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.InchPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("in/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.InchPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("in/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.InchPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("km/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.KilometerPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("км/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.KilometerPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("km/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.KilometerPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("км/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.KilometerPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("km/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.KilometerPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("км/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.KilometerPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("kn", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.Knot, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("kt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.Knot, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("knot", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.Knot, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("knots", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.Knot, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("уз.", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.Knot, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("M", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.Mach, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("Ma", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.Mach, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("MN", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.Mach, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("MACH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.Mach, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("мах", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.Mach, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("m/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MeterPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("м/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MeterPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("m/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MeterPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("м/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MeterPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("m/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MeterPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("м/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MeterPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("µm/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MicrometerPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("мкм/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MicrometerPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("µm/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MicrometerPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("мкм/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MicrometerPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("mph", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MilePerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("миль/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MilePerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("mm/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MillimeterPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("мм/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MillimeterPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("mm/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MillimeterPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("мм/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MillimeterPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("mm/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MillimeterPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("мм/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.MillimeterPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("nm/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.NanometerPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("нм/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.NanometerPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("nm/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.NanometerPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("нм/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(SpeedUnit.NanometerPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("ftUS/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.UsSurveyFootPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("ftUS/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.UsSurveyFootPerMinute, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("ftUS/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.UsSurveyFootPerSecond, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("yd/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.YardPerHour, parsedUnit); - } - - { - Assert.True(Speed.TryParseUnit("yd/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.YardPerMinute, parsedUnit); - } + [Theory] + [InlineData("en-US", "cm/h", SpeedUnit.CentimeterPerHour)] + [InlineData("en-US", "cm/min", SpeedUnit.CentimeterPerMinute)] + [InlineData("en-US", "cm/s", SpeedUnit.CentimeterPerSecond)] + [InlineData("en-US", "dm/min", SpeedUnit.DecimeterPerMinute)] + [InlineData("en-US", "dm/s", SpeedUnit.DecimeterPerSecond)] + [InlineData("en-US", "ft/h", SpeedUnit.FootPerHour)] + [InlineData("en-US", "ft/min", SpeedUnit.FootPerMinute)] + [InlineData("en-US", "ft/s", SpeedUnit.FootPerSecond)] + [InlineData("en-US", "in/h", SpeedUnit.InchPerHour)] + [InlineData("en-US", "in/min", SpeedUnit.InchPerMinute)] + [InlineData("en-US", "in/s", SpeedUnit.InchPerSecond)] + [InlineData("en-US", "km/h", SpeedUnit.KilometerPerHour)] + [InlineData("en-US", "km/min", SpeedUnit.KilometerPerMinute)] + [InlineData("en-US", "km/s", SpeedUnit.KilometerPerSecond)] + [InlineData("en-US", "kn", SpeedUnit.Knot)] + [InlineData("en-US", "kt", SpeedUnit.Knot)] + [InlineData("en-US", "knot", SpeedUnit.Knot)] + [InlineData("en-US", "knots", SpeedUnit.Knot)] + [InlineData("en-US", "M", SpeedUnit.Mach)] + [InlineData("en-US", "Ma", SpeedUnit.Mach)] + [InlineData("en-US", "MN", SpeedUnit.Mach)] + [InlineData("en-US", "MACH", SpeedUnit.Mach)] + [InlineData("en-US", "m/h", SpeedUnit.MeterPerHour)] + [InlineData("en-US", "m/min", SpeedUnit.MeterPerMinute)] + [InlineData("en-US", "m/s", SpeedUnit.MeterPerSecond)] + [InlineData("en-US", "µm/min", SpeedUnit.MicrometerPerMinute)] + [InlineData("en-US", "µm/s", SpeedUnit.MicrometerPerSecond)] + [InlineData("en-US", "mph", SpeedUnit.MilePerHour)] + [InlineData("en-US", "mm/h", SpeedUnit.MillimeterPerHour)] + [InlineData("en-US", "mm/min", SpeedUnit.MillimeterPerMinute)] + [InlineData("en-US", "mm/s", SpeedUnit.MillimeterPerSecond)] + [InlineData("en-US", "nm/min", SpeedUnit.NanometerPerMinute)] + [InlineData("en-US", "nm/s", SpeedUnit.NanometerPerSecond)] + [InlineData("en-US", "ftUS/h", SpeedUnit.UsSurveyFootPerHour)] + [InlineData("en-US", "ftUS/min", SpeedUnit.UsSurveyFootPerMinute)] + [InlineData("en-US", "ftUS/s", SpeedUnit.UsSurveyFootPerSecond)] + [InlineData("en-US", "yd/h", SpeedUnit.YardPerHour)] + [InlineData("en-US", "yd/min", SpeedUnit.YardPerMinute)] + [InlineData("en-US", "yd/s", SpeedUnit.YardPerSecond)] + [InlineData("ru-RU", "см/ч", SpeedUnit.CentimeterPerHour)] + [InlineData("ru-RU", "см/мин", SpeedUnit.CentimeterPerMinute)] + [InlineData("ru-RU", "см/с", SpeedUnit.CentimeterPerSecond)] + [InlineData("ru-RU", "дм/мин", SpeedUnit.DecimeterPerMinute)] + [InlineData("ru-RU", "дм/с", SpeedUnit.DecimeterPerSecond)] + [InlineData("ru-RU", "фут/ч", SpeedUnit.FootPerHour)] + [InlineData("ru-RU", "фут/мин", SpeedUnit.FootPerMinute)] + [InlineData("ru-RU", "фут/с", SpeedUnit.FootPerSecond)] + [InlineData("ru-RU", "км/ч", SpeedUnit.KilometerPerHour)] + [InlineData("ru-RU", "км/мин", SpeedUnit.KilometerPerMinute)] + [InlineData("ru-RU", "км/с", SpeedUnit.KilometerPerSecond)] + [InlineData("ru-RU", "уз.", SpeedUnit.Knot)] + [InlineData("ru-RU", "мах", SpeedUnit.Mach)] + [InlineData("ru-RU", "м/ч", SpeedUnit.MeterPerHour)] + [InlineData("ru-RU", "м/мин", SpeedUnit.MeterPerMinute)] + [InlineData("ru-RU", "м/с", SpeedUnit.MeterPerSecond)] + [InlineData("ru-RU", "мкм/мин", SpeedUnit.MicrometerPerMinute)] + [InlineData("ru-RU", "мкм/с", SpeedUnit.MicrometerPerSecond)] + [InlineData("ru-RU", "миль/ч", SpeedUnit.MilePerHour)] + [InlineData("ru-RU", "мм/ч", SpeedUnit.MillimeterPerHour)] + [InlineData("ru-RU", "мм/мин", SpeedUnit.MillimeterPerMinute)] + [InlineData("ru-RU", "мм/с", SpeedUnit.MillimeterPerSecond)] + [InlineData("ru-RU", "нм/мин", SpeedUnit.NanometerPerMinute)] + [InlineData("ru-RU", "нм/с", SpeedUnit.NanometerPerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, SpeedUnit expectedUnit) + { + SpeedUnit parsedUnit = Speed.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Speed.TryParseUnit("yd/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(SpeedUnit.YardPerSecond, parsedUnit); - } + [Theory] + [InlineData("cm/h", SpeedUnit.CentimeterPerHour)] + [InlineData("cm/min", SpeedUnit.CentimeterPerMinute)] + [InlineData("cm/s", SpeedUnit.CentimeterPerSecond)] + [InlineData("dm/min", SpeedUnit.DecimeterPerMinute)] + [InlineData("dm/s", SpeedUnit.DecimeterPerSecond)] + [InlineData("ft/h", SpeedUnit.FootPerHour)] + [InlineData("ft/min", SpeedUnit.FootPerMinute)] + [InlineData("ft/s", SpeedUnit.FootPerSecond)] + [InlineData("in/h", SpeedUnit.InchPerHour)] + [InlineData("in/min", SpeedUnit.InchPerMinute)] + [InlineData("in/s", SpeedUnit.InchPerSecond)] + [InlineData("km/h", SpeedUnit.KilometerPerHour)] + [InlineData("km/min", SpeedUnit.KilometerPerMinute)] + [InlineData("km/s", SpeedUnit.KilometerPerSecond)] + [InlineData("kn", SpeedUnit.Knot)] + [InlineData("kt", SpeedUnit.Knot)] + [InlineData("knot", SpeedUnit.Knot)] + [InlineData("knots", SpeedUnit.Knot)] + [InlineData("M", SpeedUnit.Mach)] + [InlineData("Ma", SpeedUnit.Mach)] + [InlineData("MN", SpeedUnit.Mach)] + [InlineData("MACH", SpeedUnit.Mach)] + [InlineData("m/h", SpeedUnit.MeterPerHour)] + [InlineData("m/min", SpeedUnit.MeterPerMinute)] + [InlineData("m/s", SpeedUnit.MeterPerSecond)] + [InlineData("µm/min", SpeedUnit.MicrometerPerMinute)] + [InlineData("µm/s", SpeedUnit.MicrometerPerSecond)] + [InlineData("mph", SpeedUnit.MilePerHour)] + [InlineData("mm/h", SpeedUnit.MillimeterPerHour)] + [InlineData("mm/min", SpeedUnit.MillimeterPerMinute)] + [InlineData("mm/s", SpeedUnit.MillimeterPerSecond)] + [InlineData("nm/min", SpeedUnit.NanometerPerMinute)] + [InlineData("nm/s", SpeedUnit.NanometerPerSecond)] + [InlineData("ftUS/h", SpeedUnit.UsSurveyFootPerHour)] + [InlineData("ftUS/min", SpeedUnit.UsSurveyFootPerMinute)] + [InlineData("ftUS/s", SpeedUnit.UsSurveyFootPerSecond)] + [InlineData("yd/h", SpeedUnit.YardPerHour)] + [InlineData("yd/min", SpeedUnit.YardPerMinute)] + [InlineData("yd/s", SpeedUnit.YardPerSecond)] + public void TryParseUnit(string abbreviation, SpeedUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Speed.TryParseUnit(abbreviation, out SpeedUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cm/h", SpeedUnit.CentimeterPerHour)] + [InlineData("en-US", "cm/min", SpeedUnit.CentimeterPerMinute)] + [InlineData("en-US", "cm/s", SpeedUnit.CentimeterPerSecond)] + [InlineData("en-US", "dm/min", SpeedUnit.DecimeterPerMinute)] + [InlineData("en-US", "dm/s", SpeedUnit.DecimeterPerSecond)] + [InlineData("en-US", "ft/h", SpeedUnit.FootPerHour)] + [InlineData("en-US", "ft/min", SpeedUnit.FootPerMinute)] + [InlineData("en-US", "ft/s", SpeedUnit.FootPerSecond)] + [InlineData("en-US", "in/h", SpeedUnit.InchPerHour)] + [InlineData("en-US", "in/min", SpeedUnit.InchPerMinute)] + [InlineData("en-US", "in/s", SpeedUnit.InchPerSecond)] + [InlineData("en-US", "km/h", SpeedUnit.KilometerPerHour)] + [InlineData("en-US", "km/min", SpeedUnit.KilometerPerMinute)] + [InlineData("en-US", "km/s", SpeedUnit.KilometerPerSecond)] + [InlineData("en-US", "kn", SpeedUnit.Knot)] + [InlineData("en-US", "kt", SpeedUnit.Knot)] + [InlineData("en-US", "knot", SpeedUnit.Knot)] + [InlineData("en-US", "knots", SpeedUnit.Knot)] + [InlineData("en-US", "M", SpeedUnit.Mach)] + [InlineData("en-US", "Ma", SpeedUnit.Mach)] + [InlineData("en-US", "MN", SpeedUnit.Mach)] + [InlineData("en-US", "MACH", SpeedUnit.Mach)] + [InlineData("en-US", "m/h", SpeedUnit.MeterPerHour)] + [InlineData("en-US", "m/min", SpeedUnit.MeterPerMinute)] + [InlineData("en-US", "m/s", SpeedUnit.MeterPerSecond)] + [InlineData("en-US", "µm/min", SpeedUnit.MicrometerPerMinute)] + [InlineData("en-US", "µm/s", SpeedUnit.MicrometerPerSecond)] + [InlineData("en-US", "mph", SpeedUnit.MilePerHour)] + [InlineData("en-US", "mm/h", SpeedUnit.MillimeterPerHour)] + [InlineData("en-US", "mm/min", SpeedUnit.MillimeterPerMinute)] + [InlineData("en-US", "mm/s", SpeedUnit.MillimeterPerSecond)] + [InlineData("en-US", "nm/min", SpeedUnit.NanometerPerMinute)] + [InlineData("en-US", "nm/s", SpeedUnit.NanometerPerSecond)] + [InlineData("en-US", "ftUS/h", SpeedUnit.UsSurveyFootPerHour)] + [InlineData("en-US", "ftUS/min", SpeedUnit.UsSurveyFootPerMinute)] + [InlineData("en-US", "ftUS/s", SpeedUnit.UsSurveyFootPerSecond)] + [InlineData("en-US", "yd/h", SpeedUnit.YardPerHour)] + [InlineData("en-US", "yd/min", SpeedUnit.YardPerMinute)] + [InlineData("en-US", "yd/s", SpeedUnit.YardPerSecond)] + [InlineData("ru-RU", "см/ч", SpeedUnit.CentimeterPerHour)] + [InlineData("ru-RU", "см/мин", SpeedUnit.CentimeterPerMinute)] + [InlineData("ru-RU", "см/с", SpeedUnit.CentimeterPerSecond)] + [InlineData("ru-RU", "дм/мин", SpeedUnit.DecimeterPerMinute)] + [InlineData("ru-RU", "дм/с", SpeedUnit.DecimeterPerSecond)] + [InlineData("ru-RU", "фут/ч", SpeedUnit.FootPerHour)] + [InlineData("ru-RU", "фут/мин", SpeedUnit.FootPerMinute)] + [InlineData("ru-RU", "фут/с", SpeedUnit.FootPerSecond)] + [InlineData("ru-RU", "км/ч", SpeedUnit.KilometerPerHour)] + [InlineData("ru-RU", "км/мин", SpeedUnit.KilometerPerMinute)] + [InlineData("ru-RU", "км/с", SpeedUnit.KilometerPerSecond)] + [InlineData("ru-RU", "уз.", SpeedUnit.Knot)] + [InlineData("ru-RU", "мах", SpeedUnit.Mach)] + [InlineData("ru-RU", "м/ч", SpeedUnit.MeterPerHour)] + [InlineData("ru-RU", "м/мин", SpeedUnit.MeterPerMinute)] + [InlineData("ru-RU", "м/с", SpeedUnit.MeterPerSecond)] + [InlineData("ru-RU", "мкм/мин", SpeedUnit.MicrometerPerMinute)] + [InlineData("ru-RU", "мкм/с", SpeedUnit.MicrometerPerSecond)] + [InlineData("ru-RU", "миль/ч", SpeedUnit.MilePerHour)] + [InlineData("ru-RU", "мм/ч", SpeedUnit.MillimeterPerHour)] + [InlineData("ru-RU", "мм/мин", SpeedUnit.MillimeterPerMinute)] + [InlineData("ru-RU", "мм/с", SpeedUnit.MillimeterPerSecond)] + [InlineData("ru-RU", "нм/мин", SpeedUnit.NanometerPerMinute)] + [InlineData("ru-RU", "нм/с", SpeedUnit.NanometerPerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, SpeedUnit expectedUnit) + { + Assert.True(Speed.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpeedUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs index c2e430333a..00d4f5abd8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs @@ -384,113 +384,70 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = StandardVolumeFlow.ParseUnit("sccm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = StandardVolumeFlow.ParseUnit("scfh", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = StandardVolumeFlow.ParseUnit("scfm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = StandardVolumeFlow.ParseUnit("Sft³/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = StandardVolumeFlow.ParseUnit("Sm³/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = StandardVolumeFlow.ParseUnit("Sm³/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = StandardVolumeFlow.ParseUnit("Sm³/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = StandardVolumeFlow.ParseUnit("Sm³/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = StandardVolumeFlow.ParseUnit("slm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(StandardVolumeFlowUnit.StandardLiterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("sccm", StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute)] + [InlineData("scfh", StandardVolumeFlowUnit.StandardCubicFootPerHour)] + [InlineData("scfm", StandardVolumeFlowUnit.StandardCubicFootPerMinute)] + [InlineData("Sft³/s", StandardVolumeFlowUnit.StandardCubicFootPerSecond)] + [InlineData("Sm³/d", StandardVolumeFlowUnit.StandardCubicMeterPerDay)] + [InlineData("Sm³/h", StandardVolumeFlowUnit.StandardCubicMeterPerHour)] + [InlineData("Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] + [InlineData("Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] + [InlineData("slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] + public void ParseUnit(string abbreviation, StandardVolumeFlowUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + StandardVolumeFlowUnit parsedUnit = StandardVolumeFlow.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "sccm", StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute)] + [InlineData("en-US", "scfh", StandardVolumeFlowUnit.StandardCubicFootPerHour)] + [InlineData("en-US", "scfm", StandardVolumeFlowUnit.StandardCubicFootPerMinute)] + [InlineData("en-US", "Sft³/s", StandardVolumeFlowUnit.StandardCubicFootPerSecond)] + [InlineData("en-US", "Sm³/d", StandardVolumeFlowUnit.StandardCubicMeterPerDay)] + [InlineData("en-US", "Sm³/h", StandardVolumeFlowUnit.StandardCubicMeterPerHour)] + [InlineData("en-US", "Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] + [InlineData("en-US", "Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] + [InlineData("en-US", "slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] + public void ParseUnitWithCulture(string culture, string abbreviation, StandardVolumeFlowUnit expectedUnit) { - { - Assert.True(StandardVolumeFlow.TryParseUnit("sccm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute, parsedUnit); - } - - { - Assert.True(StandardVolumeFlow.TryParseUnit("scfh", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerHour, parsedUnit); - } - - { - Assert.True(StandardVolumeFlow.TryParseUnit("scfm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerMinute, parsedUnit); - } - - { - Assert.True(StandardVolumeFlow.TryParseUnit("Sft³/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicFootPerSecond, parsedUnit); - } - - { - Assert.True(StandardVolumeFlow.TryParseUnit("Sm³/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerDay, parsedUnit); - } - - { - Assert.True(StandardVolumeFlow.TryParseUnit("Sm³/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerHour, parsedUnit); - } - - { - Assert.True(StandardVolumeFlow.TryParseUnit("Sm³/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerMinute, parsedUnit); - } - - { - Assert.True(StandardVolumeFlow.TryParseUnit("Sm³/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(StandardVolumeFlowUnit.StandardCubicMeterPerSecond, parsedUnit); - } + StandardVolumeFlowUnit parsedUnit = StandardVolumeFlow.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(StandardVolumeFlow.TryParseUnit("slm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(StandardVolumeFlowUnit.StandardLiterPerMinute, parsedUnit); - } + [Theory] + [InlineData("sccm", StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute)] + [InlineData("scfh", StandardVolumeFlowUnit.StandardCubicFootPerHour)] + [InlineData("scfm", StandardVolumeFlowUnit.StandardCubicFootPerMinute)] + [InlineData("Sft³/s", StandardVolumeFlowUnit.StandardCubicFootPerSecond)] + [InlineData("Sm³/d", StandardVolumeFlowUnit.StandardCubicMeterPerDay)] + [InlineData("Sm³/h", StandardVolumeFlowUnit.StandardCubicMeterPerHour)] + [InlineData("Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] + [InlineData("Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] + [InlineData("slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] + public void TryParseUnit(string abbreviation, StandardVolumeFlowUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(StandardVolumeFlow.TryParseUnit(abbreviation, out StandardVolumeFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "sccm", StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute)] + [InlineData("en-US", "scfh", StandardVolumeFlowUnit.StandardCubicFootPerHour)] + [InlineData("en-US", "scfm", StandardVolumeFlowUnit.StandardCubicFootPerMinute)] + [InlineData("en-US", "Sft³/s", StandardVolumeFlowUnit.StandardCubicFootPerSecond)] + [InlineData("en-US", "Sm³/d", StandardVolumeFlowUnit.StandardCubicMeterPerDay)] + [InlineData("en-US", "Sm³/h", StandardVolumeFlowUnit.StandardCubicMeterPerHour)] + [InlineData("en-US", "Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] + [InlineData("en-US", "Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] + [InlineData("en-US", "slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] + public void TryParseUnitWithCulture(string culture, string abbreviation, StandardVolumeFlowUnit expectedUnit) + { + Assert.True(StandardVolumeFlow.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out StandardVolumeFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs index 4afb8b5cc3..c5af1cb067 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs @@ -407,124 +407,74 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = TemperatureChangeRate.ParseUnit("c°C/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureChangeRate.ParseUnit("da°C/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureChangeRate.ParseUnit("d°C/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureChangeRate.ParseUnit("°C/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureChangeRate.ParseUnit("°C/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureChangeRate.ParseUnit("h°C/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureChangeRate.ParseUnit("k°C/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureChangeRate.ParseUnit("µ°C/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureChangeRate.ParseUnit("m°C/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureChangeRate.ParseUnit("n°C/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("c°C/s", TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond)] + [InlineData("da°C/s", TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond)] + [InlineData("d°C/s", TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond)] + [InlineData("°C/min", TemperatureChangeRateUnit.DegreeCelsiusPerMinute)] + [InlineData("°C/s", TemperatureChangeRateUnit.DegreeCelsiusPerSecond)] + [InlineData("h°C/s", TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond)] + [InlineData("k°C/s", TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond)] + [InlineData("µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] + [InlineData("m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] + [InlineData("n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] + public void ParseUnit(string abbreviation, TemperatureChangeRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + TemperatureChangeRateUnit parsedUnit = TemperatureChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(TemperatureChangeRate.TryParseUnit("c°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond, parsedUnit); - } - - { - Assert.True(TemperatureChangeRate.TryParseUnit("da°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond, parsedUnit); - } - - { - Assert.True(TemperatureChangeRate.TryParseUnit("d°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond, parsedUnit); - } - - { - Assert.True(TemperatureChangeRate.TryParseUnit("°C/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerMinute, parsedUnit); - } - - { - Assert.True(TemperatureChangeRate.TryParseUnit("°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureChangeRateUnit.DegreeCelsiusPerSecond, parsedUnit); - } - - { - Assert.True(TemperatureChangeRate.TryParseUnit("h°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond, parsedUnit); - } - - { - Assert.True(TemperatureChangeRate.TryParseUnit("k°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond, parsedUnit); - } - - { - Assert.True(TemperatureChangeRate.TryParseUnit("µ°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond, parsedUnit); - } - - { - Assert.True(TemperatureChangeRate.TryParseUnit("m°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond, parsedUnit); - } + [Theory] + [InlineData("en-US", "c°C/s", TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond)] + [InlineData("en-US", "da°C/s", TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond)] + [InlineData("en-US", "d°C/s", TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond)] + [InlineData("en-US", "°C/min", TemperatureChangeRateUnit.DegreeCelsiusPerMinute)] + [InlineData("en-US", "°C/s", TemperatureChangeRateUnit.DegreeCelsiusPerSecond)] + [InlineData("en-US", "h°C/s", TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond)] + [InlineData("en-US", "k°C/s", TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond)] + [InlineData("en-US", "µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] + [InlineData("en-US", "m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] + [InlineData("en-US", "n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, TemperatureChangeRateUnit expectedUnit) + { + TemperatureChangeRateUnit parsedUnit = TemperatureChangeRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(TemperatureChangeRate.TryParseUnit("n°C/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond, parsedUnit); - } + [Theory] + [InlineData("c°C/s", TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond)] + [InlineData("da°C/s", TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond)] + [InlineData("d°C/s", TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond)] + [InlineData("°C/min", TemperatureChangeRateUnit.DegreeCelsiusPerMinute)] + [InlineData("°C/s", TemperatureChangeRateUnit.DegreeCelsiusPerSecond)] + [InlineData("h°C/s", TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond)] + [InlineData("k°C/s", TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond)] + [InlineData("µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] + [InlineData("m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] + [InlineData("n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] + public void TryParseUnit(string abbreviation, TemperatureChangeRateUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(TemperatureChangeRate.TryParseUnit(abbreviation, out TemperatureChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "c°C/s", TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond)] + [InlineData("en-US", "da°C/s", TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond)] + [InlineData("en-US", "d°C/s", TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond)] + [InlineData("en-US", "°C/min", TemperatureChangeRateUnit.DegreeCelsiusPerMinute)] + [InlineData("en-US", "°C/s", TemperatureChangeRateUnit.DegreeCelsiusPerSecond)] + [InlineData("en-US", "h°C/s", TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond)] + [InlineData("en-US", "k°C/s", TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond)] + [InlineData("en-US", "µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] + [InlineData("en-US", "m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] + [InlineData("en-US", "n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, TemperatureChangeRateUnit expectedUnit) + { + Assert.True(TemperatureChangeRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TemperatureChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs index f11977c1b4..eb2137c59b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs @@ -384,113 +384,70 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = TemperatureDelta.ParseUnit("∆°C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureDeltaUnit.DegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureDelta.ParseUnit("∆°De", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureDeltaUnit.DegreeDelisle, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureDelta.ParseUnit("∆°F", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureDeltaUnit.DegreeFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureDelta.ParseUnit("∆°N", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureDeltaUnit.DegreeNewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureDelta.ParseUnit("∆°R", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureDeltaUnit.DegreeRankine, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureDelta.ParseUnit("∆°Ré", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureDeltaUnit.DegreeReaumur, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureDelta.ParseUnit("∆°Rø", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureDeltaUnit.DegreeRoemer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureDelta.ParseUnit("∆K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureDeltaUnit.Kelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureDelta.ParseUnit("∆m°C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureDeltaUnit.MillidegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("∆°C", TemperatureDeltaUnit.DegreeCelsius)] + [InlineData("∆°De", TemperatureDeltaUnit.DegreeDelisle)] + [InlineData("∆°F", TemperatureDeltaUnit.DegreeFahrenheit)] + [InlineData("∆°N", TemperatureDeltaUnit.DegreeNewton)] + [InlineData("∆°R", TemperatureDeltaUnit.DegreeRankine)] + [InlineData("∆°Ré", TemperatureDeltaUnit.DegreeReaumur)] + [InlineData("∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] + [InlineData("∆K", TemperatureDeltaUnit.Kelvin)] + [InlineData("∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] + public void ParseUnit(string abbreviation, TemperatureDeltaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + TemperatureDeltaUnit parsedUnit = TemperatureDelta.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "∆°C", TemperatureDeltaUnit.DegreeCelsius)] + [InlineData("en-US", "∆°De", TemperatureDeltaUnit.DegreeDelisle)] + [InlineData("en-US", "∆°F", TemperatureDeltaUnit.DegreeFahrenheit)] + [InlineData("en-US", "∆°N", TemperatureDeltaUnit.DegreeNewton)] + [InlineData("en-US", "∆°R", TemperatureDeltaUnit.DegreeRankine)] + [InlineData("en-US", "∆°Ré", TemperatureDeltaUnit.DegreeReaumur)] + [InlineData("en-US", "∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] + [InlineData("en-US", "∆K", TemperatureDeltaUnit.Kelvin)] + [InlineData("en-US", "∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] + public void ParseUnitWithCulture(string culture, string abbreviation, TemperatureDeltaUnit expectedUnit) { - { - Assert.True(TemperatureDelta.TryParseUnit("∆°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureDeltaUnit.DegreeCelsius, parsedUnit); - } - - { - Assert.True(TemperatureDelta.TryParseUnit("∆°De", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureDeltaUnit.DegreeDelisle, parsedUnit); - } - - { - Assert.True(TemperatureDelta.TryParseUnit("∆°F", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureDeltaUnit.DegreeFahrenheit, parsedUnit); - } - - { - Assert.True(TemperatureDelta.TryParseUnit("∆°N", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureDeltaUnit.DegreeNewton, parsedUnit); - } - - { - Assert.True(TemperatureDelta.TryParseUnit("∆°R", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureDeltaUnit.DegreeRankine, parsedUnit); - } - - { - Assert.True(TemperatureDelta.TryParseUnit("∆°Ré", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureDeltaUnit.DegreeReaumur, parsedUnit); - } - - { - Assert.True(TemperatureDelta.TryParseUnit("∆°Rø", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureDeltaUnit.DegreeRoemer, parsedUnit); - } - - { - Assert.True(TemperatureDelta.TryParseUnit("∆K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureDeltaUnit.Kelvin, parsedUnit); - } + TemperatureDeltaUnit parsedUnit = TemperatureDelta.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(TemperatureDelta.TryParseUnit("∆m°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureDeltaUnit.MillidegreeCelsius, parsedUnit); - } + [Theory] + [InlineData("∆°C", TemperatureDeltaUnit.DegreeCelsius)] + [InlineData("∆°De", TemperatureDeltaUnit.DegreeDelisle)] + [InlineData("∆°F", TemperatureDeltaUnit.DegreeFahrenheit)] + [InlineData("∆°N", TemperatureDeltaUnit.DegreeNewton)] + [InlineData("∆°R", TemperatureDeltaUnit.DegreeRankine)] + [InlineData("∆°Ré", TemperatureDeltaUnit.DegreeReaumur)] + [InlineData("∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] + [InlineData("∆K", TemperatureDeltaUnit.Kelvin)] + [InlineData("∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] + public void TryParseUnit(string abbreviation, TemperatureDeltaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(TemperatureDelta.TryParseUnit(abbreviation, out TemperatureDeltaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "∆°C", TemperatureDeltaUnit.DegreeCelsius)] + [InlineData("en-US", "∆°De", TemperatureDeltaUnit.DegreeDelisle)] + [InlineData("en-US", "∆°F", TemperatureDeltaUnit.DegreeFahrenheit)] + [InlineData("en-US", "∆°N", TemperatureDeltaUnit.DegreeNewton)] + [InlineData("en-US", "∆°R", TemperatureDeltaUnit.DegreeRankine)] + [InlineData("en-US", "∆°Ré", TemperatureDeltaUnit.DegreeReaumur)] + [InlineData("en-US", "∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] + [InlineData("en-US", "∆K", TemperatureDeltaUnit.Kelvin)] + [InlineData("en-US", "∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] + public void TryParseUnitWithCulture(string culture, string abbreviation, TemperatureDeltaUnit expectedUnit) + { + Assert.True(TemperatureDelta.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TemperatureDeltaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs index 8ef845aca4..824ff09341 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs @@ -269,58 +269,50 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("∆°C/km", TemperatureGradientUnit.DegreeCelsiusPerKilometer)] + [InlineData("∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] + [InlineData("∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] + [InlineData("∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] + public void ParseUnit(string abbreviation, TemperatureGradientUnit expectedUnit) { - try - { - var parsedUnit = TemperatureGradient.ParseUnit("∆°C/km", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureGradientUnit.DegreeCelsiusPerKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureGradient.ParseUnit("∆°C/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureGradientUnit.DegreeCelsiusPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureGradient.ParseUnit("∆°F/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureGradientUnit.DegreeFahrenheitPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = TemperatureGradient.ParseUnit("∆°K/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureGradientUnit.KelvinPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + TemperatureGradientUnit parsedUnit = TemperatureGradient.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "∆°C/km", TemperatureGradientUnit.DegreeCelsiusPerKilometer)] + [InlineData("en-US", "∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] + [InlineData("en-US", "∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] + [InlineData("en-US", "∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, TemperatureGradientUnit expectedUnit) { - { - Assert.True(TemperatureGradient.TryParseUnit("∆°C/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureGradientUnit.DegreeCelsiusPerKilometer, parsedUnit); - } - - { - Assert.True(TemperatureGradient.TryParseUnit("∆°C/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureGradientUnit.DegreeCelsiusPerMeter, parsedUnit); - } - - { - Assert.True(TemperatureGradient.TryParseUnit("∆°F/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureGradientUnit.DegreeFahrenheitPerFoot, parsedUnit); - } + TemperatureGradientUnit parsedUnit = TemperatureGradient.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(TemperatureGradient.TryParseUnit("∆°K/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureGradientUnit.KelvinPerMeter, parsedUnit); - } + [Theory] + [InlineData("∆°C/km", TemperatureGradientUnit.DegreeCelsiusPerKilometer)] + [InlineData("∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] + [InlineData("∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] + [InlineData("∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] + public void TryParseUnit(string abbreviation, TemperatureGradientUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(TemperatureGradient.TryParseUnit(abbreviation, out TemperatureGradientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "∆°C/km", TemperatureGradientUnit.DegreeCelsiusPerKilometer)] + [InlineData("en-US", "∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] + [InlineData("en-US", "∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] + [InlineData("en-US", "∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, TemperatureGradientUnit expectedUnit) + { + Assert.True(TemperatureGradient.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TemperatureGradientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs index 81026bf346..b97698e0fa 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs @@ -407,124 +407,74 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Temperature.ParseUnit("°C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureUnit.DegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Temperature.ParseUnit("°De", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureUnit.DegreeDelisle, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Temperature.ParseUnit("°F", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureUnit.DegreeFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Temperature.ParseUnit("°N", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureUnit.DegreeNewton, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Temperature.ParseUnit("°R", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureUnit.DegreeRankine, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Temperature.ParseUnit("°Ré", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureUnit.DegreeReaumur, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Temperature.ParseUnit("°Rø", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureUnit.DegreeRoemer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Temperature.ParseUnit("K", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureUnit.Kelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Temperature.ParseUnit("m°C", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureUnit.MillidegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Temperature.ParseUnit("T⊙", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TemperatureUnit.SolarTemperature, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("°C", TemperatureUnit.DegreeCelsius)] + [InlineData("°De", TemperatureUnit.DegreeDelisle)] + [InlineData("°F", TemperatureUnit.DegreeFahrenheit)] + [InlineData("°N", TemperatureUnit.DegreeNewton)] + [InlineData("°R", TemperatureUnit.DegreeRankine)] + [InlineData("°Ré", TemperatureUnit.DegreeReaumur)] + [InlineData("°Rø", TemperatureUnit.DegreeRoemer)] + [InlineData("K", TemperatureUnit.Kelvin)] + [InlineData("m°C", TemperatureUnit.MillidegreeCelsius)] + [InlineData("T⊙", TemperatureUnit.SolarTemperature)] + public void ParseUnit(string abbreviation, TemperatureUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + TemperatureUnit parsedUnit = Temperature.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Temperature.TryParseUnit("°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureUnit.DegreeCelsius, parsedUnit); - } - - { - Assert.True(Temperature.TryParseUnit("°De", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureUnit.DegreeDelisle, parsedUnit); - } - - { - Assert.True(Temperature.TryParseUnit("°F", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureUnit.DegreeFahrenheit, parsedUnit); - } - - { - Assert.True(Temperature.TryParseUnit("°N", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureUnit.DegreeNewton, parsedUnit); - } - - { - Assert.True(Temperature.TryParseUnit("°R", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureUnit.DegreeRankine, parsedUnit); - } - - { - Assert.True(Temperature.TryParseUnit("°Ré", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureUnit.DegreeReaumur, parsedUnit); - } - - { - Assert.True(Temperature.TryParseUnit("°Rø", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureUnit.DegreeRoemer, parsedUnit); - } - - { - Assert.True(Temperature.TryParseUnit("K", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureUnit.Kelvin, parsedUnit); - } - - { - Assert.True(Temperature.TryParseUnit("m°C", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureUnit.MillidegreeCelsius, parsedUnit); - } + [Theory] + [InlineData("en-US", "°C", TemperatureUnit.DegreeCelsius)] + [InlineData("en-US", "°De", TemperatureUnit.DegreeDelisle)] + [InlineData("en-US", "°F", TemperatureUnit.DegreeFahrenheit)] + [InlineData("en-US", "°N", TemperatureUnit.DegreeNewton)] + [InlineData("en-US", "°R", TemperatureUnit.DegreeRankine)] + [InlineData("en-US", "°Ré", TemperatureUnit.DegreeReaumur)] + [InlineData("en-US", "°Rø", TemperatureUnit.DegreeRoemer)] + [InlineData("en-US", "K", TemperatureUnit.Kelvin)] + [InlineData("en-US", "m°C", TemperatureUnit.MillidegreeCelsius)] + [InlineData("en-US", "T⊙", TemperatureUnit.SolarTemperature)] + public void ParseUnitWithCulture(string culture, string abbreviation, TemperatureUnit expectedUnit) + { + TemperatureUnit parsedUnit = Temperature.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Temperature.TryParseUnit("T⊙", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TemperatureUnit.SolarTemperature, parsedUnit); - } + [Theory] + [InlineData("°C", TemperatureUnit.DegreeCelsius)] + [InlineData("°De", TemperatureUnit.DegreeDelisle)] + [InlineData("°F", TemperatureUnit.DegreeFahrenheit)] + [InlineData("°N", TemperatureUnit.DegreeNewton)] + [InlineData("°R", TemperatureUnit.DegreeRankine)] + [InlineData("°Ré", TemperatureUnit.DegreeReaumur)] + [InlineData("°Rø", TemperatureUnit.DegreeRoemer)] + [InlineData("K", TemperatureUnit.Kelvin)] + [InlineData("m°C", TemperatureUnit.MillidegreeCelsius)] + [InlineData("T⊙", TemperatureUnit.SolarTemperature)] + public void TryParseUnit(string abbreviation, TemperatureUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Temperature.TryParseUnit(abbreviation, out TemperatureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "°C", TemperatureUnit.DegreeCelsius)] + [InlineData("en-US", "°De", TemperatureUnit.DegreeDelisle)] + [InlineData("en-US", "°F", TemperatureUnit.DegreeFahrenheit)] + [InlineData("en-US", "°N", TemperatureUnit.DegreeNewton)] + [InlineData("en-US", "°R", TemperatureUnit.DegreeRankine)] + [InlineData("en-US", "°Ré", TemperatureUnit.DegreeReaumur)] + [InlineData("en-US", "°Rø", TemperatureUnit.DegreeRoemer)] + [InlineData("en-US", "K", TemperatureUnit.Kelvin)] + [InlineData("en-US", "m°C", TemperatureUnit.MillidegreeCelsius)] + [InlineData("en-US", "T⊙", TemperatureUnit.SolarTemperature)] + public void TryParseUnitWithCulture(string culture, string abbreviation, TemperatureUnit expectedUnit) + { + Assert.True(Temperature.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TemperatureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs index ed4138ba78..35ce56e9c0 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs @@ -223,36 +223,42 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] + [InlineData("W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] + public void ParseUnit(string abbreviation, ThermalConductivityUnit expectedUnit) { - try - { - var parsedUnit = ThermalConductivity.ParseUnit("BTU/(h·ft·°F)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ThermalConductivityUnit.BtuPerHourFootFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ThermalConductivity.ParseUnit("W/(m·K)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ThermalConductivityUnit.WattPerMeterKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ThermalConductivityUnit parsedUnit = ThermalConductivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] + [InlineData("en-US", "W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] + public void ParseUnitWithCulture(string culture, string abbreviation, ThermalConductivityUnit expectedUnit) { - { - Assert.True(ThermalConductivity.TryParseUnit("BTU/(h·ft·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ThermalConductivityUnit.BtuPerHourFootFahrenheit, parsedUnit); - } + ThermalConductivityUnit parsedUnit = ThermalConductivity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ThermalConductivity.TryParseUnit("W/(m·K)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ThermalConductivityUnit.WattPerMeterKelvin, parsedUnit); - } + [Theory] + [InlineData("BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] + [InlineData("W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] + public void TryParseUnit(string abbreviation, ThermalConductivityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ThermalConductivity.TryParseUnit(abbreviation, out ThermalConductivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] + [InlineData("en-US", "W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ThermalConductivityUnit expectedUnit) + { + Assert.True(ThermalConductivity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ThermalConductivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs index 1600222913..e8892b405e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs @@ -315,80 +315,58 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("Hrft²°F/Btu", ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu)] + [InlineData("cm²Hr°C/kcal", ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie)] + [InlineData("cm²K/W", ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt)] + [InlineData("m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] + [InlineData("m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] + [InlineData("m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] + public void ParseUnit(string abbreviation, ThermalInsulanceUnit expectedUnit) { - try - { - var parsedUnit = ThermalInsulance.ParseUnit("Hrft²°F/Btu", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ThermalInsulance.ParseUnit("cm²Hr°C/kcal", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ThermalInsulance.ParseUnit("cm²K/W", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ThermalInsulance.ParseUnit("m²°C/W", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ThermalInsulance.ParseUnit("m²K/kW", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = ThermalInsulance.ParseUnit("m²K/W", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(ThermalInsulanceUnit.SquareMeterKelvinPerWatt, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + ThermalInsulanceUnit parsedUnit = ThermalInsulance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "Hrft²°F/Btu", ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu)] + [InlineData("en-US", "cm²Hr°C/kcal", ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie)] + [InlineData("en-US", "cm²K/W", ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt)] + [InlineData("en-US", "m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] + [InlineData("en-US", "m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] + [InlineData("en-US", "m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] + public void ParseUnitWithCulture(string culture, string abbreviation, ThermalInsulanceUnit expectedUnit) { - { - Assert.True(ThermalInsulance.TryParseUnit("Hrft²°F/Btu", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu, parsedUnit); - } - - { - Assert.True(ThermalInsulance.TryParseUnit("cm²Hr°C/kcal", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie, parsedUnit); - } - - { - Assert.True(ThermalInsulance.TryParseUnit("cm²K/W", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt, parsedUnit); - } - - { - Assert.True(ThermalInsulance.TryParseUnit("m²°C/W", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt, parsedUnit); - } - - { - Assert.True(ThermalInsulance.TryParseUnit("m²K/kW", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt, parsedUnit); - } + ThermalInsulanceUnit parsedUnit = ThermalInsulance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(ThermalInsulance.TryParseUnit("m²K/W", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(ThermalInsulanceUnit.SquareMeterKelvinPerWatt, parsedUnit); - } + [Theory] + [InlineData("Hrft²°F/Btu", ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu)] + [InlineData("cm²Hr°C/kcal", ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie)] + [InlineData("cm²K/W", ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt)] + [InlineData("m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] + [InlineData("m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] + [InlineData("m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] + public void TryParseUnit(string abbreviation, ThermalInsulanceUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(ThermalInsulance.TryParseUnit(abbreviation, out ThermalInsulanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "Hrft²°F/Btu", ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu)] + [InlineData("en-US", "cm²Hr°C/kcal", ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie)] + [InlineData("en-US", "cm²K/W", ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt)] + [InlineData("en-US", "m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] + [InlineData("en-US", "m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] + [InlineData("en-US", "m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] + public void TryParseUnitWithCulture(string culture, string abbreviation, ThermalInsulanceUnit expectedUnit) + { + Assert.True(ThermalInsulance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ThermalInsulanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs index e92e79d831..866544f56e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs @@ -791,322 +791,140 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Torque.ParseUnit("gf·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.GramForceCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("gf·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.GramForceMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("gf·mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.GramForceMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("kgf·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.KilogramForceCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("kgf·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.KilogramForceMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("kgf·mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.KilogramForceMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("kN·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.KilonewtonCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("kN·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.KilonewtonMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("кН·м", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(TorqueUnit.KilonewtonMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("kN·mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.KilonewtonMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("kipf·ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.KilopoundForceFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("kipf·in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.KilopoundForceInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("MN·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.MeganewtonCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("MN·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.MeganewtonMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("МН·м", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(TorqueUnit.MeganewtonMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("MN·mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.MeganewtonMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("Mlbf·ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.MegapoundForceFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("Mlbf·in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.MegapoundForceInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("N·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.NewtonCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("N·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.NewtonMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("Н·м", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(TorqueUnit.NewtonMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("N·mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.NewtonMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("pdl·ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.PoundalFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("lbf·ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.PoundForceFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("lbf·in", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.PoundForceInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("tf·cm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.TonneForceCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("tf·m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.TonneForceMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Torque.ParseUnit("tf·mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TorqueUnit.TonneForceMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("gf·cm", TorqueUnit.GramForceCentimeter)] + [InlineData("gf·m", TorqueUnit.GramForceMeter)] + [InlineData("gf·mm", TorqueUnit.GramForceMillimeter)] + [InlineData("kgf·cm", TorqueUnit.KilogramForceCentimeter)] + [InlineData("kgf·m", TorqueUnit.KilogramForceMeter)] + [InlineData("kgf·mm", TorqueUnit.KilogramForceMillimeter)] + [InlineData("kN·cm", TorqueUnit.KilonewtonCentimeter)] + [InlineData("kN·m", TorqueUnit.KilonewtonMeter)] + [InlineData("kN·mm", TorqueUnit.KilonewtonMillimeter)] + [InlineData("kipf·ft", TorqueUnit.KilopoundForceFoot)] + [InlineData("kipf·in", TorqueUnit.KilopoundForceInch)] + [InlineData("MN·cm", TorqueUnit.MeganewtonCentimeter)] + [InlineData("MN·m", TorqueUnit.MeganewtonMeter)] + [InlineData("MN·mm", TorqueUnit.MeganewtonMillimeter)] + [InlineData("Mlbf·ft", TorqueUnit.MegapoundForceFoot)] + [InlineData("Mlbf·in", TorqueUnit.MegapoundForceInch)] + [InlineData("N·cm", TorqueUnit.NewtonCentimeter)] + [InlineData("N·m", TorqueUnit.NewtonMeter)] + [InlineData("N·mm", TorqueUnit.NewtonMillimeter)] + [InlineData("pdl·ft", TorqueUnit.PoundalFoot)] + [InlineData("lbf·ft", TorqueUnit.PoundForceFoot)] + [InlineData("lbf·in", TorqueUnit.PoundForceInch)] + [InlineData("tf·cm", TorqueUnit.TonneForceCentimeter)] + [InlineData("tf·m", TorqueUnit.TonneForceMeter)] + [InlineData("tf·mm", TorqueUnit.TonneForceMillimeter)] + public void ParseUnit(string abbreviation, TorqueUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + TorqueUnit parsedUnit = Torque.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(Torque.TryParseUnit("gf·cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.GramForceCentimeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("gf·m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.GramForceMeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("gf·mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.GramForceMillimeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("kgf·cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.KilogramForceCentimeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("kgf·m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.KilogramForceMeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("kgf·mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.KilogramForceMillimeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("kN·cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.KilonewtonCentimeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("kN·m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.KilonewtonMeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("кН·м", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(TorqueUnit.KilonewtonMeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("kN·mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.KilonewtonMillimeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("kipf·ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.KilopoundForceFoot, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("kipf·in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.KilopoundForceInch, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("MN·cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.MeganewtonCentimeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("MN·m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.MeganewtonMeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("МН·м", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(TorqueUnit.MeganewtonMeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("MN·mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.MeganewtonMillimeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("Mlbf·ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.MegapoundForceFoot, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("Mlbf·in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.MegapoundForceInch, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("N·cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.NewtonCentimeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("N·m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.NewtonMeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("Н·м", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(TorqueUnit.NewtonMeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("N·mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.NewtonMillimeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("pdl·ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.PoundalFoot, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("lbf·ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.PoundForceFoot, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("lbf·in", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.PoundForceInch, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("tf·cm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.TonneForceCentimeter, parsedUnit); - } - - { - Assert.True(Torque.TryParseUnit("tf·m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.TonneForceMeter, parsedUnit); - } + [Theory] + [InlineData("en-US", "gf·cm", TorqueUnit.GramForceCentimeter)] + [InlineData("en-US", "gf·m", TorqueUnit.GramForceMeter)] + [InlineData("en-US", "gf·mm", TorqueUnit.GramForceMillimeter)] + [InlineData("en-US", "kgf·cm", TorqueUnit.KilogramForceCentimeter)] + [InlineData("en-US", "kgf·m", TorqueUnit.KilogramForceMeter)] + [InlineData("en-US", "kgf·mm", TorqueUnit.KilogramForceMillimeter)] + [InlineData("en-US", "kN·cm", TorqueUnit.KilonewtonCentimeter)] + [InlineData("en-US", "kN·m", TorqueUnit.KilonewtonMeter)] + [InlineData("en-US", "kN·mm", TorqueUnit.KilonewtonMillimeter)] + [InlineData("en-US", "kipf·ft", TorqueUnit.KilopoundForceFoot)] + [InlineData("en-US", "kipf·in", TorqueUnit.KilopoundForceInch)] + [InlineData("en-US", "MN·cm", TorqueUnit.MeganewtonCentimeter)] + [InlineData("en-US", "MN·m", TorqueUnit.MeganewtonMeter)] + [InlineData("en-US", "MN·mm", TorqueUnit.MeganewtonMillimeter)] + [InlineData("en-US", "Mlbf·ft", TorqueUnit.MegapoundForceFoot)] + [InlineData("en-US", "Mlbf·in", TorqueUnit.MegapoundForceInch)] + [InlineData("en-US", "N·cm", TorqueUnit.NewtonCentimeter)] + [InlineData("en-US", "N·m", TorqueUnit.NewtonMeter)] + [InlineData("en-US", "N·mm", TorqueUnit.NewtonMillimeter)] + [InlineData("en-US", "pdl·ft", TorqueUnit.PoundalFoot)] + [InlineData("en-US", "lbf·ft", TorqueUnit.PoundForceFoot)] + [InlineData("en-US", "lbf·in", TorqueUnit.PoundForceInch)] + [InlineData("en-US", "tf·cm", TorqueUnit.TonneForceCentimeter)] + [InlineData("en-US", "tf·m", TorqueUnit.TonneForceMeter)] + [InlineData("en-US", "tf·mm", TorqueUnit.TonneForceMillimeter)] + [InlineData("ru-RU", "кН·м", TorqueUnit.KilonewtonMeter)] + [InlineData("ru-RU", "МН·м", TorqueUnit.MeganewtonMeter)] + [InlineData("ru-RU", "Н·м", TorqueUnit.NewtonMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, TorqueUnit expectedUnit) + { + TorqueUnit parsedUnit = Torque.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Torque.TryParseUnit("tf·mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TorqueUnit.TonneForceMillimeter, parsedUnit); - } + [Theory] + [InlineData("gf·cm", TorqueUnit.GramForceCentimeter)] + [InlineData("gf·m", TorqueUnit.GramForceMeter)] + [InlineData("gf·mm", TorqueUnit.GramForceMillimeter)] + [InlineData("kgf·cm", TorqueUnit.KilogramForceCentimeter)] + [InlineData("kgf·m", TorqueUnit.KilogramForceMeter)] + [InlineData("kgf·mm", TorqueUnit.KilogramForceMillimeter)] + [InlineData("kN·cm", TorqueUnit.KilonewtonCentimeter)] + [InlineData("kN·m", TorqueUnit.KilonewtonMeter)] + [InlineData("kN·mm", TorqueUnit.KilonewtonMillimeter)] + [InlineData("kipf·ft", TorqueUnit.KilopoundForceFoot)] + [InlineData("kipf·in", TorqueUnit.KilopoundForceInch)] + [InlineData("MN·cm", TorqueUnit.MeganewtonCentimeter)] + [InlineData("MN·m", TorqueUnit.MeganewtonMeter)] + [InlineData("MN·mm", TorqueUnit.MeganewtonMillimeter)] + [InlineData("Mlbf·ft", TorqueUnit.MegapoundForceFoot)] + [InlineData("Mlbf·in", TorqueUnit.MegapoundForceInch)] + [InlineData("N·cm", TorqueUnit.NewtonCentimeter)] + [InlineData("N·m", TorqueUnit.NewtonMeter)] + [InlineData("N·mm", TorqueUnit.NewtonMillimeter)] + [InlineData("pdl·ft", TorqueUnit.PoundalFoot)] + [InlineData("lbf·ft", TorqueUnit.PoundForceFoot)] + [InlineData("lbf·in", TorqueUnit.PoundForceInch)] + [InlineData("tf·cm", TorqueUnit.TonneForceCentimeter)] + [InlineData("tf·m", TorqueUnit.TonneForceMeter)] + [InlineData("tf·mm", TorqueUnit.TonneForceMillimeter)] + public void TryParseUnit(string abbreviation, TorqueUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Torque.TryParseUnit(abbreviation, out TorqueUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "gf·cm", TorqueUnit.GramForceCentimeter)] + [InlineData("en-US", "gf·m", TorqueUnit.GramForceMeter)] + [InlineData("en-US", "gf·mm", TorqueUnit.GramForceMillimeter)] + [InlineData("en-US", "kgf·cm", TorqueUnit.KilogramForceCentimeter)] + [InlineData("en-US", "kgf·m", TorqueUnit.KilogramForceMeter)] + [InlineData("en-US", "kgf·mm", TorqueUnit.KilogramForceMillimeter)] + [InlineData("en-US", "kN·cm", TorqueUnit.KilonewtonCentimeter)] + [InlineData("en-US", "kN·m", TorqueUnit.KilonewtonMeter)] + [InlineData("en-US", "kN·mm", TorqueUnit.KilonewtonMillimeter)] + [InlineData("en-US", "kipf·ft", TorqueUnit.KilopoundForceFoot)] + [InlineData("en-US", "kipf·in", TorqueUnit.KilopoundForceInch)] + [InlineData("en-US", "MN·cm", TorqueUnit.MeganewtonCentimeter)] + [InlineData("en-US", "MN·m", TorqueUnit.MeganewtonMeter)] + [InlineData("en-US", "MN·mm", TorqueUnit.MeganewtonMillimeter)] + [InlineData("en-US", "Mlbf·ft", TorqueUnit.MegapoundForceFoot)] + [InlineData("en-US", "Mlbf·in", TorqueUnit.MegapoundForceInch)] + [InlineData("en-US", "N·cm", TorqueUnit.NewtonCentimeter)] + [InlineData("en-US", "N·m", TorqueUnit.NewtonMeter)] + [InlineData("en-US", "N·mm", TorqueUnit.NewtonMillimeter)] + [InlineData("en-US", "pdl·ft", TorqueUnit.PoundalFoot)] + [InlineData("en-US", "lbf·ft", TorqueUnit.PoundForceFoot)] + [InlineData("en-US", "lbf·in", TorqueUnit.PoundForceInch)] + [InlineData("en-US", "tf·cm", TorqueUnit.TonneForceCentimeter)] + [InlineData("en-US", "tf·m", TorqueUnit.TonneForceMeter)] + [InlineData("en-US", "tf·mm", TorqueUnit.TonneForceMillimeter)] + [InlineData("ru-RU", "кН·м", TorqueUnit.KilonewtonMeter)] + [InlineData("ru-RU", "МН·м", TorqueUnit.MeganewtonMeter)] + [InlineData("ru-RU", "Н·м", TorqueUnit.NewtonMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, TorqueUnit expectedUnit) + { + Assert.True(Torque.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TorqueUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs index af7885484b..af7eaa3075 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("NTU", TurbidityUnit.NTU)] + public void ParseUnit(string abbreviation, TurbidityUnit expectedUnit) { - try - { - var parsedUnit = Turbidity.ParseUnit("NTU", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(TurbidityUnit.NTU, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + TurbidityUnit parsedUnit = Turbidity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "NTU", TurbidityUnit.NTU)] + public void ParseUnitWithCulture(string culture, string abbreviation, TurbidityUnit expectedUnit) + { + TurbidityUnit parsedUnit = Turbidity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("NTU", TurbidityUnit.NTU)] + public void TryParseUnit(string abbreviation, TurbidityUnit expectedUnit) { - { - Assert.True(Turbidity.TryParseUnit("NTU", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(TurbidityUnit.NTU, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Turbidity.TryParseUnit(abbreviation, out TurbidityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "NTU", TurbidityUnit.NTU)] + public void TryParseUnitWithCulture(string culture, string abbreviation, TurbidityUnit expectedUnit) + { + Assert.True(Turbidity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TurbidityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs index b0b322b543..21051c7b88 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs @@ -200,25 +200,38 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("IU", VitaminAUnit.InternationalUnit)] + public void ParseUnit(string abbreviation, VitaminAUnit expectedUnit) { - try - { - var parsedUnit = VitaminA.ParseUnit("IU", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VitaminAUnit.InternationalUnit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + VitaminAUnit parsedUnit = VitaminA.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "IU", VitaminAUnit.InternationalUnit)] + public void ParseUnitWithCulture(string culture, string abbreviation, VitaminAUnit expectedUnit) + { + VitaminAUnit parsedUnit = VitaminA.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("IU", VitaminAUnit.InternationalUnit)] + public void TryParseUnit(string abbreviation, VitaminAUnit expectedUnit) { - { - Assert.True(VitaminA.TryParseUnit("IU", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VitaminAUnit.InternationalUnit, parsedUnit); - } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(VitaminA.TryParseUnit(abbreviation, out VitaminAUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "IU", VitaminAUnit.InternationalUnit)] + public void TryParseUnitWithCulture(string culture, string abbreviation, VitaminAUnit expectedUnit) + { + Assert.True(VitaminA.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VitaminAUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs index ed95c3e1b8..3c1afc54fa 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs @@ -650,245 +650,118 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = VolumeConcentration.ParseUnit("cl/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.CentilitersPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("cl/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.CentilitersPerMililiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("dl/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.DecilitersPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("dl/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.DecilitersPerMililiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.DecimalFraction, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("l/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.LitersPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("l/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.LitersPerMililiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("µl/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.MicrolitersPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("µl/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.MicrolitersPerMililiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("ml/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.MillilitersPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("ml/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.MillilitersPerMililiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("nl/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.NanolitersPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("nl/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.NanolitersPerMililiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("ppb", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.PartPerBillion, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("ppm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.PartPerMillion, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("‰", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.PartPerThousand, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("ppt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.PartPerTrillion, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("%", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.Percent, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("% (v/v)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.Percent, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("pl/l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.PicolitersPerLiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeConcentration.ParseUnit("pl/ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeConcentrationUnit.PicolitersPerMililiter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cl/l", VolumeConcentrationUnit.CentilitersPerLiter)] + [InlineData("cl/ml", VolumeConcentrationUnit.CentilitersPerMililiter)] + [InlineData("dl/l", VolumeConcentrationUnit.DecilitersPerLiter)] + [InlineData("dl/ml", VolumeConcentrationUnit.DecilitersPerMililiter)] + [InlineData("", VolumeConcentrationUnit.DecimalFraction)] + [InlineData("l/l", VolumeConcentrationUnit.LitersPerLiter)] + [InlineData("l/ml", VolumeConcentrationUnit.LitersPerMililiter)] + [InlineData("µl/l", VolumeConcentrationUnit.MicrolitersPerLiter)] + [InlineData("µl/ml", VolumeConcentrationUnit.MicrolitersPerMililiter)] + [InlineData("ml/l", VolumeConcentrationUnit.MillilitersPerLiter)] + [InlineData("ml/ml", VolumeConcentrationUnit.MillilitersPerMililiter)] + [InlineData("nl/l", VolumeConcentrationUnit.NanolitersPerLiter)] + [InlineData("nl/ml", VolumeConcentrationUnit.NanolitersPerMililiter)] + [InlineData("ppb", VolumeConcentrationUnit.PartPerBillion)] + [InlineData("ppm", VolumeConcentrationUnit.PartPerMillion)] + [InlineData("‰", VolumeConcentrationUnit.PartPerThousand)] + [InlineData("ppt", VolumeConcentrationUnit.PartPerTrillion)] + [InlineData("%", VolumeConcentrationUnit.Percent)] + [InlineData("% (v/v)", VolumeConcentrationUnit.Percent)] + [InlineData("pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] + [InlineData("pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] + public void ParseUnit(string abbreviation, VolumeConcentrationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + VolumeConcentrationUnit parsedUnit = VolumeConcentration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(VolumeConcentration.TryParseUnit("cl/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.CentilitersPerLiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("cl/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.CentilitersPerMililiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("dl/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.DecilitersPerLiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("dl/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.DecilitersPerMililiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.DecimalFraction, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("l/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.LitersPerLiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("l/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.LitersPerMililiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("µl/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.MicrolitersPerLiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("µl/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.MicrolitersPerMililiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("ml/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.MillilitersPerLiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("ml/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.MillilitersPerMililiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("nl/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.NanolitersPerLiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("nl/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.NanolitersPerMililiter, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("ppb", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.PartPerBillion, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("ppm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.PartPerMillion, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("‰", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.PartPerThousand, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("ppt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.PartPerTrillion, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("%", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.Percent, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("% (v/v)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.Percent, parsedUnit); - } - - { - Assert.True(VolumeConcentration.TryParseUnit("pl/l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.PicolitersPerLiter, parsedUnit); - } + [Theory] + [InlineData("en-US", "cl/l", VolumeConcentrationUnit.CentilitersPerLiter)] + [InlineData("en-US", "cl/ml", VolumeConcentrationUnit.CentilitersPerMililiter)] + [InlineData("en-US", "dl/l", VolumeConcentrationUnit.DecilitersPerLiter)] + [InlineData("en-US", "dl/ml", VolumeConcentrationUnit.DecilitersPerMililiter)] + [InlineData("en-US", "", VolumeConcentrationUnit.DecimalFraction)] + [InlineData("en-US", "l/l", VolumeConcentrationUnit.LitersPerLiter)] + [InlineData("en-US", "l/ml", VolumeConcentrationUnit.LitersPerMililiter)] + [InlineData("en-US", "µl/l", VolumeConcentrationUnit.MicrolitersPerLiter)] + [InlineData("en-US", "µl/ml", VolumeConcentrationUnit.MicrolitersPerMililiter)] + [InlineData("en-US", "ml/l", VolumeConcentrationUnit.MillilitersPerLiter)] + [InlineData("en-US", "ml/ml", VolumeConcentrationUnit.MillilitersPerMililiter)] + [InlineData("en-US", "nl/l", VolumeConcentrationUnit.NanolitersPerLiter)] + [InlineData("en-US", "nl/ml", VolumeConcentrationUnit.NanolitersPerMililiter)] + [InlineData("en-US", "ppb", VolumeConcentrationUnit.PartPerBillion)] + [InlineData("en-US", "ppm", VolumeConcentrationUnit.PartPerMillion)] + [InlineData("en-US", "‰", VolumeConcentrationUnit.PartPerThousand)] + [InlineData("en-US", "ppt", VolumeConcentrationUnit.PartPerTrillion)] + [InlineData("en-US", "%", VolumeConcentrationUnit.Percent)] + [InlineData("en-US", "% (v/v)", VolumeConcentrationUnit.Percent)] + [InlineData("en-US", "pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] + [InlineData("en-US", "pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] + public void ParseUnitWithCulture(string culture, string abbreviation, VolumeConcentrationUnit expectedUnit) + { + VolumeConcentrationUnit parsedUnit = VolumeConcentration.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(VolumeConcentration.TryParseUnit("pl/ml", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeConcentrationUnit.PicolitersPerMililiter, parsedUnit); - } + [Theory] + [InlineData("cl/l", VolumeConcentrationUnit.CentilitersPerLiter)] + [InlineData("cl/ml", VolumeConcentrationUnit.CentilitersPerMililiter)] + [InlineData("dl/l", VolumeConcentrationUnit.DecilitersPerLiter)] + [InlineData("dl/ml", VolumeConcentrationUnit.DecilitersPerMililiter)] + [InlineData("", VolumeConcentrationUnit.DecimalFraction)] + [InlineData("l/l", VolumeConcentrationUnit.LitersPerLiter)] + [InlineData("l/ml", VolumeConcentrationUnit.LitersPerMililiter)] + [InlineData("µl/l", VolumeConcentrationUnit.MicrolitersPerLiter)] + [InlineData("µl/ml", VolumeConcentrationUnit.MicrolitersPerMililiter)] + [InlineData("ml/l", VolumeConcentrationUnit.MillilitersPerLiter)] + [InlineData("ml/ml", VolumeConcentrationUnit.MillilitersPerMililiter)] + [InlineData("nl/l", VolumeConcentrationUnit.NanolitersPerLiter)] + [InlineData("nl/ml", VolumeConcentrationUnit.NanolitersPerMililiter)] + [InlineData("ppb", VolumeConcentrationUnit.PartPerBillion)] + [InlineData("ppm", VolumeConcentrationUnit.PartPerMillion)] + [InlineData("‰", VolumeConcentrationUnit.PartPerThousand)] + [InlineData("ppt", VolumeConcentrationUnit.PartPerTrillion)] + [InlineData("%", VolumeConcentrationUnit.Percent)] + [InlineData("% (v/v)", VolumeConcentrationUnit.Percent)] + [InlineData("pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] + [InlineData("pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] + public void TryParseUnit(string abbreviation, VolumeConcentrationUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(VolumeConcentration.TryParseUnit(abbreviation, out VolumeConcentrationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cl/l", VolumeConcentrationUnit.CentilitersPerLiter)] + [InlineData("en-US", "cl/ml", VolumeConcentrationUnit.CentilitersPerMililiter)] + [InlineData("en-US", "dl/l", VolumeConcentrationUnit.DecilitersPerLiter)] + [InlineData("en-US", "dl/ml", VolumeConcentrationUnit.DecilitersPerMililiter)] + [InlineData("en-US", "", VolumeConcentrationUnit.DecimalFraction)] + [InlineData("en-US", "l/l", VolumeConcentrationUnit.LitersPerLiter)] + [InlineData("en-US", "l/ml", VolumeConcentrationUnit.LitersPerMililiter)] + [InlineData("en-US", "µl/l", VolumeConcentrationUnit.MicrolitersPerLiter)] + [InlineData("en-US", "µl/ml", VolumeConcentrationUnit.MicrolitersPerMililiter)] + [InlineData("en-US", "ml/l", VolumeConcentrationUnit.MillilitersPerLiter)] + [InlineData("en-US", "ml/ml", VolumeConcentrationUnit.MillilitersPerMililiter)] + [InlineData("en-US", "nl/l", VolumeConcentrationUnit.NanolitersPerLiter)] + [InlineData("en-US", "nl/ml", VolumeConcentrationUnit.NanolitersPerMililiter)] + [InlineData("en-US", "ppb", VolumeConcentrationUnit.PartPerBillion)] + [InlineData("en-US", "ppm", VolumeConcentrationUnit.PartPerMillion)] + [InlineData("en-US", "‰", VolumeConcentrationUnit.PartPerThousand)] + [InlineData("en-US", "ppt", VolumeConcentrationUnit.PartPerTrillion)] + [InlineData("en-US", "%", VolumeConcentrationUnit.Percent)] + [InlineData("en-US", "% (v/v)", VolumeConcentrationUnit.Percent)] + [InlineData("en-US", "pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] + [InlineData("en-US", "pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, VolumeConcentrationUnit expectedUnit) + { + Assert.True(VolumeConcentration.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumeConcentrationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs index 20f00728d4..988677a08b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs @@ -223,36 +223,42 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] + [InlineData("m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] + public void ParseUnit(string abbreviation, VolumeFlowPerAreaUnit expectedUnit) { - try - { - var parsedUnit = VolumeFlowPerArea.ParseUnit("CFM/ft²", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlowPerArea.ParseUnit("m³/(s·m²)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + VolumeFlowPerAreaUnit parsedUnit = VolumeFlowPerArea.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] + [InlineData("en-US", "m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] + public void ParseUnitWithCulture(string culture, string abbreviation, VolumeFlowPerAreaUnit expectedUnit) { - { - Assert.True(VolumeFlowPerArea.TryParseUnit("CFM/ft²", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot, parsedUnit); - } + VolumeFlowPerAreaUnit parsedUnit = VolumeFlowPerArea.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(VolumeFlowPerArea.TryParseUnit("m³/(s·m²)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter, parsedUnit); - } + [Theory] + [InlineData("CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] + [InlineData("m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] + public void TryParseUnit(string abbreviation, VolumeFlowPerAreaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(VolumeFlowPerArea.TryParseUnit(abbreviation, out VolumeFlowPerAreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] + [InlineData("en-US", "m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] + public void TryParseUnitWithCulture(string culture, string abbreviation, VolumeFlowPerAreaUnit expectedUnit) + { + Assert.True(VolumeFlowPerArea.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumeFlowPerAreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs index 9986be1820..659c56203f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs @@ -2993,1764 +2993,642 @@ public void TryParse() } - [Fact] - public void ParseUnit() + [Theory] + [InlineData("af/d", VolumeFlowUnit.AcreFootPerDay)] + [InlineData("af/h", VolumeFlowUnit.AcreFootPerHour)] + [InlineData("af/m", VolumeFlowUnit.AcreFootPerMinute)] + [InlineData("af/s", VolumeFlowUnit.AcreFootPerSecond)] + [InlineData("cl/day", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cl/d", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cLPD", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cl/h", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("cLPH", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("cl/min", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("cLPM", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("cl/s", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("cLPS", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("ft³/h", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("cf/hr", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("ft³/min", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("CFM", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("ft³/s", VolumeFlowUnit.CubicFootPerSecond)] + [InlineData("m³/d", VolumeFlowUnit.CubicMeterPerDay)] + [InlineData("m³/h", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("m³/min", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("m³/s", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("cy/day", VolumeFlowUnit.CubicYardPerDay)] + [InlineData("yd³/h", VolumeFlowUnit.CubicYardPerHour)] + [InlineData("yd³/min", VolumeFlowUnit.CubicYardPerMinute)] + [InlineData("yd³/s", VolumeFlowUnit.CubicYardPerSecond)] + [InlineData("dal/day", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("dal/d", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("daLPD", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("dal/h", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("daLPH", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("dal/min", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("daLPM", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("dal/s", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("daLPS", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("dl/day", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dl/d", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dLPD", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dl/h", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("dLPH", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("dl/min", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("dLPM", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("dl/s", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("dLPS", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("hl/day", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hl/d", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hLPD", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hl/h", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("hLPH", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("hl/min", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("hLPM", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("hl/s", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("hLPS", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("kl/day", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kl/d", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kLPD", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kl/h", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("kLPH", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("kl/min", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("kLPM", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("kl/s", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("kLPS", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("KGPM", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("l/day", VolumeFlowUnit.LiterPerDay)] + [InlineData("l/d", VolumeFlowUnit.LiterPerDay)] + [InlineData("LPD", VolumeFlowUnit.LiterPerDay)] + [InlineData("l/h", VolumeFlowUnit.LiterPerHour)] + [InlineData("LPH", VolumeFlowUnit.LiterPerHour)] + [InlineData("l/min", VolumeFlowUnit.LiterPerMinute)] + [InlineData("LPM", VolumeFlowUnit.LiterPerMinute)] + [InlineData("l/s", VolumeFlowUnit.LiterPerSecond)] + [InlineData("LPS", VolumeFlowUnit.LiterPerSecond)] + [InlineData("Ml/day", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("Ml/d", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("MLPD", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("Ml/h", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("MLPH", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("Ml/min", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("MLPM", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("Ml/s", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("MLPS", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay)] + [InlineData("Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond)] + [InlineData("Mgpd", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("Mgal/d", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("µl/day", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µl/d", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µLPD", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µl/h", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("µLPH", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("µl/min", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("µLPM", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("µl/s", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("µLPS", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("ml/day", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("ml/d", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("mLPD", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("ml/h", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("mLPH", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("ml/min", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("mLPM", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("ml/s", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("mLPS", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("MGD", VolumeFlowUnit.MillionUsGallonPerDay)] + [InlineData("nl/day", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nl/d", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nLPD", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nl/h", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("nLPH", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("nl/min", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("nLPM", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("nl/s", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("nLPS", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("bbl/d", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("BOPD", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("bbl/hr", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("bph", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("bbl/min", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("bpm", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("bbl/s", VolumeFlowUnit.OilBarrelPerSecond)] + [InlineData("gal (U. K.)/d", VolumeFlowUnit.UkGallonPerDay)] + [InlineData("gal (imp.)/h", VolumeFlowUnit.UkGallonPerHour)] + [InlineData("gal (imp.)/min", VolumeFlowUnit.UkGallonPerMinute)] + [InlineData("gal (imp.)/s", VolumeFlowUnit.UkGallonPerSecond)] + [InlineData("gpd", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("gal/d", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("gal (U.S.)/h", VolumeFlowUnit.UsGallonPerHour)] + [InlineData("gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("GPM", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond)] + public void ParseUnit(string abbreviation, VolumeFlowUnit expectedUnit) { - try - { - var parsedUnit = VolumeFlow.ParseUnit("af/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.AcreFootPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("af/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.AcreFootPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("af/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.AcreFootPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("af/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.AcreFootPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cl/day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cl/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cLPD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cl/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cLPH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("сл/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cl/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cLPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("сл/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cl/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cLPS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("сл/c", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cm³/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicCentimeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("см³/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.CubicCentimeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dm³/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicDecimeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("дм³/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.CubicDecimeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("ft³/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicFootPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cf/hr", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicFootPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("ft³/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicFootPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("CFM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicFootPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("ft³/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicFootPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("m³/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicMeterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("m³/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicMeterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("м³/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.CubicMeterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("m³/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicMeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("м³/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.CubicMeterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("m³/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicMeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("м³/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.CubicMeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("mm³/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicMillimeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("мм³/с", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.CubicMillimeterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("cy/day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicYardPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("yd³/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicYardPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("yd³/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicYardPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("yd³/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.CubicYardPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dal/day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dal/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("daLPD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dal/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("daLPH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("дал/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dal/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("daLPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("дал/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dal/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("daLPS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("дал/c", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dl/day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dl/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dLPD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dl/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dLPH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("дл/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dl/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dLPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("дл/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("dl/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + VolumeFlowUnit parsedUnit = VolumeFlow.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } - try - { - var parsedUnit = VolumeFlow.ParseUnit("dLPS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } + [Theory] + [InlineData("en-US", "af/d", VolumeFlowUnit.AcreFootPerDay)] + [InlineData("en-US", "af/h", VolumeFlowUnit.AcreFootPerHour)] + [InlineData("en-US", "af/m", VolumeFlowUnit.AcreFootPerMinute)] + [InlineData("en-US", "af/s", VolumeFlowUnit.AcreFootPerSecond)] + [InlineData("en-US", "cl/day", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cl/d", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cLPD", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cl/h", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("en-US", "cLPH", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("en-US", "cl/min", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("en-US", "cLPM", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("en-US", "cl/s", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("en-US", "cLPS", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("en-US", "cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("en-US", "dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("en-US", "ft³/h", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("en-US", "cf/hr", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("en-US", "ft³/min", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("en-US", "CFM", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("en-US", "ft³/s", VolumeFlowUnit.CubicFootPerSecond)] + [InlineData("en-US", "m³/d", VolumeFlowUnit.CubicMeterPerDay)] + [InlineData("en-US", "m³/h", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("en-US", "m³/min", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("en-US", "m³/s", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("en-US", "mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("en-US", "cy/day", VolumeFlowUnit.CubicYardPerDay)] + [InlineData("en-US", "yd³/h", VolumeFlowUnit.CubicYardPerHour)] + [InlineData("en-US", "yd³/min", VolumeFlowUnit.CubicYardPerMinute)] + [InlineData("en-US", "yd³/s", VolumeFlowUnit.CubicYardPerSecond)] + [InlineData("en-US", "dal/day", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "dal/d", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "daLPD", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "dal/h", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("en-US", "daLPH", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("en-US", "dal/min", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("en-US", "daLPM", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("en-US", "dal/s", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("en-US", "daLPS", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("en-US", "dl/day", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dl/d", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dLPD", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dl/h", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("en-US", "dLPH", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("en-US", "dl/min", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("en-US", "dLPM", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("en-US", "dl/s", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("en-US", "dLPS", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("en-US", "hl/day", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hl/d", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hLPD", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hl/h", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("en-US", "hLPH", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("en-US", "hl/min", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("en-US", "hLPM", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("en-US", "hl/s", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("en-US", "hLPS", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("en-US", "kl/day", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kl/d", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kLPD", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kl/h", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("en-US", "kLPH", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("en-US", "kl/min", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("en-US", "kLPM", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("en-US", "kl/s", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("en-US", "kLPS", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("en-US", "kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("en-US", "KGPM", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("en-US", "l/day", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "l/d", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "LPD", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "l/h", VolumeFlowUnit.LiterPerHour)] + [InlineData("en-US", "LPH", VolumeFlowUnit.LiterPerHour)] + [InlineData("en-US", "l/min", VolumeFlowUnit.LiterPerMinute)] + [InlineData("en-US", "LPM", VolumeFlowUnit.LiterPerMinute)] + [InlineData("en-US", "l/s", VolumeFlowUnit.LiterPerSecond)] + [InlineData("en-US", "LPS", VolumeFlowUnit.LiterPerSecond)] + [InlineData("en-US", "Ml/day", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "Ml/d", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "MLPD", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "Ml/h", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("en-US", "MLPH", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("en-US", "Ml/min", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("en-US", "MLPM", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("en-US", "Ml/s", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("en-US", "MLPS", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("en-US", "Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay)] + [InlineData("en-US", "Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond)] + [InlineData("en-US", "Mgpd", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("en-US", "Mgal/d", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("en-US", "µl/day", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µl/d", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µLPD", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µl/h", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("en-US", "µLPH", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("en-US", "µl/min", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("en-US", "µLPM", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("en-US", "µl/s", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("en-US", "µLPS", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("en-US", "ml/day", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "ml/d", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "mLPD", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "ml/h", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("en-US", "mLPH", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("en-US", "ml/min", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("en-US", "mLPM", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("en-US", "ml/s", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("en-US", "mLPS", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("en-US", "MGD", VolumeFlowUnit.MillionUsGallonPerDay)] + [InlineData("en-US", "nl/day", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nl/d", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nLPD", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nl/h", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("en-US", "nLPH", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("en-US", "nl/min", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("en-US", "nLPM", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("en-US", "nl/s", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("en-US", "nLPS", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("en-US", "bbl/d", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("en-US", "BOPD", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("en-US", "bbl/hr", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("en-US", "bph", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("en-US", "bbl/min", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("en-US", "bpm", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("en-US", "bbl/s", VolumeFlowUnit.OilBarrelPerSecond)] + [InlineData("en-US", "gal (U. K.)/d", VolumeFlowUnit.UkGallonPerDay)] + [InlineData("en-US", "gal (imp.)/h", VolumeFlowUnit.UkGallonPerHour)] + [InlineData("en-US", "gal (imp.)/min", VolumeFlowUnit.UkGallonPerMinute)] + [InlineData("en-US", "gal (imp.)/s", VolumeFlowUnit.UkGallonPerSecond)] + [InlineData("en-US", "gpd", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("en-US", "gal/d", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("en-US", "gal (U.S.)/h", VolumeFlowUnit.UsGallonPerHour)] + [InlineData("en-US", "gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("en-US", "GPM", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("en-US", "gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond)] + [InlineData("ru-RU", "сл/ч", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("ru-RU", "сл/мин", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("ru-RU", "сл/c", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("ru-RU", "см³/мин", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("ru-RU", "дм³/мин", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("ru-RU", "м³/ч", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("ru-RU", "м³/мин", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("ru-RU", "м³/с", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("ru-RU", "мм³/с", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("ru-RU", "дал/ч", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("ru-RU", "дал/мин", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("ru-RU", "дал/c", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("ru-RU", "дл/ч", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("ru-RU", "дл/мин", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("ru-RU", "дл/c", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("ru-RU", "гл/ч", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("ru-RU", "гл/мин", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("ru-RU", "гл/c", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("ru-RU", "кл/ч", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("ru-RU", "кл/мин", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("ru-RU", "кл/c", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("ru-RU", "л/ч", VolumeFlowUnit.LiterPerHour)] + [InlineData("ru-RU", "л/мин", VolumeFlowUnit.LiterPerMinute)] + [InlineData("ru-RU", "л/c", VolumeFlowUnit.LiterPerSecond)] + [InlineData("ru-RU", "Мл/ч", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("ru-RU", "Мл/мин", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("ru-RU", "Мл/c", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("ru-RU", "мкл/ч", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("ru-RU", "мкл/мин", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("ru-RU", "мкл/c", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("ru-RU", "мл/ч", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("ru-RU", "мл/мин", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("ru-RU", "мл/c", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("ru-RU", "нл/ч", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("ru-RU", "нл/мин", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("ru-RU", "нл/c", VolumeFlowUnit.NanoliterPerSecond)] + public void ParseUnitWithCulture(string culture, string abbreviation, VolumeFlowUnit expectedUnit) + { + VolumeFlowUnit parsedUnit = VolumeFlow.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - try - { - var parsedUnit = VolumeFlow.ParseUnit("дл/c", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("hl/day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("hl/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("hLPD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("hl/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("hLPH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("гл/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("hl/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("hLPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("гл/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("hl/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("hLPS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("гл/c", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("kl/day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("kl/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("kLPD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("kl/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("kLPH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("кл/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("kl/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("kLPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("кл/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("kl/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("kLPS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("кл/c", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("kgal (U.S.)/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.KilousGallonPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("KGPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.KilousGallonPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("l/day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("l/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("LPD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("l/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("LPH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("л/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("l/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("LPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("л/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("l/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("LPS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("л/c", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Ml/day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegaliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Ml/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegaliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("MLPD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegaliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Ml/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegaliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("MLPH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegaliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Мл/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.MegaliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Ml/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegaliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("MLPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegaliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Мл/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.MegaliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Ml/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegaliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("MLPS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegaliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Мл/c", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.MegaliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Mgal (U. K.)/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegaukGallonPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Mgal (imp.)/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegaukGallonPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Mgpd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegausGallonPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("Mgal/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MegausGallonPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("µl/day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("µl/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("µLPD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("µl/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("µLPH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("мкл/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("µl/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("µLPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("мкл/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("µl/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("µLPS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("мкл/c", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("ml/day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MilliliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("ml/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MilliliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("mLPD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MilliliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("ml/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MilliliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("mLPH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MilliliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("мл/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.MilliliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("ml/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MilliliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("mLPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MilliliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("мл/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.MilliliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("ml/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MilliliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("mLPS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MilliliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("мл/c", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.MilliliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("MGD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.MillionUsGallonPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("nl/day", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("nl/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("nLPD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("nl/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("nLPH", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("нл/ч", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("nl/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("nLPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("нл/мин", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("nl/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("nLPS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("нл/c", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("bbl/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.OilBarrelPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("BOPD", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.OilBarrelPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("bbl/hr", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.OilBarrelPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("bph", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.OilBarrelPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("bbl/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.OilBarrelPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("bpm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.OilBarrelPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("bbl/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.OilBarrelPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("gal (U. K.)/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.UkGallonPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("gal (imp.)/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.UkGallonPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("gal (imp.)/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.UkGallonPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("gal (imp.)/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.UkGallonPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("gpd", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.UsGallonPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("gal/d", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.UsGallonPerDay, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("gal (U.S.)/h", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.UsGallonPerHour, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("gal (U.S.)/min", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.UsGallonPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("GPM", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.UsGallonPerMinute, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumeFlow.ParseUnit("gal (U.S.)/s", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeFlowUnit.UsGallonPerSecond, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParseUnit() - { - { - Assert.True(VolumeFlow.TryParseUnit("af/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.AcreFootPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("af/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.AcreFootPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("af/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.AcreFootPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("af/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.AcreFootPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cl/day", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cl/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cLPD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cl/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cLPH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("сл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cl/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cLPM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("сл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cl/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cLPS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("сл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CentiliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cm³/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicCentimeterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("см³/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicCentimeterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dm³/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicDecimeterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("дм³/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicDecimeterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("ft³/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicFootPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cf/hr", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicFootPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("ft³/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicFootPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("CFM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicFootPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("ft³/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicFootPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("m³/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicMeterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("m³/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicMeterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("м³/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicMeterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("m³/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicMeterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("м³/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicMeterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("m³/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicMeterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("м³/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicMeterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("mm³/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicMillimeterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("мм³/с", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicMillimeterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("cy/day", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicYardPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("yd³/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicYardPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("yd³/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicYardPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("yd³/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.CubicYardPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dal/day", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dal/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("daLPD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dal/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("daLPH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("дал/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dal/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("daLPM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("дал/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dal/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("daLPS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("дал/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DecaliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dl/day", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dl/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dLPD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dl/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dLPH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("дл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dl/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dLPM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("дл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dl/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("dLPS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("дл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.DeciliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("hl/day", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("hl/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("hLPD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("hl/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("hLPH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("гл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("hl/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("hLPM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("гл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("hl/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("hLPS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("гл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.HectoliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("kl/day", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("kl/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("kLPD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("kl/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("kLPH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("кл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("kl/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("kLPM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("кл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("kl/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("kLPS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("кл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KiloliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("kgal (U.S.)/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KilousGallonPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("KGPM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.KilousGallonPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("l/day", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("l/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("LPD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("l/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("LPH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("л/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("l/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("LPM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("л/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("l/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("LPS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("л/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.LiterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("Mgal (U. K.)/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MegaukGallonPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("Mgal (imp.)/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MegaukGallonPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("Mgpd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MegausGallonPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("Mgal/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MegausGallonPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("µl/day", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("µl/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("µLPD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("µl/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("µLPH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("мкл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("µl/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("µLPM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("мкл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("µl/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("µLPS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("мкл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MicroliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("MGD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.MillionUsGallonPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("nl/day", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("nl/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("nLPD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("nl/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("nLPH", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("нл/ч", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("nl/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("nLPM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("нл/мин", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("nl/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("nLPS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("нл/c", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.NanoliterPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("bbl/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.OilBarrelPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("BOPD", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.OilBarrelPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("bbl/hr", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.OilBarrelPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("bph", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.OilBarrelPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("bbl/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.OilBarrelPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("bpm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.OilBarrelPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("bbl/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.OilBarrelPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("gal (U. K.)/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.UkGallonPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("gal (imp.)/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.UkGallonPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("gal (imp.)/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.UkGallonPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("gal (imp.)/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.UkGallonPerSecond, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("gpd", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.UsGallonPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("gal/d", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.UsGallonPerDay, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("gal (U.S.)/h", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.UsGallonPerHour, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("gal (U.S.)/min", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.UsGallonPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("GPM", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.UsGallonPerMinute, parsedUnit); - } - - { - Assert.True(VolumeFlow.TryParseUnit("gal (U.S.)/s", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeFlowUnit.UsGallonPerSecond, parsedUnit); - } + [Theory] + [InlineData("af/d", VolumeFlowUnit.AcreFootPerDay)] + [InlineData("af/h", VolumeFlowUnit.AcreFootPerHour)] + [InlineData("af/m", VolumeFlowUnit.AcreFootPerMinute)] + [InlineData("af/s", VolumeFlowUnit.AcreFootPerSecond)] + [InlineData("cl/day", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cl/d", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cLPD", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cl/h", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("cLPH", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("cl/min", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("cLPM", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("cl/s", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("cLPS", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("ft³/h", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("cf/hr", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("ft³/min", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("CFM", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("ft³/s", VolumeFlowUnit.CubicFootPerSecond)] + [InlineData("m³/d", VolumeFlowUnit.CubicMeterPerDay)] + [InlineData("m³/h", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("m³/min", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("m³/s", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("cy/day", VolumeFlowUnit.CubicYardPerDay)] + [InlineData("yd³/h", VolumeFlowUnit.CubicYardPerHour)] + [InlineData("yd³/min", VolumeFlowUnit.CubicYardPerMinute)] + [InlineData("yd³/s", VolumeFlowUnit.CubicYardPerSecond)] + [InlineData("dal/day", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("dal/d", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("daLPD", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("dal/h", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("daLPH", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("dal/min", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("daLPM", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("dal/s", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("daLPS", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("dl/day", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dl/d", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dLPD", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dl/h", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("dLPH", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("dl/min", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("dLPM", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("dl/s", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("dLPS", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("hl/day", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hl/d", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hLPD", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hl/h", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("hLPH", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("hl/min", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("hLPM", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("hl/s", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("hLPS", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("kl/day", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kl/d", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kLPD", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kl/h", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("kLPH", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("kl/min", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("kLPM", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("kl/s", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("kLPS", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("KGPM", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("l/day", VolumeFlowUnit.LiterPerDay)] + [InlineData("l/d", VolumeFlowUnit.LiterPerDay)] + [InlineData("LPD", VolumeFlowUnit.LiterPerDay)] + [InlineData("l/h", VolumeFlowUnit.LiterPerHour)] + [InlineData("LPH", VolumeFlowUnit.LiterPerHour)] + [InlineData("l/min", VolumeFlowUnit.LiterPerMinute)] + [InlineData("LPM", VolumeFlowUnit.LiterPerMinute)] + [InlineData("l/s", VolumeFlowUnit.LiterPerSecond)] + [InlineData("LPS", VolumeFlowUnit.LiterPerSecond)] + [InlineData("Ml/day", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("Ml/d", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("MLPD", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("Ml/h", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("MLPH", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("Ml/min", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("MLPM", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("Ml/s", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("MLPS", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay)] + [InlineData("Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond)] + [InlineData("Mgpd", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("Mgal/d", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("µl/day", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µl/d", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µLPD", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µl/h", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("µLPH", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("µl/min", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("µLPM", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("µl/s", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("µLPS", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("ml/day", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("ml/d", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("mLPD", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("ml/h", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("mLPH", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("ml/min", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("mLPM", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("ml/s", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("mLPS", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("MGD", VolumeFlowUnit.MillionUsGallonPerDay)] + [InlineData("nl/day", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nl/d", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nLPD", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nl/h", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("nLPH", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("nl/min", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("nLPM", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("nl/s", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("nLPS", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("bbl/d", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("BOPD", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("bbl/hr", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("bph", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("bbl/min", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("bpm", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("bbl/s", VolumeFlowUnit.OilBarrelPerSecond)] + [InlineData("gal (U. K.)/d", VolumeFlowUnit.UkGallonPerDay)] + [InlineData("gal (imp.)/h", VolumeFlowUnit.UkGallonPerHour)] + [InlineData("gal (imp.)/min", VolumeFlowUnit.UkGallonPerMinute)] + [InlineData("gal (imp.)/s", VolumeFlowUnit.UkGallonPerSecond)] + [InlineData("gpd", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("gal/d", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("gal (U.S.)/h", VolumeFlowUnit.UsGallonPerHour)] + [InlineData("gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("GPM", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond)] + public void TryParseUnit(string abbreviation, VolumeFlowUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(VolumeFlow.TryParseUnit(abbreviation, out VolumeFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "af/d", VolumeFlowUnit.AcreFootPerDay)] + [InlineData("en-US", "af/h", VolumeFlowUnit.AcreFootPerHour)] + [InlineData("en-US", "af/m", VolumeFlowUnit.AcreFootPerMinute)] + [InlineData("en-US", "af/s", VolumeFlowUnit.AcreFootPerSecond)] + [InlineData("en-US", "cl/day", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cl/d", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cLPD", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cl/h", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("en-US", "cLPH", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("en-US", "cl/min", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("en-US", "cLPM", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("en-US", "cl/s", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("en-US", "cLPS", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("en-US", "cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("en-US", "dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("en-US", "ft³/h", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("en-US", "cf/hr", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("en-US", "ft³/min", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("en-US", "CFM", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("en-US", "ft³/s", VolumeFlowUnit.CubicFootPerSecond)] + [InlineData("en-US", "m³/d", VolumeFlowUnit.CubicMeterPerDay)] + [InlineData("en-US", "m³/h", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("en-US", "m³/min", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("en-US", "m³/s", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("en-US", "mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("en-US", "cy/day", VolumeFlowUnit.CubicYardPerDay)] + [InlineData("en-US", "yd³/h", VolumeFlowUnit.CubicYardPerHour)] + [InlineData("en-US", "yd³/min", VolumeFlowUnit.CubicYardPerMinute)] + [InlineData("en-US", "yd³/s", VolumeFlowUnit.CubicYardPerSecond)] + [InlineData("en-US", "dal/day", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "dal/d", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "daLPD", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "dal/h", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("en-US", "daLPH", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("en-US", "dal/min", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("en-US", "daLPM", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("en-US", "dal/s", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("en-US", "daLPS", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("en-US", "dl/day", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dl/d", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dLPD", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dl/h", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("en-US", "dLPH", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("en-US", "dl/min", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("en-US", "dLPM", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("en-US", "dl/s", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("en-US", "dLPS", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("en-US", "hl/day", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hl/d", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hLPD", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hl/h", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("en-US", "hLPH", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("en-US", "hl/min", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("en-US", "hLPM", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("en-US", "hl/s", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("en-US", "hLPS", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("en-US", "kl/day", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kl/d", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kLPD", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kl/h", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("en-US", "kLPH", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("en-US", "kl/min", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("en-US", "kLPM", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("en-US", "kl/s", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("en-US", "kLPS", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("en-US", "kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("en-US", "KGPM", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("en-US", "l/day", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "l/d", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "LPD", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "l/h", VolumeFlowUnit.LiterPerHour)] + [InlineData("en-US", "LPH", VolumeFlowUnit.LiterPerHour)] + [InlineData("en-US", "l/min", VolumeFlowUnit.LiterPerMinute)] + [InlineData("en-US", "LPM", VolumeFlowUnit.LiterPerMinute)] + [InlineData("en-US", "l/s", VolumeFlowUnit.LiterPerSecond)] + [InlineData("en-US", "LPS", VolumeFlowUnit.LiterPerSecond)] + [InlineData("en-US", "Ml/day", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "Ml/d", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "MLPD", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "Ml/h", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("en-US", "MLPH", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("en-US", "Ml/min", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("en-US", "MLPM", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("en-US", "Ml/s", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("en-US", "MLPS", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("en-US", "Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay)] + [InlineData("en-US", "Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond)] + [InlineData("en-US", "Mgpd", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("en-US", "Mgal/d", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("en-US", "µl/day", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µl/d", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µLPD", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µl/h", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("en-US", "µLPH", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("en-US", "µl/min", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("en-US", "µLPM", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("en-US", "µl/s", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("en-US", "µLPS", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("en-US", "ml/day", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "ml/d", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "mLPD", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "ml/h", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("en-US", "mLPH", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("en-US", "ml/min", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("en-US", "mLPM", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("en-US", "ml/s", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("en-US", "mLPS", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("en-US", "MGD", VolumeFlowUnit.MillionUsGallonPerDay)] + [InlineData("en-US", "nl/day", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nl/d", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nLPD", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nl/h", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("en-US", "nLPH", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("en-US", "nl/min", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("en-US", "nLPM", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("en-US", "nl/s", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("en-US", "nLPS", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("en-US", "bbl/d", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("en-US", "BOPD", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("en-US", "bbl/hr", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("en-US", "bph", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("en-US", "bbl/min", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("en-US", "bpm", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("en-US", "bbl/s", VolumeFlowUnit.OilBarrelPerSecond)] + [InlineData("en-US", "gal (U. K.)/d", VolumeFlowUnit.UkGallonPerDay)] + [InlineData("en-US", "gal (imp.)/h", VolumeFlowUnit.UkGallonPerHour)] + [InlineData("en-US", "gal (imp.)/min", VolumeFlowUnit.UkGallonPerMinute)] + [InlineData("en-US", "gal (imp.)/s", VolumeFlowUnit.UkGallonPerSecond)] + [InlineData("en-US", "gpd", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("en-US", "gal/d", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("en-US", "gal (U.S.)/h", VolumeFlowUnit.UsGallonPerHour)] + [InlineData("en-US", "gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("en-US", "GPM", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("en-US", "gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond)] + [InlineData("ru-RU", "сл/ч", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("ru-RU", "сл/мин", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("ru-RU", "сл/c", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("ru-RU", "см³/мин", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("ru-RU", "дм³/мин", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("ru-RU", "м³/ч", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("ru-RU", "м³/мин", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("ru-RU", "м³/с", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("ru-RU", "мм³/с", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("ru-RU", "дал/ч", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("ru-RU", "дал/мин", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("ru-RU", "дал/c", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("ru-RU", "дл/ч", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("ru-RU", "дл/мин", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("ru-RU", "дл/c", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("ru-RU", "гл/ч", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("ru-RU", "гл/мин", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("ru-RU", "гл/c", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("ru-RU", "кл/ч", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("ru-RU", "кл/мин", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("ru-RU", "кл/c", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("ru-RU", "л/ч", VolumeFlowUnit.LiterPerHour)] + [InlineData("ru-RU", "л/мин", VolumeFlowUnit.LiterPerMinute)] + [InlineData("ru-RU", "л/c", VolumeFlowUnit.LiterPerSecond)] + [InlineData("ru-RU", "Мл/ч", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("ru-RU", "Мл/мин", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("ru-RU", "Мл/c", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("ru-RU", "мкл/ч", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("ru-RU", "мкл/мин", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("ru-RU", "мкл/c", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("ru-RU", "мл/ч", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("ru-RU", "мл/мин", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("ru-RU", "мл/c", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("ru-RU", "нл/ч", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("ru-RU", "нл/мин", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("ru-RU", "нл/c", VolumeFlowUnit.NanoliterPerSecond)] + public void TryParseUnitWithCulture(string culture, string abbreviation, VolumeFlowUnit expectedUnit) + { + Assert.True(VolumeFlow.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumeFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs index 00529e8ef7..e317c57b3a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs @@ -384,113 +384,70 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = VolumePerLength.ParseUnit("m³/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumePerLengthUnit.CubicMeterPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumePerLength.ParseUnit("yd³/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumePerLengthUnit.CubicYardPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumePerLength.ParseUnit("yd³/ftUS", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumePerLengthUnit.CubicYardPerUsSurveyFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumePerLength.ParseUnit("gal (imp.)/mi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumePerLengthUnit.ImperialGallonPerMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumePerLength.ParseUnit("l/km", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumePerLengthUnit.LiterPerKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumePerLength.ParseUnit("l/m", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumePerLengthUnit.LiterPerMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumePerLength.ParseUnit("l/mm", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumePerLengthUnit.LiterPerMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumePerLength.ParseUnit("bbl/ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumePerLengthUnit.OilBarrelPerFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumePerLength.ParseUnit("gal (U.S.)/mi", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumePerLengthUnit.UsGallonPerMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("m³/m", VolumePerLengthUnit.CubicMeterPerMeter)] + [InlineData("yd³/ft", VolumePerLengthUnit.CubicYardPerFoot)] + [InlineData("yd³/ftUS", VolumePerLengthUnit.CubicYardPerUsSurveyFoot)] + [InlineData("gal (imp.)/mi", VolumePerLengthUnit.ImperialGallonPerMile)] + [InlineData("l/km", VolumePerLengthUnit.LiterPerKilometer)] + [InlineData("l/m", VolumePerLengthUnit.LiterPerMeter)] + [InlineData("l/mm", VolumePerLengthUnit.LiterPerMillimeter)] + [InlineData("bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] + [InlineData("gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] + public void ParseUnit(string abbreviation, VolumePerLengthUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + VolumePerLengthUnit parsedUnit = VolumePerLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "m³/m", VolumePerLengthUnit.CubicMeterPerMeter)] + [InlineData("en-US", "yd³/ft", VolumePerLengthUnit.CubicYardPerFoot)] + [InlineData("en-US", "yd³/ftUS", VolumePerLengthUnit.CubicYardPerUsSurveyFoot)] + [InlineData("en-US", "gal (imp.)/mi", VolumePerLengthUnit.ImperialGallonPerMile)] + [InlineData("en-US", "l/km", VolumePerLengthUnit.LiterPerKilometer)] + [InlineData("en-US", "l/m", VolumePerLengthUnit.LiterPerMeter)] + [InlineData("en-US", "l/mm", VolumePerLengthUnit.LiterPerMillimeter)] + [InlineData("en-US", "bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] + [InlineData("en-US", "gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] + public void ParseUnitWithCulture(string culture, string abbreviation, VolumePerLengthUnit expectedUnit) { - { - Assert.True(VolumePerLength.TryParseUnit("m³/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumePerLengthUnit.CubicMeterPerMeter, parsedUnit); - } - - { - Assert.True(VolumePerLength.TryParseUnit("yd³/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumePerLengthUnit.CubicYardPerFoot, parsedUnit); - } - - { - Assert.True(VolumePerLength.TryParseUnit("yd³/ftUS", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumePerLengthUnit.CubicYardPerUsSurveyFoot, parsedUnit); - } - - { - Assert.True(VolumePerLength.TryParseUnit("gal (imp.)/mi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumePerLengthUnit.ImperialGallonPerMile, parsedUnit); - } - - { - Assert.True(VolumePerLength.TryParseUnit("l/km", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumePerLengthUnit.LiterPerKilometer, parsedUnit); - } - - { - Assert.True(VolumePerLength.TryParseUnit("l/m", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumePerLengthUnit.LiterPerMeter, parsedUnit); - } - - { - Assert.True(VolumePerLength.TryParseUnit("l/mm", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumePerLengthUnit.LiterPerMillimeter, parsedUnit); - } - - { - Assert.True(VolumePerLength.TryParseUnit("bbl/ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumePerLengthUnit.OilBarrelPerFoot, parsedUnit); - } + VolumePerLengthUnit parsedUnit = VolumePerLength.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(VolumePerLength.TryParseUnit("gal (U.S.)/mi", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumePerLengthUnit.UsGallonPerMile, parsedUnit); - } + [Theory] + [InlineData("m³/m", VolumePerLengthUnit.CubicMeterPerMeter)] + [InlineData("yd³/ft", VolumePerLengthUnit.CubicYardPerFoot)] + [InlineData("yd³/ftUS", VolumePerLengthUnit.CubicYardPerUsSurveyFoot)] + [InlineData("gal (imp.)/mi", VolumePerLengthUnit.ImperialGallonPerMile)] + [InlineData("l/km", VolumePerLengthUnit.LiterPerKilometer)] + [InlineData("l/m", VolumePerLengthUnit.LiterPerMeter)] + [InlineData("l/mm", VolumePerLengthUnit.LiterPerMillimeter)] + [InlineData("bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] + [InlineData("gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] + public void TryParseUnit(string abbreviation, VolumePerLengthUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(VolumePerLength.TryParseUnit(abbreviation, out VolumePerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "m³/m", VolumePerLengthUnit.CubicMeterPerMeter)] + [InlineData("en-US", "yd³/ft", VolumePerLengthUnit.CubicYardPerFoot)] + [InlineData("en-US", "yd³/ftUS", VolumePerLengthUnit.CubicYardPerUsSurveyFoot)] + [InlineData("en-US", "gal (imp.)/mi", VolumePerLengthUnit.ImperialGallonPerMile)] + [InlineData("en-US", "l/km", VolumePerLengthUnit.LiterPerKilometer)] + [InlineData("en-US", "l/m", VolumePerLengthUnit.LiterPerMeter)] + [InlineData("en-US", "l/mm", VolumePerLengthUnit.LiterPerMillimeter)] + [InlineData("en-US", "bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] + [InlineData("en-US", "gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] + public void TryParseUnitWithCulture(string culture, string abbreviation, VolumePerLengthUnit expectedUnit) + { + Assert.True(VolumePerLength.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumePerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs index c007610bb0..7deb1ce34c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs @@ -1971,1076 +1971,358 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = Volume.ParseUnit("ac-ft", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.AcreFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("acre-foot", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.AcreFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("acre-feet", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.AcreFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("bf", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("board foot", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("board feet", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("pmp", CultureInfo.GetCultureInfo("fr-CA")); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("pied-planche", CultureInfo.GetCultureInfo("fr-CA")); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("pied de planche", CultureInfo.GetCultureInfo("fr-CA")); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("cl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.Centiliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("сл", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.Centiliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("cm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.CubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("см³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.CubicCentimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("dm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.CubicDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("дм³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.CubicDecimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("ft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.CubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("фут³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.CubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("hm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.CubicHectometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("гм³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.CubicHectometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("in³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.CubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("дюйм³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.CubicInch, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("km³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.CubicKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("км³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.CubicKilometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("m³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.CubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("м³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.CubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("µm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.CubicMicrometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("мкм³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.CubicMicrometer, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("mi³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.CubicMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("миля³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.CubicMile, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("mm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.CubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("мм³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.CubicMillimeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("yd³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.CubicYard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("ярд³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.CubicYard, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("dal", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.Decaliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("дал", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.Decaliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("dagal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.DecausGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("даАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.DecausGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("dl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.Deciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("дл", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.Deciliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("dgal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.DeciusGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("дАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.DeciusGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("hft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.HectocubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("гфут³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.HectocubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("hm³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.HectocubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("гм³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.HectocubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("hl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.Hectoliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("гл", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.Hectoliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("hgal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.HectousGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("гАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.HectousGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("bl (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.ImperialBeerBarrel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("gal (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.ImperialGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("Английский галлон", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.ImperialGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("oz (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.ImperialOunce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("Английская унция", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.ImperialOunce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("pt (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.ImperialPint, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("UK pt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.ImperialPint, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("pt", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.ImperialPint, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("p", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.ImperialPint, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("qt (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.ImperialQuart, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("kft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.KilocubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("кфут³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.KilocubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("km³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.KilocubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("км³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.KilocubicMeter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("kgal (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.KiloimperialGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("кАнглийский галлон", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.KiloimperialGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("kl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.Kiloliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("кл", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.Kiloliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("kgal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.KilousGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("кАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.KilousGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("l", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.Liter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("л", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.Liter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("Mft³", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MegacubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("Мфут³", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.MegacubicFoot, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("Mgal (imp.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MegaimperialGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("МАнглийский галлон", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.MegaimperialGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("Ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.Megaliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("Мл", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.Megaliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("Mgal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MegausGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("МАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.MegausGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("tsp", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("t", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("ts", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("tspn", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("t.", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("ts.", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("tsp.", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("tspn.", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("teaspoon", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("µl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.Microliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("мкл", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.Microliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("ml", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.Milliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("мл", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.Milliliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("nl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.Nanoliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("нл", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.Nanoliter, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("bbl", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.OilBarrel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("bl (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.UsBeerBarrel, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("gal (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.UsGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("Американский галлон", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.UsGallon, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("oz (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.UsOunce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("Американская унция", CultureInfo.GetCultureInfo("ru-RU")); - Assert.Equal(VolumeUnit.UsOunce, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("pt (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.UsPint, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = Volume.ParseUnit("qt (U.S.)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumeUnit.UsQuart, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - } - - [Fact] - public void TryParseUnit() - { - { - Assert.True(Volume.TryParseUnit("ac-ft", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.AcreFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("acre-foot", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.AcreFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("acre-feet", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.AcreFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("bf", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("board foot", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("board feet", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("pmp", CultureInfo.GetCultureInfo("fr-CA"), out var parsedUnit)); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("pied-planche", CultureInfo.GetCultureInfo("fr-CA"), out var parsedUnit)); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("pied de planche", CultureInfo.GetCultureInfo("fr-CA"), out var parsedUnit)); - Assert.Equal(VolumeUnit.BoardFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("cl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Centiliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("сл", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Centiliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("cm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicCentimeter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("см³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicCentimeter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("dm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicDecimeter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("дм³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicDecimeter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("ft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("фут³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("in³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicInch, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("дюйм³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicInch, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("m³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicMeter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("м³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicMeter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("µm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicMicrometer, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("мкм³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicMicrometer, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("mi³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicMile, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("миля³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicMile, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("mm³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicMillimeter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("мм³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicMillimeter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("yd³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicYard, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("ярд³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.CubicYard, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("dal", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Decaliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("дал", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Decaliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("dagal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.DecausGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("даАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.DecausGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("dl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Deciliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("дл", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Deciliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("dgal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.DeciusGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("дАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.DeciusGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("hft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.HectocubicFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("гфут³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.HectocubicFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("hl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Hectoliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("гл", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Hectoliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("hgal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.HectousGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("гАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.HectousGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("bl (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.ImperialBeerBarrel, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("gal (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.ImperialGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("Английский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.ImperialGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("oz (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.ImperialOunce, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("Английская унция", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.ImperialOunce, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("pt (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.ImperialPint, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("UK pt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.ImperialPint, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("pt", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.ImperialPint, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("p", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.ImperialPint, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("qt (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.ImperialQuart, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("kft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.KilocubicFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("кфут³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.KilocubicFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("kgal (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.KiloimperialGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("кАнглийский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.KiloimperialGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("kl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Kiloliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("кл", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Kiloliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("kgal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.KilousGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("кАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.KilousGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("l", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Liter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("л", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Liter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("Mft³", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MegacubicFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("Мфут³", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MegacubicFoot, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("Mgal (imp.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MegaimperialGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("МАнглийский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MegaimperialGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("Mgal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MegausGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("МАмериканский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MegausGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("tsp", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("t", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("ts", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("tspn", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("t.", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("ts.", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("tsp.", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("tspn.", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("teaspoon", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.MetricTeaspoon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("µl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Microliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("мкл", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Microliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("nl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Nanoliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("нл", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.Nanoliter, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("bbl", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.OilBarrel, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("bl (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.UsBeerBarrel, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("gal (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.UsGallon, parsedUnit); - } - - { - Assert.True(Volume.TryParseUnit("Американский галлон", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.UsGallon, parsedUnit); - } + [Theory] + [InlineData("ac-ft", VolumeUnit.AcreFoot)] + [InlineData("acre-foot", VolumeUnit.AcreFoot)] + [InlineData("acre-feet", VolumeUnit.AcreFoot)] + [InlineData("bf", VolumeUnit.BoardFoot)] + [InlineData("board foot", VolumeUnit.BoardFoot)] + [InlineData("board feet", VolumeUnit.BoardFoot)] + [InlineData("cl", VolumeUnit.Centiliter)] + [InlineData("cm³", VolumeUnit.CubicCentimeter)] + [InlineData("dm³", VolumeUnit.CubicDecimeter)] + [InlineData("ft³", VolumeUnit.CubicFoot)] + [InlineData("in³", VolumeUnit.CubicInch)] + [InlineData("m³", VolumeUnit.CubicMeter)] + [InlineData("µm³", VolumeUnit.CubicMicrometer)] + [InlineData("mi³", VolumeUnit.CubicMile)] + [InlineData("mm³", VolumeUnit.CubicMillimeter)] + [InlineData("yd³", VolumeUnit.CubicYard)] + [InlineData("dal", VolumeUnit.Decaliter)] + [InlineData("dagal (U.S.)", VolumeUnit.DecausGallon)] + [InlineData("dl", VolumeUnit.Deciliter)] + [InlineData("dgal (U.S.)", VolumeUnit.DeciusGallon)] + [InlineData("hft³", VolumeUnit.HectocubicFoot)] + [InlineData("hl", VolumeUnit.Hectoliter)] + [InlineData("hgal (U.S.)", VolumeUnit.HectousGallon)] + [InlineData("bl (imp.)", VolumeUnit.ImperialBeerBarrel)] + [InlineData("gal (imp.)", VolumeUnit.ImperialGallon)] + [InlineData("oz (imp.)", VolumeUnit.ImperialOunce)] + [InlineData("pt (imp.)", VolumeUnit.ImperialPint)] + [InlineData("UK pt", VolumeUnit.ImperialPint)] + [InlineData("pt", VolumeUnit.ImperialPint)] + [InlineData("p", VolumeUnit.ImperialPint)] + [InlineData("qt (imp.)", VolumeUnit.ImperialQuart)] + [InlineData("kft³", VolumeUnit.KilocubicFoot)] + [InlineData("kgal (imp.)", VolumeUnit.KiloimperialGallon)] + [InlineData("kl", VolumeUnit.Kiloliter)] + [InlineData("kgal (U.S.)", VolumeUnit.KilousGallon)] + [InlineData("l", VolumeUnit.Liter)] + [InlineData("Mft³", VolumeUnit.MegacubicFoot)] + [InlineData("Mgal (imp.)", VolumeUnit.MegaimperialGallon)] + [InlineData("Ml", VolumeUnit.Megaliter)] + [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("tsp", VolumeUnit.MetricTeaspoon)] + [InlineData("t", VolumeUnit.MetricTeaspoon)] + [InlineData("ts", VolumeUnit.MetricTeaspoon)] + [InlineData("tspn", VolumeUnit.MetricTeaspoon)] + [InlineData("t.", VolumeUnit.MetricTeaspoon)] + [InlineData("ts.", VolumeUnit.MetricTeaspoon)] + [InlineData("tsp.", VolumeUnit.MetricTeaspoon)] + [InlineData("tspn.", VolumeUnit.MetricTeaspoon)] + [InlineData("teaspoon", VolumeUnit.MetricTeaspoon)] + [InlineData("µl", VolumeUnit.Microliter)] + [InlineData("ml", VolumeUnit.Milliliter)] + [InlineData("nl", VolumeUnit.Nanoliter)] + [InlineData("bbl", VolumeUnit.OilBarrel)] + [InlineData("bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("oz (U.S.)", VolumeUnit.UsOunce)] + [InlineData("pt (U.S.)", VolumeUnit.UsPint)] + [InlineData("qt (U.S.)", VolumeUnit.UsQuart)] + public void ParseUnit(string abbreviation, VolumeUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + VolumeUnit parsedUnit = Volume.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Volume.TryParseUnit("oz (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.UsOunce, parsedUnit); - } + [Theory] + [InlineData("en-US", "ac-ft", VolumeUnit.AcreFoot)] + [InlineData("en-US", "acre-foot", VolumeUnit.AcreFoot)] + [InlineData("en-US", "acre-feet", VolumeUnit.AcreFoot)] + [InlineData("en-US", "bf", VolumeUnit.BoardFoot)] + [InlineData("en-US", "board foot", VolumeUnit.BoardFoot)] + [InlineData("en-US", "board feet", VolumeUnit.BoardFoot)] + [InlineData("en-US", "cl", VolumeUnit.Centiliter)] + [InlineData("en-US", "cm³", VolumeUnit.CubicCentimeter)] + [InlineData("en-US", "dm³", VolumeUnit.CubicDecimeter)] + [InlineData("en-US", "ft³", VolumeUnit.CubicFoot)] + [InlineData("en-US", "in³", VolumeUnit.CubicInch)] + [InlineData("en-US", "m³", VolumeUnit.CubicMeter)] + [InlineData("en-US", "µm³", VolumeUnit.CubicMicrometer)] + [InlineData("en-US", "mi³", VolumeUnit.CubicMile)] + [InlineData("en-US", "mm³", VolumeUnit.CubicMillimeter)] + [InlineData("en-US", "yd³", VolumeUnit.CubicYard)] + [InlineData("en-US", "dal", VolumeUnit.Decaliter)] + [InlineData("en-US", "dagal (U.S.)", VolumeUnit.DecausGallon)] + [InlineData("en-US", "dl", VolumeUnit.Deciliter)] + [InlineData("en-US", "dgal (U.S.)", VolumeUnit.DeciusGallon)] + [InlineData("en-US", "hft³", VolumeUnit.HectocubicFoot)] + [InlineData("en-US", "hl", VolumeUnit.Hectoliter)] + [InlineData("en-US", "hgal (U.S.)", VolumeUnit.HectousGallon)] + [InlineData("en-US", "bl (imp.)", VolumeUnit.ImperialBeerBarrel)] + [InlineData("en-US", "gal (imp.)", VolumeUnit.ImperialGallon)] + [InlineData("en-US", "oz (imp.)", VolumeUnit.ImperialOunce)] + [InlineData("en-US", "pt (imp.)", VolumeUnit.ImperialPint)] + [InlineData("en-US", "UK pt", VolumeUnit.ImperialPint)] + [InlineData("en-US", "pt", VolumeUnit.ImperialPint)] + [InlineData("en-US", "p", VolumeUnit.ImperialPint)] + [InlineData("en-US", "qt (imp.)", VolumeUnit.ImperialQuart)] + [InlineData("en-US", "kft³", VolumeUnit.KilocubicFoot)] + [InlineData("en-US", "kgal (imp.)", VolumeUnit.KiloimperialGallon)] + [InlineData("en-US", "kl", VolumeUnit.Kiloliter)] + [InlineData("en-US", "kgal (U.S.)", VolumeUnit.KilousGallon)] + [InlineData("en-US", "l", VolumeUnit.Liter)] + [InlineData("en-US", "Mft³", VolumeUnit.MegacubicFoot)] + [InlineData("en-US", "Mgal (imp.)", VolumeUnit.MegaimperialGallon)] + [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] + [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tspn", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "t.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "ts.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tsp.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tspn.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "teaspoon", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "µl", VolumeUnit.Microliter)] + [InlineData("en-US", "ml", VolumeUnit.Milliliter)] + [InlineData("en-US", "nl", VolumeUnit.Nanoliter)] + [InlineData("en-US", "bbl", VolumeUnit.OilBarrel)] + [InlineData("en-US", "bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("en-US", "gal (U.S.)", VolumeUnit.UsGallon)] + [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("ru-RU", "сл", VolumeUnit.Centiliter)] + [InlineData("ru-RU", "см³", VolumeUnit.CubicCentimeter)] + [InlineData("ru-RU", "дм³", VolumeUnit.CubicDecimeter)] + [InlineData("ru-RU", "фут³", VolumeUnit.CubicFoot)] + [InlineData("ru-RU", "дюйм³", VolumeUnit.CubicInch)] + [InlineData("ru-RU", "м³", VolumeUnit.CubicMeter)] + [InlineData("ru-RU", "мкм³", VolumeUnit.CubicMicrometer)] + [InlineData("ru-RU", "миля³", VolumeUnit.CubicMile)] + [InlineData("ru-RU", "мм³", VolumeUnit.CubicMillimeter)] + [InlineData("ru-RU", "ярд³", VolumeUnit.CubicYard)] + [InlineData("ru-RU", "дал", VolumeUnit.Decaliter)] + [InlineData("ru-RU", "даАмериканский галлон", VolumeUnit.DecausGallon)] + [InlineData("ru-RU", "дл", VolumeUnit.Deciliter)] + [InlineData("ru-RU", "дАмериканский галлон", VolumeUnit.DeciusGallon)] + [InlineData("ru-RU", "гфут³", VolumeUnit.HectocubicFoot)] + [InlineData("ru-RU", "гл", VolumeUnit.Hectoliter)] + [InlineData("ru-RU", "гАмериканский галлон", VolumeUnit.HectousGallon)] + [InlineData("ru-RU", "Английский галлон", VolumeUnit.ImperialGallon)] + [InlineData("ru-RU", "Английская унция", VolumeUnit.ImperialOunce)] + [InlineData("ru-RU", "кфут³", VolumeUnit.KilocubicFoot)] + [InlineData("ru-RU", "кАнглийский галлон", VolumeUnit.KiloimperialGallon)] + [InlineData("ru-RU", "кл", VolumeUnit.Kiloliter)] + [InlineData("ru-RU", "кАмериканский галлон", VolumeUnit.KilousGallon)] + [InlineData("ru-RU", "л", VolumeUnit.Liter)] + [InlineData("ru-RU", "Мфут³", VolumeUnit.MegacubicFoot)] + [InlineData("ru-RU", "МАнглийский галлон", VolumeUnit.MegaimperialGallon)] + [InlineData("ru-RU", "Мл", VolumeUnit.Megaliter)] + [InlineData("ru-RU", "МАмериканский галлон", VolumeUnit.MegausGallon)] + [InlineData("ru-RU", "мкл", VolumeUnit.Microliter)] + [InlineData("ru-RU", "мл", VolumeUnit.Milliliter)] + [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 ParseUnitWithCulture(string culture, string abbreviation, VolumeUnit expectedUnit) + { + VolumeUnit parsedUnit = Volume.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Volume.TryParseUnit("Американская унция", CultureInfo.GetCultureInfo("ru-RU"), out var parsedUnit)); - Assert.Equal(VolumeUnit.UsOunce, parsedUnit); - } + [Theory] + [InlineData("en-US", "hm³")] // [CubicHectometer, HectocubicMeter] + [InlineData("en-US", "km³")] // [CubicKilometer, KilocubicMeter] + [InlineData("ru-RU", "гм³")] // [CubicHectometer, HectocubicMeter] + [InlineData("ru-RU", "км³")] // [CubicKilometer, KilocubicMeter] + public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) + { + Assert.Throws(() => Volume.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture))); + } - { - Assert.True(Volume.TryParseUnit("pt (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.UsPint, parsedUnit); - } + [Theory] + [InlineData("ac-ft", VolumeUnit.AcreFoot)] + [InlineData("acre-foot", VolumeUnit.AcreFoot)] + [InlineData("acre-feet", VolumeUnit.AcreFoot)] + [InlineData("bf", VolumeUnit.BoardFoot)] + [InlineData("board foot", VolumeUnit.BoardFoot)] + [InlineData("board feet", VolumeUnit.BoardFoot)] + [InlineData("cl", VolumeUnit.Centiliter)] + [InlineData("cm³", VolumeUnit.CubicCentimeter)] + [InlineData("dm³", VolumeUnit.CubicDecimeter)] + [InlineData("ft³", VolumeUnit.CubicFoot)] + [InlineData("in³", VolumeUnit.CubicInch)] + [InlineData("m³", VolumeUnit.CubicMeter)] + [InlineData("µm³", VolumeUnit.CubicMicrometer)] + [InlineData("mi³", VolumeUnit.CubicMile)] + [InlineData("mm³", VolumeUnit.CubicMillimeter)] + [InlineData("yd³", VolumeUnit.CubicYard)] + [InlineData("dal", VolumeUnit.Decaliter)] + [InlineData("dagal (U.S.)", VolumeUnit.DecausGallon)] + [InlineData("dl", VolumeUnit.Deciliter)] + [InlineData("dgal (U.S.)", VolumeUnit.DeciusGallon)] + [InlineData("hft³", VolumeUnit.HectocubicFoot)] + [InlineData("hl", VolumeUnit.Hectoliter)] + [InlineData("hgal (U.S.)", VolumeUnit.HectousGallon)] + [InlineData("bl (imp.)", VolumeUnit.ImperialBeerBarrel)] + [InlineData("gal (imp.)", VolumeUnit.ImperialGallon)] + [InlineData("oz (imp.)", VolumeUnit.ImperialOunce)] + [InlineData("pt (imp.)", VolumeUnit.ImperialPint)] + [InlineData("UK pt", VolumeUnit.ImperialPint)] + [InlineData("pt", VolumeUnit.ImperialPint)] + [InlineData("p", VolumeUnit.ImperialPint)] + [InlineData("qt (imp.)", VolumeUnit.ImperialQuart)] + [InlineData("kft³", VolumeUnit.KilocubicFoot)] + [InlineData("kgal (imp.)", VolumeUnit.KiloimperialGallon)] + [InlineData("kl", VolumeUnit.Kiloliter)] + [InlineData("kgal (U.S.)", VolumeUnit.KilousGallon)] + [InlineData("l", VolumeUnit.Liter)] + [InlineData("Mft³", VolumeUnit.MegacubicFoot)] + [InlineData("Mgal (imp.)", VolumeUnit.MegaimperialGallon)] + [InlineData("Ml", VolumeUnit.Megaliter)] + [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("tsp", VolumeUnit.MetricTeaspoon)] + [InlineData("t", VolumeUnit.MetricTeaspoon)] + [InlineData("ts", VolumeUnit.MetricTeaspoon)] + [InlineData("tspn", VolumeUnit.MetricTeaspoon)] + [InlineData("t.", VolumeUnit.MetricTeaspoon)] + [InlineData("ts.", VolumeUnit.MetricTeaspoon)] + [InlineData("tsp.", VolumeUnit.MetricTeaspoon)] + [InlineData("tspn.", VolumeUnit.MetricTeaspoon)] + [InlineData("teaspoon", VolumeUnit.MetricTeaspoon)] + [InlineData("µl", VolumeUnit.Microliter)] + [InlineData("ml", VolumeUnit.Milliliter)] + [InlineData("nl", VolumeUnit.Nanoliter)] + [InlineData("bbl", VolumeUnit.OilBarrel)] + [InlineData("bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("oz (U.S.)", VolumeUnit.UsOunce)] + [InlineData("pt (U.S.)", VolumeUnit.UsPint)] + [InlineData("qt (U.S.)", VolumeUnit.UsQuart)] + public void TryParseUnit(string abbreviation, VolumeUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(Volume.TryParseUnit(abbreviation, out VolumeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(Volume.TryParseUnit("qt (U.S.)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumeUnit.UsQuart, parsedUnit); - } + [Theory] + [InlineData("en-US", "ac-ft", VolumeUnit.AcreFoot)] + [InlineData("en-US", "acre-foot", VolumeUnit.AcreFoot)] + [InlineData("en-US", "acre-feet", VolumeUnit.AcreFoot)] + [InlineData("en-US", "bf", VolumeUnit.BoardFoot)] + [InlineData("en-US", "board foot", VolumeUnit.BoardFoot)] + [InlineData("en-US", "board feet", VolumeUnit.BoardFoot)] + [InlineData("en-US", "cl", VolumeUnit.Centiliter)] + [InlineData("en-US", "cm³", VolumeUnit.CubicCentimeter)] + [InlineData("en-US", "dm³", VolumeUnit.CubicDecimeter)] + [InlineData("en-US", "ft³", VolumeUnit.CubicFoot)] + [InlineData("en-US", "in³", VolumeUnit.CubicInch)] + [InlineData("en-US", "m³", VolumeUnit.CubicMeter)] + [InlineData("en-US", "µm³", VolumeUnit.CubicMicrometer)] + [InlineData("en-US", "mi³", VolumeUnit.CubicMile)] + [InlineData("en-US", "mm³", VolumeUnit.CubicMillimeter)] + [InlineData("en-US", "yd³", VolumeUnit.CubicYard)] + [InlineData("en-US", "dal", VolumeUnit.Decaliter)] + [InlineData("en-US", "dagal (U.S.)", VolumeUnit.DecausGallon)] + [InlineData("en-US", "dl", VolumeUnit.Deciliter)] + [InlineData("en-US", "dgal (U.S.)", VolumeUnit.DeciusGallon)] + [InlineData("en-US", "hft³", VolumeUnit.HectocubicFoot)] + [InlineData("en-US", "hl", VolumeUnit.Hectoliter)] + [InlineData("en-US", "hgal (U.S.)", VolumeUnit.HectousGallon)] + [InlineData("en-US", "bl (imp.)", VolumeUnit.ImperialBeerBarrel)] + [InlineData("en-US", "gal (imp.)", VolumeUnit.ImperialGallon)] + [InlineData("en-US", "oz (imp.)", VolumeUnit.ImperialOunce)] + [InlineData("en-US", "pt (imp.)", VolumeUnit.ImperialPint)] + [InlineData("en-US", "UK pt", VolumeUnit.ImperialPint)] + [InlineData("en-US", "pt", VolumeUnit.ImperialPint)] + [InlineData("en-US", "p", VolumeUnit.ImperialPint)] + [InlineData("en-US", "qt (imp.)", VolumeUnit.ImperialQuart)] + [InlineData("en-US", "kft³", VolumeUnit.KilocubicFoot)] + [InlineData("en-US", "kgal (imp.)", VolumeUnit.KiloimperialGallon)] + [InlineData("en-US", "kl", VolumeUnit.Kiloliter)] + [InlineData("en-US", "kgal (U.S.)", VolumeUnit.KilousGallon)] + [InlineData("en-US", "l", VolumeUnit.Liter)] + [InlineData("en-US", "Mft³", VolumeUnit.MegacubicFoot)] + [InlineData("en-US", "Mgal (imp.)", VolumeUnit.MegaimperialGallon)] + [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] + [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tspn", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "t.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "ts.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tsp.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tspn.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "teaspoon", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "µl", VolumeUnit.Microliter)] + [InlineData("en-US", "ml", VolumeUnit.Milliliter)] + [InlineData("en-US", "nl", VolumeUnit.Nanoliter)] + [InlineData("en-US", "bbl", VolumeUnit.OilBarrel)] + [InlineData("en-US", "bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("en-US", "gal (U.S.)", VolumeUnit.UsGallon)] + [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("ru-RU", "сл", VolumeUnit.Centiliter)] + [InlineData("ru-RU", "см³", VolumeUnit.CubicCentimeter)] + [InlineData("ru-RU", "дм³", VolumeUnit.CubicDecimeter)] + [InlineData("ru-RU", "фут³", VolumeUnit.CubicFoot)] + [InlineData("ru-RU", "дюйм³", VolumeUnit.CubicInch)] + [InlineData("ru-RU", "м³", VolumeUnit.CubicMeter)] + [InlineData("ru-RU", "мкм³", VolumeUnit.CubicMicrometer)] + [InlineData("ru-RU", "миля³", VolumeUnit.CubicMile)] + [InlineData("ru-RU", "мм³", VolumeUnit.CubicMillimeter)] + [InlineData("ru-RU", "ярд³", VolumeUnit.CubicYard)] + [InlineData("ru-RU", "дал", VolumeUnit.Decaliter)] + [InlineData("ru-RU", "даАмериканский галлон", VolumeUnit.DecausGallon)] + [InlineData("ru-RU", "дл", VolumeUnit.Deciliter)] + [InlineData("ru-RU", "дАмериканский галлон", VolumeUnit.DeciusGallon)] + [InlineData("ru-RU", "гфут³", VolumeUnit.HectocubicFoot)] + [InlineData("ru-RU", "гл", VolumeUnit.Hectoliter)] + [InlineData("ru-RU", "гАмериканский галлон", VolumeUnit.HectousGallon)] + [InlineData("ru-RU", "Английский галлон", VolumeUnit.ImperialGallon)] + [InlineData("ru-RU", "Английская унция", VolumeUnit.ImperialOunce)] + [InlineData("ru-RU", "кфут³", VolumeUnit.KilocubicFoot)] + [InlineData("ru-RU", "кАнглийский галлон", VolumeUnit.KiloimperialGallon)] + [InlineData("ru-RU", "кл", VolumeUnit.Kiloliter)] + [InlineData("ru-RU", "кАмериканский галлон", VolumeUnit.KilousGallon)] + [InlineData("ru-RU", "л", VolumeUnit.Liter)] + [InlineData("ru-RU", "Мфут³", VolumeUnit.MegacubicFoot)] + [InlineData("ru-RU", "МАнглийский галлон", VolumeUnit.MegaimperialGallon)] + [InlineData("ru-RU", "Мл", VolumeUnit.Megaliter)] + [InlineData("ru-RU", "МАмериканский галлон", VolumeUnit.MegausGallon)] + [InlineData("ru-RU", "мкл", VolumeUnit.Microliter)] + [InlineData("ru-RU", "мл", VolumeUnit.Milliliter)] + [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 TryParseUnitWithCulture(string culture, string abbreviation, VolumeUnit expectedUnit) + { + Assert.True(Volume.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "hm³")] // [CubicHectometer, HectocubicMeter] + [InlineData("en-US", "km³")] // [CubicKilometer, KilocubicMeter] + [InlineData("ru-RU", "гм³")] // [CubicHectometer, HectocubicMeter] + [InlineData("ru-RU", "км³")] // [CubicKilometer, KilocubicMeter] + public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbreviation) + { + Assert.False(Volume.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out _)); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs index 3258232b08..468cb82fc1 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs @@ -384,113 +384,70 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = VolumetricHeatCapacity.ParseUnit("BTU/(ft³·°F)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumetricHeatCapacity.ParseUnit("cal/(cm³·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumetricHeatCapacity.ParseUnit("J/(m³·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumetricHeatCapacity.ParseUnit("J/(m³·K)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumetricHeatCapacity.ParseUnit("kcal/(cm³·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumetricHeatCapacity.ParseUnit("kJ/(m³·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumetricHeatCapacity.ParseUnit("kJ/(m³·K)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumetricHeatCapacity.ParseUnit("MJ/(m³·°C)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = VolumetricHeatCapacity.ParseUnit("MJ/(m³·K)", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("BTU/(ft³·°F)", VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit)] + [InlineData("cal/(cm³·°C)", VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("J/(m³·°C)", VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius)] + [InlineData("J/(m³·K)", VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin)] + [InlineData("kcal/(cm³·°C)", VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("kJ/(m³·°C)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius)] + [InlineData("kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] + [InlineData("MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] + [InlineData("MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] + public void ParseUnit(string abbreviation, VolumetricHeatCapacityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + VolumetricHeatCapacityUnit parsedUnit = VolumetricHeatCapacity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() + [Theory] + [InlineData("en-US", "BTU/(ft³·°F)", VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit)] + [InlineData("en-US", "cal/(cm³·°C)", VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("en-US", "J/(m³·°C)", VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "J/(m³·K)", VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin)] + [InlineData("en-US", "kcal/(cm³·°C)", VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("en-US", "kJ/(m³·°C)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] + [InlineData("en-US", "MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] + public void ParseUnitWithCulture(string culture, string abbreviation, VolumetricHeatCapacityUnit expectedUnit) { - { - Assert.True(VolumetricHeatCapacity.TryParseUnit("BTU/(ft³·°F)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit, parsedUnit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParseUnit("cal/(cm³·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParseUnit("J/(m³·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParseUnit("J/(m³·K)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin, parsedUnit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParseUnit("kcal/(cm³·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParseUnit("kJ/(m³·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius, parsedUnit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParseUnit("kJ/(m³·K)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin, parsedUnit); - } - - { - Assert.True(VolumetricHeatCapacity.TryParseUnit("MJ/(m³·°C)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius, parsedUnit); - } + VolumetricHeatCapacityUnit parsedUnit = VolumetricHeatCapacity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(VolumetricHeatCapacity.TryParseUnit("MJ/(m³·K)", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin, parsedUnit); - } + [Theory] + [InlineData("BTU/(ft³·°F)", VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit)] + [InlineData("cal/(cm³·°C)", VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("J/(m³·°C)", VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius)] + [InlineData("J/(m³·K)", VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin)] + [InlineData("kcal/(cm³·°C)", VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("kJ/(m³·°C)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius)] + [InlineData("kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] + [InlineData("MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] + [InlineData("MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] + public void TryParseUnit(string abbreviation, VolumetricHeatCapacityUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(VolumetricHeatCapacity.TryParseUnit(abbreviation, out VolumetricHeatCapacityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "BTU/(ft³·°F)", VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit)] + [InlineData("en-US", "cal/(cm³·°C)", VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("en-US", "J/(m³·°C)", VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "J/(m³·K)", VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin)] + [InlineData("en-US", "kcal/(cm³·°C)", VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("en-US", "kJ/(m³·°C)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] + [InlineData("en-US", "MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] + public void TryParseUnitWithCulture(string culture, string abbreviation, VolumetricHeatCapacityUnit expectedUnit) + { + Assert.True(VolumetricHeatCapacity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumetricHeatCapacityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs index 4ea94b4737..99a34b606e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs @@ -393,146 +393,82 @@ public void TryParse() } - [Fact] - public void ParseUnit() - { - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("cm⁶", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.CentimeterToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("cm^6", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.CentimeterToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("dm⁶", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.DecimeterToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("dm^6", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.DecimeterToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("ft⁶", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.FootToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("ft^6", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.FootToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("in⁶", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.InchToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("in^6", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.InchToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("m⁶", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.MeterToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("m^6", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.MeterToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("mm⁶", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.MillimeterToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - - try - { - var parsedUnit = WarpingMomentOfInertia.ParseUnit("mm^6", CultureInfo.GetCultureInfo("en-US")); - Assert.Equal(WarpingMomentOfInertiaUnit.MillimeterToTheSixth, parsedUnit); - } catch (AmbiguousUnitParseException) { /* Some units have the same abbreviations */ } - + [Theory] + [InlineData("cm⁶", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("cm^6", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("dm⁶", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("dm^6", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("ft⁶", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("ft^6", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("in⁶", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("in^6", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("m⁶", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + [InlineData("mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + public void ParseUnit(string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + WarpingMomentOfInertiaUnit parsedUnit = WarpingMomentOfInertia.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); } - [Fact] - public void TryParseUnit() - { - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("cm⁶", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.CentimeterToTheSixth, parsedUnit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("cm^6", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.CentimeterToTheSixth, parsedUnit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("dm⁶", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.DecimeterToTheSixth, parsedUnit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("dm^6", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.DecimeterToTheSixth, parsedUnit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("ft⁶", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.FootToTheSixth, parsedUnit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("ft^6", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.FootToTheSixth, parsedUnit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("in⁶", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.InchToTheSixth, parsedUnit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("in^6", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.InchToTheSixth, parsedUnit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("m⁶", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.MeterToTheSixth, parsedUnit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("m^6", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.MeterToTheSixth, parsedUnit); - } - - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("mm⁶", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.MillimeterToTheSixth, parsedUnit); - } + [Theory] + [InlineData("en-US", "cm⁶", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("en-US", "cm^6", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("en-US", "dm⁶", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("en-US", "dm^6", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("en-US", "ft⁶", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("en-US", "ft^6", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("en-US", "in⁶", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("en-US", "in^6", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("en-US", "m⁶", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("en-US", "m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("en-US", "mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + [InlineData("en-US", "mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + public void ParseUnitWithCulture(string culture, string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + { + WarpingMomentOfInertiaUnit parsedUnit = WarpingMomentOfInertia.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } - { - Assert.True(WarpingMomentOfInertia.TryParseUnit("mm^6", CultureInfo.GetCultureInfo("en-US"), out var parsedUnit)); - Assert.Equal(WarpingMomentOfInertiaUnit.MillimeterToTheSixth, parsedUnit); - } + [Theory] + [InlineData("cm⁶", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("cm^6", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("dm⁶", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("dm^6", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("ft⁶", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("ft^6", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("in⁶", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("in^6", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("m⁶", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + [InlineData("mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + public void TryParseUnit(string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + { + // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + Assert.True(WarpingMomentOfInertia.TryParseUnit(abbreviation, out WarpingMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + [Theory] + [InlineData("en-US", "cm⁶", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("en-US", "cm^6", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("en-US", "dm⁶", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("en-US", "dm^6", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("en-US", "ft⁶", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("en-US", "ft^6", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("en-US", "in⁶", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("en-US", "in^6", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("en-US", "m⁶", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("en-US", "m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("en-US", "mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + [InlineData("en-US", "mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + public void TryParseUnitWithCulture(string culture, string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + { + Assert.True(WarpingMomentOfInertia.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out WarpingMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); } [Theory] From 70f1b3e124e815e5901ad4ede1bb91b19095e262 Mon Sep 17 00:00:00 2001 From: Andreas Gullberg Larsen Date: Thu, 26 Dec 2024 19:11:59 +0100 Subject: [PATCH 3/3] Add/improve test cases Change tests to control current culture: - Change `ParseUnit` to `ParseUnit_WithUsEnglishCurrentCulture` - Change `TryParseUnit` to `TryParseUnit_WithUsEnglishCurrentCulture` Add tests for more cases: - ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish - ParseUnit_WithCurrentCulture - TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish - TryParseUnit_WithCurrentCulture --- .../UnitsNetGen/UnitTestBaseClassGenerator.cs | 99 +- ...orbedDoseOfIonizingRadiationTestsBase.g.cs | 147 ++- .../TestsBase/AccelerationTestsBase.g.cs | 135 ++- .../TestsBase/AmountOfSubstanceTestsBase.g.cs | 119 ++- .../TestsBase/AmplitudeRatioTestsBase.g.cs | 67 +- .../TestsBase/AngleTestsBase.g.cs | 175 +++- .../TestsBase/ApparentEnergyTestsBase.g.cs | 63 +- .../TestsBase/ApparentPowerTestsBase.g.cs | 75 +- .../TestsBase/AreaDensityTestsBase.g.cs | 67 +- .../AreaMomentOfInertiaTestsBase.g.cs | 99 +- .../TestsBase/AreaTestsBase.g.cs | 157 ++- .../TestsBase/BitRateTestsBase.g.cs | 207 +++- ...BrakeSpecificFuelConsumptionTestsBase.g.cs | 63 +- .../TestsBase/CapacitanceTestsBase.g.cs | 79 +- ...oefficientOfThermalExpansionTestsBase.g.cs | 75 +- .../TestsBase/CompressibilityTestsBase.g.cs | 107 ++- .../TestsBase/DensityTestsBase.g.cs | 283 +++++- .../TestsBase/DurationTestsBase.g.cs | 263 +++++- .../TestsBase/DynamicViscosityTestsBase.g.cs | 103 +- .../ElectricAdmittanceTestsBase.g.cs | 67 +- .../ElectricChargeDensityTestsBase.g.cs | 55 +- .../TestsBase/ElectricChargeTestsBase.g.cs | 111 ++- .../ElectricConductanceTestsBase.g.cs | 71 +- .../ElectricConductivityTestsBase.g.cs | 75 +- .../ElectricCurrentDensityTestsBase.g.cs | 63 +- .../ElectricCurrentGradientTestsBase.g.cs | 79 +- .../TestsBase/ElectricCurrentTestsBase.g.cs | 87 +- .../TestsBase/ElectricFieldTestsBase.g.cs | 55 +- .../ElectricInductanceTestsBase.g.cs | 71 +- .../ElectricPotentialAcTestsBase.g.cs | 71 +- .../ElectricPotentialChangeRateTestsBase.g.cs | 131 ++- .../ElectricPotentialDcTestsBase.g.cs | 71 +- .../TestsBase/ElectricPotentialTestsBase.g.cs | 87 +- .../ElectricResistanceTestsBase.g.cs | 79 +- .../ElectricResistivityTestsBase.g.cs | 107 ++- ...ElectricSurfaceChargeDensityTestsBase.g.cs | 63 +- .../TestsBase/EnergyDensityTestsBase.g.cs | 99 +- .../TestsBase/EnergyTestsBase.g.cs | 253 ++++- .../TestsBase/EntropyTestsBase.g.cs | 79 +- .../TestsBase/ForceChangeRateTestsBase.g.cs | 127 ++- .../TestsBase/ForcePerLengthTestsBase.g.cs | 231 ++++- .../TestsBase/ForceTestsBase.g.cs | 157 ++- .../TestsBase/FrequencyTestsBase.g.cs | 121 ++- .../TestsBase/FuelEfficiencyTestsBase.g.cs | 67 +- .../TestsBase/HeatFluxTestsBase.g.cs | 127 ++- .../HeatTransferCoefficientTestsBase.g.cs | 107 ++- .../TestsBase/IlluminanceTestsBase.g.cs | 67 +- .../TestsBase/ImpulseTestsBase.g.cs | 103 +- .../TestsBase/InformationTestsBase.g.cs | 155 ++- .../TestsBase/IrradianceTestsBase.g.cs | 107 ++- .../TestsBase/IrradiationTestsBase.g.cs | 87 +- .../TestsBase/JerkTestsBase.g.cs | 117 ++- .../KinematicViscosityTestsBase.g.cs | 103 +- .../TestsBase/LeakRateTestsBase.g.cs | 63 +- .../TestsBase/LengthTestsBase.g.cs | 323 ++++++- .../TestsBase/LevelTestsBase.g.cs | 59 +- .../TestsBase/LinearDensityTestsBase.g.cs | 123 ++- .../LinearPowerDensityTestsBase.g.cs | 151 ++- .../TestsBase/LuminanceTestsBase.g.cs | 91 +- .../TestsBase/LuminosityTestsBase.g.cs | 107 ++- .../TestsBase/LuminousFluxTestsBase.g.cs | 55 +- .../TestsBase/LuminousIntensityTestsBase.g.cs | 55 +- .../TestsBase/MagneticFieldTestsBase.g.cs | 75 +- .../TestsBase/MagneticFluxTestsBase.g.cs | 55 +- .../TestsBase/MagnetizationTestsBase.g.cs | 55 +- .../TestsBase/MassConcentrationTestsBase.g.cs | 255 ++++- .../TestsBase/MassFlowTestsBase.g.cs | 223 ++++- .../TestsBase/MassFluxTestsBase.g.cs | 99 +- .../TestsBase/MassFractionTestsBase.g.cs | 151 ++- .../MassMomentOfInertiaTestsBase.g.cs | 163 +++- .../TestsBase/MassTestsBase.g.cs | 265 +++++- .../TestsBase/MolalityTestsBase.g.cs | 63 +- .../TestsBase/MolarEnergyTestsBase.g.cs | 63 +- .../TestsBase/MolarEntropyTestsBase.g.cs | 63 +- .../TestsBase/MolarFlowTestsBase.g.cs | 87 +- .../TestsBase/MolarMassTestsBase.g.cs | 127 ++- .../TestsBase/MolarityTestsBase.g.cs | 127 ++- .../TestsBase/PermeabilityTestsBase.g.cs | 55 +- .../TestsBase/PermittivityTestsBase.g.cs | 55 +- .../PorousMediumPermeabilityTestsBase.g.cs | 71 +- .../TestsBase/PowerDensityTestsBase.g.cs | 227 ++++- .../TestsBase/PowerRatioTestsBase.g.cs | 63 +- .../TestsBase/PowerTestsBase.g.cs | 171 +++- .../PressureChangeRateTestsBase.g.cs | 195 +++- .../TestsBase/PressureTestsBase.g.cs | 373 +++++++- .../RadiationEquivalentDoseTestsBase.g.cs | 83 +- .../TestsBase/RadiationExposureTestsBase.g.cs | 83 +- .../TestsBase/RadioactivityTestsBase.g.cs | 225 ++++- .../TestsBase/RatioChangeRateTestsBase.g.cs | 59 +- .../TestsBase/RatioTestsBase.g.cs | 75 +- .../TestsBase/ReactiveEnergyTestsBase.g.cs | 63 +- .../TestsBase/ReactivePowerTestsBase.g.cs | 67 +- .../TestsBase/ReciprocalAreaTestsBase.g.cs | 95 +- .../TestsBase/ReciprocalLengthTestsBase.g.cs | 131 ++- .../TestsBase/RelativeHumidityTestsBase.g.cs | 55 +- .../RotationalAccelerationTestsBase.g.cs | 71 +- .../TestsBase/RotationalSpeedTestsBase.g.cs | 151 ++- ...RotationalStiffnessPerLengthTestsBase.g.cs | 103 +- .../RotationalStiffnessTestsBase.g.cs | 467 ++++++++- .../TestsBase/ScalarTestsBase.g.cs | 55 +- .../TestsBase/SolidAngleTestsBase.g.cs | 55 +- .../TestsBase/SpecificEnergyTestsBase.g.cs | 171 +++- .../TestsBase/SpecificEntropyTestsBase.g.cs | 91 +- .../SpecificFuelConsumptionTestsBase.g.cs | 67 +- .../TestsBase/SpecificVolumeTestsBase.g.cs | 63 +- .../TestsBase/SpecificWeightTestsBase.g.cs | 119 ++- .../TestsBase/SpeedTestsBase.g.cs | 255 ++++- .../StandardVolumeFlowTestsBase.g.cs | 87 +- .../TemperatureChangeRateTestsBase.g.cs | 91 +- .../TestsBase/TemperatureDeltaTestsBase.g.cs | 87 +- .../TemperatureGradientTestsBase.g.cs | 67 +- .../TestsBase/TemperatureTestsBase.g.cs | 91 +- .../ThermalConductivityTestsBase.g.cs | 59 +- .../TestsBase/ThermalInsulanceTestsBase.g.cs | 75 +- .../TestsBase/TorqueTestsBase.g.cs | 157 ++- .../TestsBase/TurbidityTestsBase.g.cs | 55 +- .../TestsBase/VitaminATestsBase.g.cs | 55 +- .../VolumeConcentrationTestsBase.g.cs | 135 ++- .../TestsBase/VolumeFlowPerAreaTestsBase.g.cs | 59 +- .../TestsBase/VolumeFlowTestsBase.g.cs | 893 +++++++++++++++--- .../TestsBase/VolumePerLengthTestsBase.g.cs | 87 +- .../TestsBase/VolumeTestsBase.g.cs | 355 ++++++- .../VolumetricHeatCapacityTestsBase.g.cs | 87 +- .../WarpingMomentOfInertiaTestsBase.g.cs | 99 +- UnitsNet.Tests/Helpers/CultureScope.cs | 32 + 125 files changed, 14128 insertions(+), 988 deletions(-) create mode 100644 UnitsNet.Tests/Helpers/CultureScope.cs diff --git a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs index 3ff853dd38..91cd605d0b 100644 --- a/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs +++ b/CodeGen/Generators/UnitsNetGen/UnitTestBaseClassGenerator.cs @@ -169,6 +169,7 @@ public string Generate() using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -403,7 +404,7 @@ public void TryParse() Writer.WL($@" }} "); - + Writer.WL($@" [Theory]"); foreach ((var abbreviation, Unit unit) in _uniqueAbbreviationsForCulture[FallbackCultureName]) @@ -412,13 +413,51 @@ public void TryParse() [InlineData(""{abbreviation}"", {GetUnitFullName(unit)})]"); } Writer.WL($@" - public void ParseUnit(string abbreviation, {_unitEnumName} expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, {_unitEnumName} expectedUnit) + {{ + // Fallback culture ""{FallbackCultureName}"" is always localized + using var _ = new CultureScope(""{FallbackCultureName}""); + {_unitEnumName} parsedUnit = {_quantity.Name}.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + }} +"); + + Writer.WL($@" + [Theory]"); + foreach ((var abbreviation, Unit unit) in _uniqueAbbreviationsForCulture[FallbackCultureName]) + { + Writer.WL($@" + [InlineData(""{abbreviation}"", {GetUnitFullName(unit)})]"); + } + Writer.WL($@" + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, {_unitEnumName} expectedUnit) + {{ + // Currently, no abbreviations are localized for Icelandic, so it should fall back to ""{FallbackCultureName}"" when parsing. + using var _ = new CultureScope(""is-IS""); + {_unitEnumName} parsedUnit = {_quantity.Name}.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + }} +"); + + Writer.WL($@" + [Theory]"); + foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) + { + foreach ((var abbreviation, Unit unit) in abbreviations) + { + Writer.WL($@" + [InlineData(""{cultureName}"", ""{abbreviation}"", {GetUnitFullName(unit)})]"); + } + } + Writer.WL($@" + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) {{ - // regardless of the CurrentCulture is, this should always work with the FallbackCulture (""{FallbackCultureName}"") - {_unitEnumName} parsedUnit = {_quantity.Name}.ParseUnit(abbreviation); + using var _ = new CultureScope(culture); + {_unitEnumName} parsedUnit = {_quantity.Name}.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); }} "); + Writer.WL($@" [Theory]"); foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) @@ -430,12 +469,13 @@ public void ParseUnit(string abbreviation, {_unitEnumName} expectedUnit) } } Writer.WL($@" - public void ParseUnitWithCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) + public void ParseUnit_WithCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) {{ {_unitEnumName} parsedUnit = {_quantity.Name}.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); }} "); + // we only generate these for a few of the quantities if (_ambiguousAbbreviationsForCulture.Count != 0) { @@ -456,7 +496,7 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati }} "); } // ambiguousAbbreviations - + Writer.WL($@" [Theory]"); foreach ((var abbreviation, Unit unit) in _uniqueAbbreviationsForCulture[FallbackCultureName]) @@ -465,13 +505,32 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati [InlineData(""{abbreviation}"", {GetUnitFullName(unit)})]"); } Writer.WL($@" - public void TryParseUnit(string abbreviation, {_unitEnumName} expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, {_unitEnumName} expectedUnit) {{ - // regardless of the CurrentCulture is, this should always work with the FallbackCulture (""{FallbackCultureName}"") + // Fallback culture ""{FallbackCultureName}"" is always localized + using var _ = new CultureScope(""{FallbackCultureName}""); Assert.True({_quantity.Name}.TryParseUnit(abbreviation, out {_unitEnumName} parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); }} "); + + Writer.WL($@" + [Theory]"); + foreach ((var abbreviation, Unit unit) in _uniqueAbbreviationsForCulture[FallbackCultureName]) + { + Writer.WL($@" + [InlineData(""{abbreviation}"", {GetUnitFullName(unit)})]"); + } + Writer.WL($@" + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, {_unitEnumName} expectedUnit) + {{ + // Currently, no abbreviations are localized for Icelandic, so it should fall back to ""{FallbackCultureName}"" when parsing. + using var _ = new CultureScope(""is-IS""); + Assert.True({_quantity.Name}.TryParseUnit(abbreviation, out {_unitEnumName} parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + }} +"); + Writer.WL($@" [Theory]"); foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) @@ -483,12 +542,32 @@ public void TryParseUnit(string abbreviation, {_unitEnumName} expectedUnit) } } Writer.WL($@" - public void TryParseUnitWithCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) + {{ + using var _ = new CultureScope(culture); + Assert.True({_quantity.Name}.TryParseUnit(abbreviation, out {_unitEnumName} parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + }} +"); + + Writer.WL($@" + [Theory]"); + foreach ((var cultureName, Dictionary abbreviations) in _uniqueAbbreviationsForCulture) + { + foreach ((var abbreviation, Unit unit) in abbreviations) + { + Writer.WL($@" + [InlineData(""{cultureName}"", ""{abbreviation}"", {GetUnitFullName(unit)})]"); + } + } + Writer.WL($@" + public void TryParseUnit_WithCulture(string culture, string abbreviation, {_unitEnumName} expectedUnit) {{ Assert.True({_quantity.Name}.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out {_unitEnumName} parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); }} "); + // we only generate these for a few of the quantities if (_ambiguousAbbreviationsForCulture.Count != 0) { @@ -509,7 +588,7 @@ public void TryParseUnitWithAmbiguousAbbreviation(string culture, string abbrevi }} "); } // ambiguousAbbreviations - + Writer.WL($@" [Theory] [MemberData(nameof(UnitTypes))] diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs index cb3fee8e9a..3bb73c4843 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -698,10 +699,36 @@ public void TryParse() [InlineData("pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] [InlineData("rad", AbsorbedDoseOfIonizingRadiationUnit.Rad)] [InlineData("TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] - public void ParseUnit(string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - AbsorbedDoseOfIonizingRadiationUnit parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + AbsorbedDoseOfIonizingRadiationUnit parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cGy", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("fGy", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("GGy", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("Gy", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("kGy", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("krad", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("MGy", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("Mrad", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("µGy", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("mGy", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("mrad", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("nGy", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("PGy", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("rad", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + AbsorbedDoseOfIonizingRadiationUnit parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -738,7 +765,47 @@ public void ParseUnit(string abbreviation, AbsorbedDoseOfIonizingRadiationUnit e [InlineData("ru-RU", "пГр", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] [InlineData("ru-RU", "рад", AbsorbedDoseOfIonizingRadiationUnit.Rad)] [InlineData("ru-RU", "ТГр", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] - public void ParseUnitWithCulture(string culture, string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + { + using var _ = new CultureScope(culture); + AbsorbedDoseOfIonizingRadiationUnit parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cGy", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("en-US", "fGy", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("en-US", "GGy", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("en-US", "Gy", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("en-US", "kGy", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("en-US", "krad", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("en-US", "MGy", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("en-US", "Mrad", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("en-US", "µGy", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("en-US", "mGy", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("en-US", "mrad", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("en-US", "nGy", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("en-US", "PGy", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("en-US", "pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("en-US", "rad", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("en-US", "TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + [InlineData("ru-RU", "сГр", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("ru-RU", "фГр", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("ru-RU", "ГГр", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("ru-RU", "Гр", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("ru-RU", "кГр", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("ru-RU", "крад", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("ru-RU", "МГр", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("ru-RU", "Мрад", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("ru-RU", "мкГр", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("ru-RU", "мГр", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("ru-RU", "мрад", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("ru-RU", "нГр", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("ru-RU", "ПГр", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("ru-RU", "пГр", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("ru-RU", "рад", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("ru-RU", "ТГр", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + public void ParseUnit_WithCulture(string culture, string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) { AbsorbedDoseOfIonizingRadiationUnit parsedUnit = AbsorbedDoseOfIonizingRadiation.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -761,9 +828,75 @@ public void ParseUnitWithCulture(string culture, string abbreviation, AbsorbedDo [InlineData("pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] [InlineData("rad", AbsorbedDoseOfIonizingRadiationUnit.Rad)] [InlineData("TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] - public void TryParseUnit(string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit(abbreviation, out AbsorbedDoseOfIonizingRadiationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cGy", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("fGy", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("GGy", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("Gy", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("kGy", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("krad", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("MGy", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("Mrad", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("µGy", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("mGy", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("mrad", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("nGy", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("PGy", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("rad", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit(abbreviation, out AbsorbedDoseOfIonizingRadiationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cGy", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("en-US", "fGy", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("en-US", "GGy", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("en-US", "Gy", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("en-US", "kGy", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("en-US", "krad", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("en-US", "MGy", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("en-US", "Mrad", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("en-US", "µGy", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("en-US", "mGy", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("en-US", "mrad", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("en-US", "nGy", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("en-US", "PGy", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("en-US", "pGy", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("en-US", "rad", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("en-US", "TGy", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + [InlineData("ru-RU", "сГр", AbsorbedDoseOfIonizingRadiationUnit.Centigray)] + [InlineData("ru-RU", "фГр", AbsorbedDoseOfIonizingRadiationUnit.Femtogray)] + [InlineData("ru-RU", "ГГр", AbsorbedDoseOfIonizingRadiationUnit.Gigagray)] + [InlineData("ru-RU", "Гр", AbsorbedDoseOfIonizingRadiationUnit.Gray)] + [InlineData("ru-RU", "кГр", AbsorbedDoseOfIonizingRadiationUnit.Kilogray)] + [InlineData("ru-RU", "крад", AbsorbedDoseOfIonizingRadiationUnit.Kilorad)] + [InlineData("ru-RU", "МГр", AbsorbedDoseOfIonizingRadiationUnit.Megagray)] + [InlineData("ru-RU", "Мрад", AbsorbedDoseOfIonizingRadiationUnit.Megarad)] + [InlineData("ru-RU", "мкГр", AbsorbedDoseOfIonizingRadiationUnit.Microgray)] + [InlineData("ru-RU", "мГр", AbsorbedDoseOfIonizingRadiationUnit.Milligray)] + [InlineData("ru-RU", "мрад", AbsorbedDoseOfIonizingRadiationUnit.Millirad)] + [InlineData("ru-RU", "нГр", AbsorbedDoseOfIonizingRadiationUnit.Nanogray)] + [InlineData("ru-RU", "ПГр", AbsorbedDoseOfIonizingRadiationUnit.Petagray)] + [InlineData("ru-RU", "пГр", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] + [InlineData("ru-RU", "рад", AbsorbedDoseOfIonizingRadiationUnit.Rad)] + [InlineData("ru-RU", "ТГр", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit(abbreviation, out AbsorbedDoseOfIonizingRadiationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -801,7 +934,7 @@ public void TryParseUnit(string abbreviation, AbsorbedDoseOfIonizingRadiationUni [InlineData("ru-RU", "пГр", AbsorbedDoseOfIonizingRadiationUnit.Picogray)] [InlineData("ru-RU", "рад", AbsorbedDoseOfIonizingRadiationUnit.Rad)] [InlineData("ru-RU", "ТГр", AbsorbedDoseOfIonizingRadiationUnit.Teragray)] - public void TryParseUnitWithCulture(string culture, string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, AbsorbedDoseOfIonizingRadiationUnit expectedUnit) { Assert.True(AbsorbedDoseOfIonizingRadiation.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AbsorbedDoseOfIonizingRadiationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs index fbff93d050..bde4732fae 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -696,10 +697,34 @@ public void TryParse() [InlineData("mg", AccelerationUnit.MillistandardGravity)] [InlineData("nm/s²", AccelerationUnit.NanometerPerSecondSquared)] [InlineData("g", AccelerationUnit.StandardGravity)] - public void ParseUnit(string abbreviation, AccelerationUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AccelerationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - AccelerationUnit parsedUnit = Acceleration.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + AccelerationUnit parsedUnit = Acceleration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm/s²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("dm/s²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("ft/s²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("in/s²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("km/s²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("kn/h", AccelerationUnit.KnotPerHour)] + [InlineData("kn/min", AccelerationUnit.KnotPerMinute)] + [InlineData("kn/s", AccelerationUnit.KnotPerSecond)] + [InlineData("m/s²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("µm/s²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("mm/s²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("mg", AccelerationUnit.MillistandardGravity)] + [InlineData("nm/s²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("g", AccelerationUnit.StandardGravity)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AccelerationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + AccelerationUnit parsedUnit = Acceleration.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -732,7 +757,43 @@ public void ParseUnit(string abbreviation, AccelerationUnit expectedUnit) [InlineData("ru-RU", "мg", AccelerationUnit.MillistandardGravity)] [InlineData("ru-RU", "нм/с²", AccelerationUnit.NanometerPerSecondSquared)] [InlineData("ru-RU", "g", AccelerationUnit.StandardGravity)] - public void ParseUnitWithCulture(string culture, string abbreviation, AccelerationUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, AccelerationUnit expectedUnit) + { + using var _ = new CultureScope(culture); + AccelerationUnit parsedUnit = Acceleration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm/s²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("en-US", "dm/s²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("en-US", "ft/s²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("en-US", "in/s²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("en-US", "km/s²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("en-US", "kn/h", AccelerationUnit.KnotPerHour)] + [InlineData("en-US", "kn/min", AccelerationUnit.KnotPerMinute)] + [InlineData("en-US", "kn/s", AccelerationUnit.KnotPerSecond)] + [InlineData("en-US", "m/s²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("en-US", "µm/s²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("en-US", "mm/s²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("en-US", "mg", AccelerationUnit.MillistandardGravity)] + [InlineData("en-US", "nm/s²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("en-US", "g", AccelerationUnit.StandardGravity)] + [InlineData("ru-RU", "см/с²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("ru-RU", "дм/с²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("ru-RU", "фут/с²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("ru-RU", "дюйм/с²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("ru-RU", "км/с²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("ru-RU", "узел/час", AccelerationUnit.KnotPerHour)] + [InlineData("ru-RU", "узел/мин", AccelerationUnit.KnotPerMinute)] + [InlineData("ru-RU", "узел/с", AccelerationUnit.KnotPerSecond)] + [InlineData("ru-RU", "м/с²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("ru-RU", "мкм/с²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("ru-RU", "мм/с²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("ru-RU", "мg", AccelerationUnit.MillistandardGravity)] + [InlineData("ru-RU", "нм/с²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("ru-RU", "g", AccelerationUnit.StandardGravity)] + public void ParseUnit_WithCulture(string culture, string abbreviation, AccelerationUnit expectedUnit) { AccelerationUnit parsedUnit = Acceleration.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -753,9 +814,69 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Accelerati [InlineData("mg", AccelerationUnit.MillistandardGravity)] [InlineData("nm/s²", AccelerationUnit.NanometerPerSecondSquared)] [InlineData("g", AccelerationUnit.StandardGravity)] - public void TryParseUnit(string abbreviation, AccelerationUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AccelerationUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Acceleration.TryParseUnit(abbreviation, out AccelerationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm/s²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("dm/s²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("ft/s²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("in/s²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("km/s²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("kn/h", AccelerationUnit.KnotPerHour)] + [InlineData("kn/min", AccelerationUnit.KnotPerMinute)] + [InlineData("kn/s", AccelerationUnit.KnotPerSecond)] + [InlineData("m/s²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("µm/s²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("mm/s²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("mg", AccelerationUnit.MillistandardGravity)] + [InlineData("nm/s²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("g", AccelerationUnit.StandardGravity)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AccelerationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Acceleration.TryParseUnit(abbreviation, out AccelerationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm/s²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("en-US", "dm/s²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("en-US", "ft/s²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("en-US", "in/s²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("en-US", "km/s²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("en-US", "kn/h", AccelerationUnit.KnotPerHour)] + [InlineData("en-US", "kn/min", AccelerationUnit.KnotPerMinute)] + [InlineData("en-US", "kn/s", AccelerationUnit.KnotPerSecond)] + [InlineData("en-US", "m/s²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("en-US", "µm/s²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("en-US", "mm/s²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("en-US", "mg", AccelerationUnit.MillistandardGravity)] + [InlineData("en-US", "nm/s²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("en-US", "g", AccelerationUnit.StandardGravity)] + [InlineData("ru-RU", "см/с²", AccelerationUnit.CentimeterPerSecondSquared)] + [InlineData("ru-RU", "дм/с²", AccelerationUnit.DecimeterPerSecondSquared)] + [InlineData("ru-RU", "фут/с²", AccelerationUnit.FootPerSecondSquared)] + [InlineData("ru-RU", "дюйм/с²", AccelerationUnit.InchPerSecondSquared)] + [InlineData("ru-RU", "км/с²", AccelerationUnit.KilometerPerSecondSquared)] + [InlineData("ru-RU", "узел/час", AccelerationUnit.KnotPerHour)] + [InlineData("ru-RU", "узел/мин", AccelerationUnit.KnotPerMinute)] + [InlineData("ru-RU", "узел/с", AccelerationUnit.KnotPerSecond)] + [InlineData("ru-RU", "м/с²", AccelerationUnit.MeterPerSecondSquared)] + [InlineData("ru-RU", "мкм/с²", AccelerationUnit.MicrometerPerSecondSquared)] + [InlineData("ru-RU", "мм/с²", AccelerationUnit.MillimeterPerSecondSquared)] + [InlineData("ru-RU", "мg", AccelerationUnit.MillistandardGravity)] + [InlineData("ru-RU", "нм/с²", AccelerationUnit.NanometerPerSecondSquared)] + [InlineData("ru-RU", "g", AccelerationUnit.StandardGravity)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, AccelerationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Acceleration.TryParseUnit(abbreviation, out AccelerationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -789,7 +910,7 @@ public void TryParseUnit(string abbreviation, AccelerationUnit expectedUnit) [InlineData("ru-RU", "мg", AccelerationUnit.MillistandardGravity)] [InlineData("ru-RU", "нм/с²", AccelerationUnit.NanometerPerSecondSquared)] [InlineData("ru-RU", "g", AccelerationUnit.StandardGravity)] - public void TryParseUnitWithCulture(string culture, string abbreviation, AccelerationUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, AccelerationUnit expectedUnit) { Assert.True(Acceleration.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AccelerationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs index 9af206c2c1..9d079f1ef8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -574,10 +575,37 @@ public void TryParse() [InlineData("nlbmol", AmountOfSubstanceUnit.NanopoundMole)] [InlineData("pmol", AmountOfSubstanceUnit.Picomole)] [InlineData("lbmol", AmountOfSubstanceUnit.PoundMole)] - public void ParseUnit(string abbreviation, AmountOfSubstanceUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AmountOfSubstanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - AmountOfSubstanceUnit parsedUnit = AmountOfSubstance.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + AmountOfSubstanceUnit parsedUnit = AmountOfSubstance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cmol", AmountOfSubstanceUnit.Centimole)] + [InlineData("clbmol", AmountOfSubstanceUnit.CentipoundMole)] + [InlineData("dmol", AmountOfSubstanceUnit.Decimole)] + [InlineData("dlbmol", AmountOfSubstanceUnit.DecipoundMole)] + [InlineData("fmol", AmountOfSubstanceUnit.Femtomole)] + [InlineData("kmol", AmountOfSubstanceUnit.Kilomole)] + [InlineData("klbmol", AmountOfSubstanceUnit.KilopoundMole)] + [InlineData("Mmol", AmountOfSubstanceUnit.Megamole)] + [InlineData("µmol", AmountOfSubstanceUnit.Micromole)] + [InlineData("µlbmol", AmountOfSubstanceUnit.MicropoundMole)] + [InlineData("mmol", AmountOfSubstanceUnit.Millimole)] + [InlineData("mlbmol", AmountOfSubstanceUnit.MillipoundMole)] + [InlineData("mol", AmountOfSubstanceUnit.Mole)] + [InlineData("nmol", AmountOfSubstanceUnit.Nanomole)] + [InlineData("nlbmol", AmountOfSubstanceUnit.NanopoundMole)] + [InlineData("pmol", AmountOfSubstanceUnit.Picomole)] + [InlineData("lbmol", AmountOfSubstanceUnit.PoundMole)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AmountOfSubstanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + AmountOfSubstanceUnit parsedUnit = AmountOfSubstance.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -599,7 +627,32 @@ public void ParseUnit(string abbreviation, AmountOfSubstanceUnit expectedUnit) [InlineData("en-US", "nlbmol", AmountOfSubstanceUnit.NanopoundMole)] [InlineData("en-US", "pmol", AmountOfSubstanceUnit.Picomole)] [InlineData("en-US", "lbmol", AmountOfSubstanceUnit.PoundMole)] - public void ParseUnitWithCulture(string culture, string abbreviation, AmountOfSubstanceUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, AmountOfSubstanceUnit expectedUnit) + { + using var _ = new CultureScope(culture); + AmountOfSubstanceUnit parsedUnit = AmountOfSubstance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cmol", AmountOfSubstanceUnit.Centimole)] + [InlineData("en-US", "clbmol", AmountOfSubstanceUnit.CentipoundMole)] + [InlineData("en-US", "dmol", AmountOfSubstanceUnit.Decimole)] + [InlineData("en-US", "dlbmol", AmountOfSubstanceUnit.DecipoundMole)] + [InlineData("en-US", "fmol", AmountOfSubstanceUnit.Femtomole)] + [InlineData("en-US", "kmol", AmountOfSubstanceUnit.Kilomole)] + [InlineData("en-US", "klbmol", AmountOfSubstanceUnit.KilopoundMole)] + [InlineData("en-US", "Mmol", AmountOfSubstanceUnit.Megamole)] + [InlineData("en-US", "µmol", AmountOfSubstanceUnit.Micromole)] + [InlineData("en-US", "µlbmol", AmountOfSubstanceUnit.MicropoundMole)] + [InlineData("en-US", "mmol", AmountOfSubstanceUnit.Millimole)] + [InlineData("en-US", "mlbmol", AmountOfSubstanceUnit.MillipoundMole)] + [InlineData("en-US", "mol", AmountOfSubstanceUnit.Mole)] + [InlineData("en-US", "nmol", AmountOfSubstanceUnit.Nanomole)] + [InlineData("en-US", "nlbmol", AmountOfSubstanceUnit.NanopoundMole)] + [InlineData("en-US", "pmol", AmountOfSubstanceUnit.Picomole)] + [InlineData("en-US", "lbmol", AmountOfSubstanceUnit.PoundMole)] + public void ParseUnit_WithCulture(string culture, string abbreviation, AmountOfSubstanceUnit expectedUnit) { AmountOfSubstanceUnit parsedUnit = AmountOfSubstance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -623,9 +676,61 @@ public void ParseUnitWithCulture(string culture, string abbreviation, AmountOfSu [InlineData("nlbmol", AmountOfSubstanceUnit.NanopoundMole)] [InlineData("pmol", AmountOfSubstanceUnit.Picomole)] [InlineData("lbmol", AmountOfSubstanceUnit.PoundMole)] - public void TryParseUnit(string abbreviation, AmountOfSubstanceUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AmountOfSubstanceUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(AmountOfSubstance.TryParseUnit(abbreviation, out AmountOfSubstanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cmol", AmountOfSubstanceUnit.Centimole)] + [InlineData("clbmol", AmountOfSubstanceUnit.CentipoundMole)] + [InlineData("dmol", AmountOfSubstanceUnit.Decimole)] + [InlineData("dlbmol", AmountOfSubstanceUnit.DecipoundMole)] + [InlineData("fmol", AmountOfSubstanceUnit.Femtomole)] + [InlineData("kmol", AmountOfSubstanceUnit.Kilomole)] + [InlineData("klbmol", AmountOfSubstanceUnit.KilopoundMole)] + [InlineData("Mmol", AmountOfSubstanceUnit.Megamole)] + [InlineData("µmol", AmountOfSubstanceUnit.Micromole)] + [InlineData("µlbmol", AmountOfSubstanceUnit.MicropoundMole)] + [InlineData("mmol", AmountOfSubstanceUnit.Millimole)] + [InlineData("mlbmol", AmountOfSubstanceUnit.MillipoundMole)] + [InlineData("mol", AmountOfSubstanceUnit.Mole)] + [InlineData("nmol", AmountOfSubstanceUnit.Nanomole)] + [InlineData("nlbmol", AmountOfSubstanceUnit.NanopoundMole)] + [InlineData("pmol", AmountOfSubstanceUnit.Picomole)] + [InlineData("lbmol", AmountOfSubstanceUnit.PoundMole)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AmountOfSubstanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(AmountOfSubstance.TryParseUnit(abbreviation, out AmountOfSubstanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cmol", AmountOfSubstanceUnit.Centimole)] + [InlineData("en-US", "clbmol", AmountOfSubstanceUnit.CentipoundMole)] + [InlineData("en-US", "dmol", AmountOfSubstanceUnit.Decimole)] + [InlineData("en-US", "dlbmol", AmountOfSubstanceUnit.DecipoundMole)] + [InlineData("en-US", "fmol", AmountOfSubstanceUnit.Femtomole)] + [InlineData("en-US", "kmol", AmountOfSubstanceUnit.Kilomole)] + [InlineData("en-US", "klbmol", AmountOfSubstanceUnit.KilopoundMole)] + [InlineData("en-US", "Mmol", AmountOfSubstanceUnit.Megamole)] + [InlineData("en-US", "µmol", AmountOfSubstanceUnit.Micromole)] + [InlineData("en-US", "µlbmol", AmountOfSubstanceUnit.MicropoundMole)] + [InlineData("en-US", "mmol", AmountOfSubstanceUnit.Millimole)] + [InlineData("en-US", "mlbmol", AmountOfSubstanceUnit.MillipoundMole)] + [InlineData("en-US", "mol", AmountOfSubstanceUnit.Mole)] + [InlineData("en-US", "nmol", AmountOfSubstanceUnit.Nanomole)] + [InlineData("en-US", "nlbmol", AmountOfSubstanceUnit.NanopoundMole)] + [InlineData("en-US", "pmol", AmountOfSubstanceUnit.Picomole)] + [InlineData("en-US", "lbmol", AmountOfSubstanceUnit.PoundMole)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, AmountOfSubstanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(AmountOfSubstance.TryParseUnit(abbreviation, out AmountOfSubstanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -648,7 +753,7 @@ public void TryParseUnit(string abbreviation, AmountOfSubstanceUnit expectedUnit [InlineData("en-US", "nlbmol", AmountOfSubstanceUnit.NanopoundMole)] [InlineData("en-US", "pmol", AmountOfSubstanceUnit.Picomole)] [InlineData("en-US", "lbmol", AmountOfSubstanceUnit.PoundMole)] - public void TryParseUnitWithCulture(string culture, string abbreviation, AmountOfSubstanceUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, AmountOfSubstanceUnit expectedUnit) { Assert.True(AmountOfSubstance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AmountOfSubstanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs index 8d3765aaf9..4332953b34 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -274,10 +275,24 @@ public void TryParse() [InlineData("dBmV", AmplitudeRatioUnit.DecibelMillivolt)] [InlineData("dBu", AmplitudeRatioUnit.DecibelUnloaded)] [InlineData("dBV", AmplitudeRatioUnit.DecibelVolt)] - public void ParseUnit(string abbreviation, AmplitudeRatioUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AmplitudeRatioUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - AmplitudeRatioUnit parsedUnit = AmplitudeRatio.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + AmplitudeRatioUnit parsedUnit = AmplitudeRatio.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("dBµV", AmplitudeRatioUnit.DecibelMicrovolt)] + [InlineData("dBmV", AmplitudeRatioUnit.DecibelMillivolt)] + [InlineData("dBu", AmplitudeRatioUnit.DecibelUnloaded)] + [InlineData("dBV", AmplitudeRatioUnit.DecibelVolt)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AmplitudeRatioUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + AmplitudeRatioUnit parsedUnit = AmplitudeRatio.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -286,7 +301,19 @@ public void ParseUnit(string abbreviation, AmplitudeRatioUnit expectedUnit) [InlineData("en-US", "dBmV", AmplitudeRatioUnit.DecibelMillivolt)] [InlineData("en-US", "dBu", AmplitudeRatioUnit.DecibelUnloaded)] [InlineData("en-US", "dBV", AmplitudeRatioUnit.DecibelVolt)] - public void ParseUnitWithCulture(string culture, string abbreviation, AmplitudeRatioUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, AmplitudeRatioUnit expectedUnit) + { + using var _ = new CultureScope(culture); + AmplitudeRatioUnit parsedUnit = AmplitudeRatio.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "dBµV", AmplitudeRatioUnit.DecibelMicrovolt)] + [InlineData("en-US", "dBmV", AmplitudeRatioUnit.DecibelMillivolt)] + [InlineData("en-US", "dBu", AmplitudeRatioUnit.DecibelUnloaded)] + [InlineData("en-US", "dBV", AmplitudeRatioUnit.DecibelVolt)] + public void ParseUnit_WithCulture(string culture, string abbreviation, AmplitudeRatioUnit expectedUnit) { AmplitudeRatioUnit parsedUnit = AmplitudeRatio.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -297,9 +324,35 @@ public void ParseUnitWithCulture(string culture, string abbreviation, AmplitudeR [InlineData("dBmV", AmplitudeRatioUnit.DecibelMillivolt)] [InlineData("dBu", AmplitudeRatioUnit.DecibelUnloaded)] [InlineData("dBV", AmplitudeRatioUnit.DecibelVolt)] - public void TryParseUnit(string abbreviation, AmplitudeRatioUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AmplitudeRatioUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(AmplitudeRatio.TryParseUnit(abbreviation, out AmplitudeRatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("dBµV", AmplitudeRatioUnit.DecibelMicrovolt)] + [InlineData("dBmV", AmplitudeRatioUnit.DecibelMillivolt)] + [InlineData("dBu", AmplitudeRatioUnit.DecibelUnloaded)] + [InlineData("dBV", AmplitudeRatioUnit.DecibelVolt)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AmplitudeRatioUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(AmplitudeRatio.TryParseUnit(abbreviation, out AmplitudeRatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "dBµV", AmplitudeRatioUnit.DecibelMicrovolt)] + [InlineData("en-US", "dBmV", AmplitudeRatioUnit.DecibelMillivolt)] + [InlineData("en-US", "dBu", AmplitudeRatioUnit.DecibelUnloaded)] + [InlineData("en-US", "dBV", AmplitudeRatioUnit.DecibelVolt)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, AmplitudeRatioUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(AmplitudeRatio.TryParseUnit(abbreviation, out AmplitudeRatioUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -309,7 +362,7 @@ public void TryParseUnit(string abbreviation, AmplitudeRatioUnit expectedUnit) [InlineData("en-US", "dBmV", AmplitudeRatioUnit.DecibelMillivolt)] [InlineData("en-US", "dBu", AmplitudeRatioUnit.DecibelUnloaded)] [InlineData("en-US", "dBV", AmplitudeRatioUnit.DecibelVolt)] - public void TryParseUnitWithCulture(string culture, string abbreviation, AmplitudeRatioUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, AmplitudeRatioUnit expectedUnit) { Assert.True(AmplitudeRatio.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AmplitudeRatioUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs index 3f574bd34b..87e77f4236 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AngleTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -834,10 +835,45 @@ public void TryParse() [InlineData("mil", AngleUnit.NatoMil)] [InlineData("rad", AngleUnit.Radian)] [InlineData("r", AngleUnit.Revolution)] - public void ParseUnit(string abbreviation, AngleUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AngleUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - AngleUnit parsedUnit = Angle.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + AngleUnit parsedUnit = Angle.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("'", AngleUnit.Arcminute)] + [InlineData("arcmin", AngleUnit.Arcminute)] + [InlineData("amin", AngleUnit.Arcminute)] + [InlineData("min", AngleUnit.Arcminute)] + [InlineData("″", AngleUnit.Arcsecond)] + [InlineData("arcsec", AngleUnit.Arcsecond)] + [InlineData("asec", AngleUnit.Arcsecond)] + [InlineData("sec", AngleUnit.Arcsecond)] + [InlineData("crad", AngleUnit.Centiradian)] + [InlineData("drad", AngleUnit.Deciradian)] + [InlineData("°", AngleUnit.Degree)] + [InlineData("deg", AngleUnit.Degree)] + [InlineData("g", AngleUnit.Gradian)] + [InlineData("µ°", AngleUnit.Microdegree)] + [InlineData("µdeg", AngleUnit.Microdegree)] + [InlineData("µrad", AngleUnit.Microradian)] + [InlineData("m°", AngleUnit.Millidegree)] + [InlineData("mdeg", AngleUnit.Millidegree)] + [InlineData("mrad", AngleUnit.Milliradian)] + [InlineData("n°", AngleUnit.Nanodegree)] + [InlineData("ndeg", AngleUnit.Nanodegree)] + [InlineData("nrad", AngleUnit.Nanoradian)] + [InlineData("mil", AngleUnit.NatoMil)] + [InlineData("rad", AngleUnit.Radian)] + [InlineData("r", AngleUnit.Revolution)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AngleUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + AngleUnit parsedUnit = Angle.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -879,7 +915,52 @@ public void ParseUnit(string abbreviation, AngleUnit expectedUnit) [InlineData("ru-RU", "нрад", AngleUnit.Nanoradian)] [InlineData("ru-RU", "рад", AngleUnit.Radian)] [InlineData("ru-RU", "r", AngleUnit.Revolution)] - public void ParseUnitWithCulture(string culture, string abbreviation, AngleUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, AngleUnit expectedUnit) + { + using var _ = new CultureScope(culture); + AngleUnit parsedUnit = Angle.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "'", AngleUnit.Arcminute)] + [InlineData("en-US", "arcmin", AngleUnit.Arcminute)] + [InlineData("en-US", "amin", AngleUnit.Arcminute)] + [InlineData("en-US", "min", AngleUnit.Arcminute)] + [InlineData("en-US", "″", AngleUnit.Arcsecond)] + [InlineData("en-US", "arcsec", AngleUnit.Arcsecond)] + [InlineData("en-US", "asec", AngleUnit.Arcsecond)] + [InlineData("en-US", "sec", AngleUnit.Arcsecond)] + [InlineData("en-US", "crad", AngleUnit.Centiradian)] + [InlineData("en-US", "drad", AngleUnit.Deciradian)] + [InlineData("en-US", "°", AngleUnit.Degree)] + [InlineData("en-US", "deg", AngleUnit.Degree)] + [InlineData("en-US", "g", AngleUnit.Gradian)] + [InlineData("en-US", "µ°", AngleUnit.Microdegree)] + [InlineData("en-US", "µdeg", AngleUnit.Microdegree)] + [InlineData("en-US", "µrad", AngleUnit.Microradian)] + [InlineData("en-US", "m°", AngleUnit.Millidegree)] + [InlineData("en-US", "mdeg", AngleUnit.Millidegree)] + [InlineData("en-US", "mrad", AngleUnit.Milliradian)] + [InlineData("en-US", "n°", AngleUnit.Nanodegree)] + [InlineData("en-US", "ndeg", AngleUnit.Nanodegree)] + [InlineData("en-US", "nrad", AngleUnit.Nanoradian)] + [InlineData("en-US", "mil", AngleUnit.NatoMil)] + [InlineData("en-US", "rad", AngleUnit.Radian)] + [InlineData("en-US", "r", AngleUnit.Revolution)] + [InlineData("ru-RU", "срад", AngleUnit.Centiradian)] + [InlineData("ru-RU", "драд", AngleUnit.Deciradian)] + [InlineData("ru-RU", "°", AngleUnit.Degree)] + [InlineData("ru-RU", "g", AngleUnit.Gradian)] + [InlineData("ru-RU", "мк°", AngleUnit.Microdegree)] + [InlineData("ru-RU", "мкрад", AngleUnit.Microradian)] + [InlineData("ru-RU", "м°", AngleUnit.Millidegree)] + [InlineData("ru-RU", "мрад", AngleUnit.Milliradian)] + [InlineData("ru-RU", "н°", AngleUnit.Nanodegree)] + [InlineData("ru-RU", "нрад", AngleUnit.Nanoradian)] + [InlineData("ru-RU", "рад", AngleUnit.Radian)] + [InlineData("ru-RU", "r", AngleUnit.Revolution)] + public void ParseUnit_WithCulture(string culture, string abbreviation, AngleUnit expectedUnit) { AngleUnit parsedUnit = Angle.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -911,9 +992,89 @@ public void ParseUnitWithCulture(string culture, string abbreviation, AngleUnit [InlineData("mil", AngleUnit.NatoMil)] [InlineData("rad", AngleUnit.Radian)] [InlineData("r", AngleUnit.Revolution)] - public void TryParseUnit(string abbreviation, AngleUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AngleUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Angle.TryParseUnit(abbreviation, out AngleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("'", AngleUnit.Arcminute)] + [InlineData("arcmin", AngleUnit.Arcminute)] + [InlineData("amin", AngleUnit.Arcminute)] + [InlineData("min", AngleUnit.Arcminute)] + [InlineData("″", AngleUnit.Arcsecond)] + [InlineData("arcsec", AngleUnit.Arcsecond)] + [InlineData("asec", AngleUnit.Arcsecond)] + [InlineData("sec", AngleUnit.Arcsecond)] + [InlineData("crad", AngleUnit.Centiradian)] + [InlineData("drad", AngleUnit.Deciradian)] + [InlineData("°", AngleUnit.Degree)] + [InlineData("deg", AngleUnit.Degree)] + [InlineData("g", AngleUnit.Gradian)] + [InlineData("µ°", AngleUnit.Microdegree)] + [InlineData("µdeg", AngleUnit.Microdegree)] + [InlineData("µrad", AngleUnit.Microradian)] + [InlineData("m°", AngleUnit.Millidegree)] + [InlineData("mdeg", AngleUnit.Millidegree)] + [InlineData("mrad", AngleUnit.Milliradian)] + [InlineData("n°", AngleUnit.Nanodegree)] + [InlineData("ndeg", AngleUnit.Nanodegree)] + [InlineData("nrad", AngleUnit.Nanoradian)] + [InlineData("mil", AngleUnit.NatoMil)] + [InlineData("rad", AngleUnit.Radian)] + [InlineData("r", AngleUnit.Revolution)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AngleUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Angle.TryParseUnit(abbreviation, out AngleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "'", AngleUnit.Arcminute)] + [InlineData("en-US", "arcmin", AngleUnit.Arcminute)] + [InlineData("en-US", "amin", AngleUnit.Arcminute)] + [InlineData("en-US", "min", AngleUnit.Arcminute)] + [InlineData("en-US", "″", AngleUnit.Arcsecond)] + [InlineData("en-US", "arcsec", AngleUnit.Arcsecond)] + [InlineData("en-US", "asec", AngleUnit.Arcsecond)] + [InlineData("en-US", "sec", AngleUnit.Arcsecond)] + [InlineData("en-US", "crad", AngleUnit.Centiradian)] + [InlineData("en-US", "drad", AngleUnit.Deciradian)] + [InlineData("en-US", "°", AngleUnit.Degree)] + [InlineData("en-US", "deg", AngleUnit.Degree)] + [InlineData("en-US", "g", AngleUnit.Gradian)] + [InlineData("en-US", "µ°", AngleUnit.Microdegree)] + [InlineData("en-US", "µdeg", AngleUnit.Microdegree)] + [InlineData("en-US", "µrad", AngleUnit.Microradian)] + [InlineData("en-US", "m°", AngleUnit.Millidegree)] + [InlineData("en-US", "mdeg", AngleUnit.Millidegree)] + [InlineData("en-US", "mrad", AngleUnit.Milliradian)] + [InlineData("en-US", "n°", AngleUnit.Nanodegree)] + [InlineData("en-US", "ndeg", AngleUnit.Nanodegree)] + [InlineData("en-US", "nrad", AngleUnit.Nanoradian)] + [InlineData("en-US", "mil", AngleUnit.NatoMil)] + [InlineData("en-US", "rad", AngleUnit.Radian)] + [InlineData("en-US", "r", AngleUnit.Revolution)] + [InlineData("ru-RU", "срад", AngleUnit.Centiradian)] + [InlineData("ru-RU", "драд", AngleUnit.Deciradian)] + [InlineData("ru-RU", "°", AngleUnit.Degree)] + [InlineData("ru-RU", "g", AngleUnit.Gradian)] + [InlineData("ru-RU", "мк°", AngleUnit.Microdegree)] + [InlineData("ru-RU", "мкрад", AngleUnit.Microradian)] + [InlineData("ru-RU", "м°", AngleUnit.Millidegree)] + [InlineData("ru-RU", "мрад", AngleUnit.Milliradian)] + [InlineData("ru-RU", "н°", AngleUnit.Nanodegree)] + [InlineData("ru-RU", "нрад", AngleUnit.Nanoradian)] + [InlineData("ru-RU", "рад", AngleUnit.Radian)] + [InlineData("ru-RU", "r", AngleUnit.Revolution)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, AngleUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Angle.TryParseUnit(abbreviation, out AngleUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -956,7 +1117,7 @@ public void TryParseUnit(string abbreviation, AngleUnit expectedUnit) [InlineData("ru-RU", "нрад", AngleUnit.Nanoradian)] [InlineData("ru-RU", "рад", AngleUnit.Radian)] [InlineData("ru-RU", "r", AngleUnit.Revolution)] - public void TryParseUnitWithCulture(string culture, string abbreviation, AngleUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, AngleUnit expectedUnit) { Assert.True(Angle.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AngleUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs index ff6d078ce1..8f227e20bb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentEnergyTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -250,10 +251,23 @@ public void TryParse() [InlineData("kVAh", ApparentEnergyUnit.KilovoltampereHour)] [InlineData("MVAh", ApparentEnergyUnit.MegavoltampereHour)] [InlineData("VAh", ApparentEnergyUnit.VoltampereHour)] - public void ParseUnit(string abbreviation, ApparentEnergyUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ApparentEnergyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ApparentEnergyUnit parsedUnit = ApparentEnergy.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ApparentEnergyUnit parsedUnit = ApparentEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kVAh", ApparentEnergyUnit.KilovoltampereHour)] + [InlineData("MVAh", ApparentEnergyUnit.MegavoltampereHour)] + [InlineData("VAh", ApparentEnergyUnit.VoltampereHour)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ApparentEnergyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ApparentEnergyUnit parsedUnit = ApparentEnergy.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -261,7 +275,18 @@ public void ParseUnit(string abbreviation, ApparentEnergyUnit expectedUnit) [InlineData("en-US", "kVAh", ApparentEnergyUnit.KilovoltampereHour)] [InlineData("en-US", "MVAh", ApparentEnergyUnit.MegavoltampereHour)] [InlineData("en-US", "VAh", ApparentEnergyUnit.VoltampereHour)] - public void ParseUnitWithCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ApparentEnergyUnit parsedUnit = ApparentEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kVAh", ApparentEnergyUnit.KilovoltampereHour)] + [InlineData("en-US", "MVAh", ApparentEnergyUnit.MegavoltampereHour)] + [InlineData("en-US", "VAh", ApparentEnergyUnit.VoltampereHour)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) { ApparentEnergyUnit parsedUnit = ApparentEnergy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -271,9 +296,33 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ApparentEn [InlineData("kVAh", ApparentEnergyUnit.KilovoltampereHour)] [InlineData("MVAh", ApparentEnergyUnit.MegavoltampereHour)] [InlineData("VAh", ApparentEnergyUnit.VoltampereHour)] - public void TryParseUnit(string abbreviation, ApparentEnergyUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ApparentEnergyUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ApparentEnergy.TryParseUnit(abbreviation, out ApparentEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kVAh", ApparentEnergyUnit.KilovoltampereHour)] + [InlineData("MVAh", ApparentEnergyUnit.MegavoltampereHour)] + [InlineData("VAh", ApparentEnergyUnit.VoltampereHour)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ApparentEnergyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ApparentEnergy.TryParseUnit(abbreviation, out ApparentEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kVAh", ApparentEnergyUnit.KilovoltampereHour)] + [InlineData("en-US", "MVAh", ApparentEnergyUnit.MegavoltampereHour)] + [InlineData("en-US", "VAh", ApparentEnergyUnit.VoltampereHour)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ApparentEnergy.TryParseUnit(abbreviation, out ApparentEnergyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -282,7 +331,7 @@ public void TryParseUnit(string abbreviation, ApparentEnergyUnit expectedUnit) [InlineData("en-US", "kVAh", ApparentEnergyUnit.KilovoltampereHour)] [InlineData("en-US", "MVAh", ApparentEnergyUnit.MegavoltampereHour)] [InlineData("en-US", "VAh", ApparentEnergyUnit.VoltampereHour)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ApparentEnergyUnit expectedUnit) { Assert.True(ApparentEnergy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ApparentEnergyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs index edba712ac8..5b9bedae26 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ApparentPowerTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -310,10 +311,26 @@ public void TryParse() [InlineData("µVA", ApparentPowerUnit.Microvoltampere)] [InlineData("mVA", ApparentPowerUnit.Millivoltampere)] [InlineData("VA", ApparentPowerUnit.Voltampere)] - public void ParseUnit(string abbreviation, ApparentPowerUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ApparentPowerUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ApparentPowerUnit parsedUnit = ApparentPower.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ApparentPowerUnit parsedUnit = ApparentPower.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("GVA", ApparentPowerUnit.Gigavoltampere)] + [InlineData("kVA", ApparentPowerUnit.Kilovoltampere)] + [InlineData("MVA", ApparentPowerUnit.Megavoltampere)] + [InlineData("µVA", ApparentPowerUnit.Microvoltampere)] + [InlineData("mVA", ApparentPowerUnit.Millivoltampere)] + [InlineData("VA", ApparentPowerUnit.Voltampere)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ApparentPowerUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ApparentPowerUnit parsedUnit = ApparentPower.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -324,7 +341,21 @@ public void ParseUnit(string abbreviation, ApparentPowerUnit expectedUnit) [InlineData("en-US", "µVA", ApparentPowerUnit.Microvoltampere)] [InlineData("en-US", "mVA", ApparentPowerUnit.Millivoltampere)] [InlineData("en-US", "VA", ApparentPowerUnit.Voltampere)] - public void ParseUnitWithCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ApparentPowerUnit parsedUnit = ApparentPower.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "GVA", ApparentPowerUnit.Gigavoltampere)] + [InlineData("en-US", "kVA", ApparentPowerUnit.Kilovoltampere)] + [InlineData("en-US", "MVA", ApparentPowerUnit.Megavoltampere)] + [InlineData("en-US", "µVA", ApparentPowerUnit.Microvoltampere)] + [InlineData("en-US", "mVA", ApparentPowerUnit.Millivoltampere)] + [InlineData("en-US", "VA", ApparentPowerUnit.Voltampere)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) { ApparentPowerUnit parsedUnit = ApparentPower.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -337,9 +368,39 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ApparentPo [InlineData("µVA", ApparentPowerUnit.Microvoltampere)] [InlineData("mVA", ApparentPowerUnit.Millivoltampere)] [InlineData("VA", ApparentPowerUnit.Voltampere)] - public void TryParseUnit(string abbreviation, ApparentPowerUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ApparentPowerUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ApparentPower.TryParseUnit(abbreviation, out ApparentPowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("GVA", ApparentPowerUnit.Gigavoltampere)] + [InlineData("kVA", ApparentPowerUnit.Kilovoltampere)] + [InlineData("MVA", ApparentPowerUnit.Megavoltampere)] + [InlineData("µVA", ApparentPowerUnit.Microvoltampere)] + [InlineData("mVA", ApparentPowerUnit.Millivoltampere)] + [InlineData("VA", ApparentPowerUnit.Voltampere)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ApparentPowerUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ApparentPower.TryParseUnit(abbreviation, out ApparentPowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "GVA", ApparentPowerUnit.Gigavoltampere)] + [InlineData("en-US", "kVA", ApparentPowerUnit.Kilovoltampere)] + [InlineData("en-US", "MVA", ApparentPowerUnit.Megavoltampere)] + [InlineData("en-US", "µVA", ApparentPowerUnit.Microvoltampere)] + [InlineData("en-US", "mVA", ApparentPowerUnit.Millivoltampere)] + [InlineData("en-US", "VA", ApparentPowerUnit.Voltampere)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ApparentPower.TryParseUnit(abbreviation, out ApparentPowerUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -351,7 +412,7 @@ public void TryParseUnit(string abbreviation, ApparentPowerUnit expectedUnit) [InlineData("en-US", "µVA", ApparentPowerUnit.Microvoltampere)] [InlineData("en-US", "mVA", ApparentPowerUnit.Millivoltampere)] [InlineData("en-US", "VA", ApparentPowerUnit.Voltampere)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ApparentPowerUnit expectedUnit) { Assert.True(ApparentPower.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ApparentPowerUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs index 767001e0ab..d6774f1390 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaDensityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -264,10 +265,24 @@ public void TryParse() [InlineData("gsm", AreaDensityUnit.GramPerSquareMeter)] [InlineData("kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] [InlineData("mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] - public void ParseUnit(string abbreviation, AreaDensityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AreaDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - AreaDensityUnit parsedUnit = AreaDensity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + AreaDensityUnit parsedUnit = AreaDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g/m²", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("gsm", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] + [InlineData("mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AreaDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + AreaDensityUnit parsedUnit = AreaDensity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -276,7 +291,19 @@ public void ParseUnit(string abbreviation, AreaDensityUnit expectedUnit) [InlineData("en-US", "gsm", AreaDensityUnit.GramPerSquareMeter)] [InlineData("en-US", "kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] [InlineData("en-US", "mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, AreaDensityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, AreaDensityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + AreaDensityUnit parsedUnit = AreaDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g/m²", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("en-US", "gsm", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("en-US", "kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] + [InlineData("en-US", "mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, AreaDensityUnit expectedUnit) { AreaDensityUnit parsedUnit = AreaDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -287,9 +314,35 @@ public void ParseUnitWithCulture(string culture, string abbreviation, AreaDensit [InlineData("gsm", AreaDensityUnit.GramPerSquareMeter)] [InlineData("kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] [InlineData("mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] - public void TryParseUnit(string abbreviation, AreaDensityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AreaDensityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(AreaDensity.TryParseUnit(abbreviation, out AreaDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g/m²", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("gsm", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] + [InlineData("mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AreaDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(AreaDensity.TryParseUnit(abbreviation, out AreaDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g/m²", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("en-US", "gsm", AreaDensityUnit.GramPerSquareMeter)] + [InlineData("en-US", "kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] + [InlineData("en-US", "mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, AreaDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(AreaDensity.TryParseUnit(abbreviation, out AreaDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -299,7 +352,7 @@ public void TryParseUnit(string abbreviation, AreaDensityUnit expectedUnit) [InlineData("en-US", "gsm", AreaDensityUnit.GramPerSquareMeter)] [InlineData("en-US", "kg/m²", AreaDensityUnit.KilogramPerSquareMeter)] [InlineData("en-US", "mg/m²", AreaDensityUnit.MilligramPerSquareMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, AreaDensityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, AreaDensityUnit expectedUnit) { Assert.True(AreaDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AreaDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs index 4bfae0e4fb..5b55a5f23f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaMomentOfInertiaTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -406,10 +407,32 @@ public void TryParse() [InlineData("m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] [InlineData("mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] [InlineData("mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] - public void ParseUnit(string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AreaMomentOfInertiaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - AreaMomentOfInertiaUnit parsedUnit = AreaMomentOfInertia.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + AreaMomentOfInertiaUnit parsedUnit = AreaMomentOfInertia.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm⁴", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("cm^4", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("dm⁴", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("dm^4", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("ft⁴", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("ft^4", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("in⁴", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("in^4", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("m⁴", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + [InlineData("mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + AreaMomentOfInertiaUnit parsedUnit = AreaMomentOfInertia.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -426,7 +449,27 @@ public void ParseUnit(string abbreviation, AreaMomentOfInertiaUnit expectedUnit) [InlineData("en-US", "m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] [InlineData("en-US", "mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] [InlineData("en-US", "mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] - public void ParseUnitWithCulture(string culture, string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + { + using var _ = new CultureScope(culture); + AreaMomentOfInertiaUnit parsedUnit = AreaMomentOfInertia.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm⁴", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("en-US", "cm^4", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("en-US", "dm⁴", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("en-US", "dm^4", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("en-US", "ft⁴", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("en-US", "ft^4", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("en-US", "in⁴", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("en-US", "in^4", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("en-US", "m⁴", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("en-US", "m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("en-US", "mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + [InlineData("en-US", "mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + public void ParseUnit_WithCulture(string culture, string abbreviation, AreaMomentOfInertiaUnit expectedUnit) { AreaMomentOfInertiaUnit parsedUnit = AreaMomentOfInertia.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -445,9 +488,51 @@ public void ParseUnitWithCulture(string culture, string abbreviation, AreaMoment [InlineData("m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] [InlineData("mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] [InlineData("mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] - public void TryParseUnit(string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(AreaMomentOfInertia.TryParseUnit(abbreviation, out AreaMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm⁴", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("cm^4", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("dm⁴", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("dm^4", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("ft⁴", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("ft^4", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("in⁴", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("in^4", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("m⁴", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + [InlineData("mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(AreaMomentOfInertia.TryParseUnit(abbreviation, out AreaMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm⁴", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("en-US", "cm^4", AreaMomentOfInertiaUnit.CentimeterToTheFourth)] + [InlineData("en-US", "dm⁴", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("en-US", "dm^4", AreaMomentOfInertiaUnit.DecimeterToTheFourth)] + [InlineData("en-US", "ft⁴", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("en-US", "ft^4", AreaMomentOfInertiaUnit.FootToTheFourth)] + [InlineData("en-US", "in⁴", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("en-US", "in^4", AreaMomentOfInertiaUnit.InchToTheFourth)] + [InlineData("en-US", "m⁴", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("en-US", "m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] + [InlineData("en-US", "mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + [InlineData("en-US", "mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, AreaMomentOfInertiaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(AreaMomentOfInertia.TryParseUnit(abbreviation, out AreaMomentOfInertiaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -465,7 +550,7 @@ public void TryParseUnit(string abbreviation, AreaMomentOfInertiaUnit expectedUn [InlineData("en-US", "m^4", AreaMomentOfInertiaUnit.MeterToTheFourth)] [InlineData("en-US", "mm⁴", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] [InlineData("en-US", "mm^4", AreaMomentOfInertiaUnit.MillimeterToTheFourth)] - public void TryParseUnitWithCulture(string culture, string abbreviation, AreaMomentOfInertiaUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, AreaMomentOfInertiaUnit expectedUnit) { Assert.True(AreaMomentOfInertia.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AreaMomentOfInertiaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs index 7035b42f49..e417282f9a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/AreaTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -853,10 +854,81 @@ public void TryParse() [InlineData("nmi²", AreaUnit.SquareNauticalMile)] [InlineData("yd²", AreaUnit.SquareYard)] [InlineData("ft² (US)", AreaUnit.UsSurveySquareFoot)] - public void ParseUnit(string abbreviation, AreaUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AreaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - AreaUnit parsedUnit = Area.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + AreaUnit parsedUnit = Area.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("ac", AreaUnit.Acre)] + [InlineData("ha", AreaUnit.Hectare)] + [InlineData("cm²", AreaUnit.SquareCentimeter)] + [InlineData("dm²", AreaUnit.SquareDecimeter)] + [InlineData("ft²", AreaUnit.SquareFoot)] + [InlineData("in²", AreaUnit.SquareInch)] + [InlineData("km²", AreaUnit.SquareKilometer)] + [InlineData("m²", AreaUnit.SquareMeter)] + [InlineData("µm²", AreaUnit.SquareMicrometer)] + [InlineData("mi²", AreaUnit.SquareMile)] + [InlineData("mm²", AreaUnit.SquareMillimeter)] + [InlineData("nmi²", AreaUnit.SquareNauticalMile)] + [InlineData("yd²", AreaUnit.SquareYard)] + [InlineData("ft² (US)", AreaUnit.UsSurveySquareFoot)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AreaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + AreaUnit parsedUnit = Area.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "ac", AreaUnit.Acre)] + [InlineData("en-US", "ha", AreaUnit.Hectare)] + [InlineData("en-US", "cm²", AreaUnit.SquareCentimeter)] + [InlineData("en-US", "dm²", AreaUnit.SquareDecimeter)] + [InlineData("en-US", "ft²", AreaUnit.SquareFoot)] + [InlineData("en-US", "in²", AreaUnit.SquareInch)] + [InlineData("en-US", "km²", AreaUnit.SquareKilometer)] + [InlineData("en-US", "m²", AreaUnit.SquareMeter)] + [InlineData("en-US", "µm²", AreaUnit.SquareMicrometer)] + [InlineData("en-US", "mi²", AreaUnit.SquareMile)] + [InlineData("en-US", "mm²", AreaUnit.SquareMillimeter)] + [InlineData("en-US", "nmi²", AreaUnit.SquareNauticalMile)] + [InlineData("en-US", "yd²", AreaUnit.SquareYard)] + [InlineData("en-US", "ft² (US)", AreaUnit.UsSurveySquareFoot)] + [InlineData("ru-RU", "акр", AreaUnit.Acre)] + [InlineData("ru-RU", "га", AreaUnit.Hectare)] + [InlineData("ru-RU", "см²", AreaUnit.SquareCentimeter)] + [InlineData("ru-RU", "дм²", AreaUnit.SquareDecimeter)] + [InlineData("ru-RU", "фут²", AreaUnit.SquareFoot)] + [InlineData("ru-RU", "дюйм²", AreaUnit.SquareInch)] + [InlineData("ru-RU", "км²", AreaUnit.SquareKilometer)] + [InlineData("ru-RU", "м²", AreaUnit.SquareMeter)] + [InlineData("ru-RU", "мкм²", AreaUnit.SquareMicrometer)] + [InlineData("ru-RU", "миля²", AreaUnit.SquareMile)] + [InlineData("ru-RU", "мм²", AreaUnit.SquareMillimeter)] + [InlineData("ru-RU", "морск.миля²", AreaUnit.SquareNauticalMile)] + [InlineData("ru-RU", "ярд²", AreaUnit.SquareYard)] + [InlineData("ru-RU", "фут² (US)", AreaUnit.UsSurveySquareFoot)] + [InlineData("zh-CN", "平方厘米", AreaUnit.SquareCentimeter)] + [InlineData("zh-CN", "平方分米", AreaUnit.SquareDecimeter)] + [InlineData("zh-CN", "平方英尺", AreaUnit.SquareFoot)] + [InlineData("zh-CN", "平方英寸", AreaUnit.SquareInch)] + [InlineData("zh-CN", "平方公里", AreaUnit.SquareKilometer)] + [InlineData("zh-CN", "平方米", AreaUnit.SquareMeter)] + [InlineData("zh-CN", "平方微米", AreaUnit.SquareMicrometer)] + [InlineData("zh-CN", "平方英里", AreaUnit.SquareMile)] + [InlineData("zh-CN", "平方毫米", AreaUnit.SquareMillimeter)] + [InlineData("zh-CN", "平方海里", AreaUnit.SquareNauticalMile)] + [InlineData("zh-CN", "平方码", AreaUnit.SquareYard)] + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, AreaUnit expectedUnit) + { + using var _ = new CultureScope(culture); + AreaUnit parsedUnit = Area.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -900,7 +972,7 @@ public void ParseUnit(string abbreviation, AreaUnit expectedUnit) [InlineData("zh-CN", "平方毫米", AreaUnit.SquareMillimeter)] [InlineData("zh-CN", "平方海里", AreaUnit.SquareNauticalMile)] [InlineData("zh-CN", "平方码", AreaUnit.SquareYard)] - public void ParseUnitWithCulture(string culture, string abbreviation, AreaUnit expectedUnit) + public void ParseUnit_WithCulture(string culture, string abbreviation, AreaUnit expectedUnit) { AreaUnit parsedUnit = Area.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -928,9 +1000,80 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati [InlineData("nmi²", AreaUnit.SquareNauticalMile)] [InlineData("yd²", AreaUnit.SquareYard)] [InlineData("ft² (US)", AreaUnit.UsSurveySquareFoot)] - public void TryParseUnit(string abbreviation, AreaUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, AreaUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Area.TryParseUnit(abbreviation, out AreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("ac", AreaUnit.Acre)] + [InlineData("ha", AreaUnit.Hectare)] + [InlineData("cm²", AreaUnit.SquareCentimeter)] + [InlineData("dm²", AreaUnit.SquareDecimeter)] + [InlineData("ft²", AreaUnit.SquareFoot)] + [InlineData("in²", AreaUnit.SquareInch)] + [InlineData("km²", AreaUnit.SquareKilometer)] + [InlineData("m²", AreaUnit.SquareMeter)] + [InlineData("µm²", AreaUnit.SquareMicrometer)] + [InlineData("mi²", AreaUnit.SquareMile)] + [InlineData("mm²", AreaUnit.SquareMillimeter)] + [InlineData("nmi²", AreaUnit.SquareNauticalMile)] + [InlineData("yd²", AreaUnit.SquareYard)] + [InlineData("ft² (US)", AreaUnit.UsSurveySquareFoot)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, AreaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Area.TryParseUnit(abbreviation, out AreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "ac", AreaUnit.Acre)] + [InlineData("en-US", "ha", AreaUnit.Hectare)] + [InlineData("en-US", "cm²", AreaUnit.SquareCentimeter)] + [InlineData("en-US", "dm²", AreaUnit.SquareDecimeter)] + [InlineData("en-US", "ft²", AreaUnit.SquareFoot)] + [InlineData("en-US", "in²", AreaUnit.SquareInch)] + [InlineData("en-US", "km²", AreaUnit.SquareKilometer)] + [InlineData("en-US", "m²", AreaUnit.SquareMeter)] + [InlineData("en-US", "µm²", AreaUnit.SquareMicrometer)] + [InlineData("en-US", "mi²", AreaUnit.SquareMile)] + [InlineData("en-US", "mm²", AreaUnit.SquareMillimeter)] + [InlineData("en-US", "nmi²", AreaUnit.SquareNauticalMile)] + [InlineData("en-US", "yd²", AreaUnit.SquareYard)] + [InlineData("en-US", "ft² (US)", AreaUnit.UsSurveySquareFoot)] + [InlineData("ru-RU", "акр", AreaUnit.Acre)] + [InlineData("ru-RU", "га", AreaUnit.Hectare)] + [InlineData("ru-RU", "см²", AreaUnit.SquareCentimeter)] + [InlineData("ru-RU", "дм²", AreaUnit.SquareDecimeter)] + [InlineData("ru-RU", "фут²", AreaUnit.SquareFoot)] + [InlineData("ru-RU", "дюйм²", AreaUnit.SquareInch)] + [InlineData("ru-RU", "км²", AreaUnit.SquareKilometer)] + [InlineData("ru-RU", "м²", AreaUnit.SquareMeter)] + [InlineData("ru-RU", "мкм²", AreaUnit.SquareMicrometer)] + [InlineData("ru-RU", "миля²", AreaUnit.SquareMile)] + [InlineData("ru-RU", "мм²", AreaUnit.SquareMillimeter)] + [InlineData("ru-RU", "морск.миля²", AreaUnit.SquareNauticalMile)] + [InlineData("ru-RU", "ярд²", AreaUnit.SquareYard)] + [InlineData("ru-RU", "фут² (US)", AreaUnit.UsSurveySquareFoot)] + [InlineData("zh-CN", "平方厘米", AreaUnit.SquareCentimeter)] + [InlineData("zh-CN", "平方分米", AreaUnit.SquareDecimeter)] + [InlineData("zh-CN", "平方英尺", AreaUnit.SquareFoot)] + [InlineData("zh-CN", "平方英寸", AreaUnit.SquareInch)] + [InlineData("zh-CN", "平方公里", AreaUnit.SquareKilometer)] + [InlineData("zh-CN", "平方米", AreaUnit.SquareMeter)] + [InlineData("zh-CN", "平方微米", AreaUnit.SquareMicrometer)] + [InlineData("zh-CN", "平方英里", AreaUnit.SquareMile)] + [InlineData("zh-CN", "平方毫米", AreaUnit.SquareMillimeter)] + [InlineData("zh-CN", "平方海里", AreaUnit.SquareNauticalMile)] + [InlineData("zh-CN", "平方码", AreaUnit.SquareYard)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, AreaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Area.TryParseUnit(abbreviation, out AreaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -975,7 +1118,7 @@ public void TryParseUnit(string abbreviation, AreaUnit expectedUnit) [InlineData("zh-CN", "平方毫米", AreaUnit.SquareMillimeter)] [InlineData("zh-CN", "平方海里", AreaUnit.SquareNauticalMile)] [InlineData("zh-CN", "平方码", AreaUnit.SquareYard)] - public void TryParseUnitWithCulture(string culture, string abbreviation, AreaUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, AreaUnit expectedUnit) { Assert.True(Area.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out AreaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs index e952925d43..869bf15a89 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BitRateTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -984,10 +985,59 @@ public void TryParse() [InlineData("Tbit/s", BitRateUnit.TerabitPerSecond)] [InlineData("Tbps", BitRateUnit.TerabitPerSecond)] [InlineData("TB/s", BitRateUnit.TerabytePerSecond)] - public void ParseUnit(string abbreviation, BitRateUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, BitRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - BitRateUnit parsedUnit = BitRate.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + BitRateUnit parsedUnit = BitRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("bit/s", BitRateUnit.BitPerSecond)] + [InlineData("bps", BitRateUnit.BitPerSecond)] + [InlineData("B/s", BitRateUnit.BytePerSecond)] + [InlineData("Ebit/s", BitRateUnit.ExabitPerSecond)] + [InlineData("Ebps", BitRateUnit.ExabitPerSecond)] + [InlineData("EB/s", BitRateUnit.ExabytePerSecond)] + [InlineData("Eibit/s", BitRateUnit.ExbibitPerSecond)] + [InlineData("Eibps", BitRateUnit.ExbibitPerSecond)] + [InlineData("EiB/s", BitRateUnit.ExbibytePerSecond)] + [InlineData("Gibit/s", BitRateUnit.GibibitPerSecond)] + [InlineData("Gibps", BitRateUnit.GibibitPerSecond)] + [InlineData("GiB/s", BitRateUnit.GibibytePerSecond)] + [InlineData("Gbit/s", BitRateUnit.GigabitPerSecond)] + [InlineData("Gbps", BitRateUnit.GigabitPerSecond)] + [InlineData("GB/s", BitRateUnit.GigabytePerSecond)] + [InlineData("Kibit/s", BitRateUnit.KibibitPerSecond)] + [InlineData("Kibps", BitRateUnit.KibibitPerSecond)] + [InlineData("KiB/s", BitRateUnit.KibibytePerSecond)] + [InlineData("kbit/s", BitRateUnit.KilobitPerSecond)] + [InlineData("kbps", BitRateUnit.KilobitPerSecond)] + [InlineData("kB/s", BitRateUnit.KilobytePerSecond)] + [InlineData("Mibit/s", BitRateUnit.MebibitPerSecond)] + [InlineData("Mibps", BitRateUnit.MebibitPerSecond)] + [InlineData("MiB/s", BitRateUnit.MebibytePerSecond)] + [InlineData("Mbit/s", BitRateUnit.MegabitPerSecond)] + [InlineData("Mbps", BitRateUnit.MegabitPerSecond)] + [InlineData("MB/s", BitRateUnit.MegabytePerSecond)] + [InlineData("Pibit/s", BitRateUnit.PebibitPerSecond)] + [InlineData("Pibps", BitRateUnit.PebibitPerSecond)] + [InlineData("PiB/s", BitRateUnit.PebibytePerSecond)] + [InlineData("Pbit/s", BitRateUnit.PetabitPerSecond)] + [InlineData("Pbps", BitRateUnit.PetabitPerSecond)] + [InlineData("PB/s", BitRateUnit.PetabytePerSecond)] + [InlineData("Tibit/s", BitRateUnit.TebibitPerSecond)] + [InlineData("Tibps", BitRateUnit.TebibitPerSecond)] + [InlineData("TiB/s", BitRateUnit.TebibytePerSecond)] + [InlineData("Tbit/s", BitRateUnit.TerabitPerSecond)] + [InlineData("Tbps", BitRateUnit.TerabitPerSecond)] + [InlineData("TB/s", BitRateUnit.TerabytePerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, BitRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + BitRateUnit parsedUnit = BitRate.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1031,7 +1081,54 @@ public void ParseUnit(string abbreviation, BitRateUnit expectedUnit) [InlineData("en-US", "Tbit/s", BitRateUnit.TerabitPerSecond)] [InlineData("en-US", "Tbps", BitRateUnit.TerabitPerSecond)] [InlineData("en-US", "TB/s", BitRateUnit.TerabytePerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, BitRateUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, BitRateUnit expectedUnit) + { + using var _ = new CultureScope(culture); + BitRateUnit parsedUnit = BitRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "bit/s", BitRateUnit.BitPerSecond)] + [InlineData("en-US", "bps", BitRateUnit.BitPerSecond)] + [InlineData("en-US", "B/s", BitRateUnit.BytePerSecond)] + [InlineData("en-US", "Ebit/s", BitRateUnit.ExabitPerSecond)] + [InlineData("en-US", "Ebps", BitRateUnit.ExabitPerSecond)] + [InlineData("en-US", "EB/s", BitRateUnit.ExabytePerSecond)] + [InlineData("en-US", "Eibit/s", BitRateUnit.ExbibitPerSecond)] + [InlineData("en-US", "Eibps", BitRateUnit.ExbibitPerSecond)] + [InlineData("en-US", "EiB/s", BitRateUnit.ExbibytePerSecond)] + [InlineData("en-US", "Gibit/s", BitRateUnit.GibibitPerSecond)] + [InlineData("en-US", "Gibps", BitRateUnit.GibibitPerSecond)] + [InlineData("en-US", "GiB/s", BitRateUnit.GibibytePerSecond)] + [InlineData("en-US", "Gbit/s", BitRateUnit.GigabitPerSecond)] + [InlineData("en-US", "Gbps", BitRateUnit.GigabitPerSecond)] + [InlineData("en-US", "GB/s", BitRateUnit.GigabytePerSecond)] + [InlineData("en-US", "Kibit/s", BitRateUnit.KibibitPerSecond)] + [InlineData("en-US", "Kibps", BitRateUnit.KibibitPerSecond)] + [InlineData("en-US", "KiB/s", BitRateUnit.KibibytePerSecond)] + [InlineData("en-US", "kbit/s", BitRateUnit.KilobitPerSecond)] + [InlineData("en-US", "kbps", BitRateUnit.KilobitPerSecond)] + [InlineData("en-US", "kB/s", BitRateUnit.KilobytePerSecond)] + [InlineData("en-US", "Mibit/s", BitRateUnit.MebibitPerSecond)] + [InlineData("en-US", "Mibps", BitRateUnit.MebibitPerSecond)] + [InlineData("en-US", "MiB/s", BitRateUnit.MebibytePerSecond)] + [InlineData("en-US", "Mbit/s", BitRateUnit.MegabitPerSecond)] + [InlineData("en-US", "Mbps", BitRateUnit.MegabitPerSecond)] + [InlineData("en-US", "MB/s", BitRateUnit.MegabytePerSecond)] + [InlineData("en-US", "Pibit/s", BitRateUnit.PebibitPerSecond)] + [InlineData("en-US", "Pibps", BitRateUnit.PebibitPerSecond)] + [InlineData("en-US", "PiB/s", BitRateUnit.PebibytePerSecond)] + [InlineData("en-US", "Pbit/s", BitRateUnit.PetabitPerSecond)] + [InlineData("en-US", "Pbps", BitRateUnit.PetabitPerSecond)] + [InlineData("en-US", "PB/s", BitRateUnit.PetabytePerSecond)] + [InlineData("en-US", "Tibit/s", BitRateUnit.TebibitPerSecond)] + [InlineData("en-US", "Tibps", BitRateUnit.TebibitPerSecond)] + [InlineData("en-US", "TiB/s", BitRateUnit.TebibytePerSecond)] + [InlineData("en-US", "Tbit/s", BitRateUnit.TerabitPerSecond)] + [InlineData("en-US", "Tbps", BitRateUnit.TerabitPerSecond)] + [InlineData("en-US", "TB/s", BitRateUnit.TerabytePerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, BitRateUnit expectedUnit) { BitRateUnit parsedUnit = BitRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1077,9 +1174,105 @@ public void ParseUnitWithCulture(string culture, string abbreviation, BitRateUni [InlineData("Tbit/s", BitRateUnit.TerabitPerSecond)] [InlineData("Tbps", BitRateUnit.TerabitPerSecond)] [InlineData("TB/s", BitRateUnit.TerabytePerSecond)] - public void TryParseUnit(string abbreviation, BitRateUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, BitRateUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(BitRate.TryParseUnit(abbreviation, out BitRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("bit/s", BitRateUnit.BitPerSecond)] + [InlineData("bps", BitRateUnit.BitPerSecond)] + [InlineData("B/s", BitRateUnit.BytePerSecond)] + [InlineData("Ebit/s", BitRateUnit.ExabitPerSecond)] + [InlineData("Ebps", BitRateUnit.ExabitPerSecond)] + [InlineData("EB/s", BitRateUnit.ExabytePerSecond)] + [InlineData("Eibit/s", BitRateUnit.ExbibitPerSecond)] + [InlineData("Eibps", BitRateUnit.ExbibitPerSecond)] + [InlineData("EiB/s", BitRateUnit.ExbibytePerSecond)] + [InlineData("Gibit/s", BitRateUnit.GibibitPerSecond)] + [InlineData("Gibps", BitRateUnit.GibibitPerSecond)] + [InlineData("GiB/s", BitRateUnit.GibibytePerSecond)] + [InlineData("Gbit/s", BitRateUnit.GigabitPerSecond)] + [InlineData("Gbps", BitRateUnit.GigabitPerSecond)] + [InlineData("GB/s", BitRateUnit.GigabytePerSecond)] + [InlineData("Kibit/s", BitRateUnit.KibibitPerSecond)] + [InlineData("Kibps", BitRateUnit.KibibitPerSecond)] + [InlineData("KiB/s", BitRateUnit.KibibytePerSecond)] + [InlineData("kbit/s", BitRateUnit.KilobitPerSecond)] + [InlineData("kbps", BitRateUnit.KilobitPerSecond)] + [InlineData("kB/s", BitRateUnit.KilobytePerSecond)] + [InlineData("Mibit/s", BitRateUnit.MebibitPerSecond)] + [InlineData("Mibps", BitRateUnit.MebibitPerSecond)] + [InlineData("MiB/s", BitRateUnit.MebibytePerSecond)] + [InlineData("Mbit/s", BitRateUnit.MegabitPerSecond)] + [InlineData("Mbps", BitRateUnit.MegabitPerSecond)] + [InlineData("MB/s", BitRateUnit.MegabytePerSecond)] + [InlineData("Pibit/s", BitRateUnit.PebibitPerSecond)] + [InlineData("Pibps", BitRateUnit.PebibitPerSecond)] + [InlineData("PiB/s", BitRateUnit.PebibytePerSecond)] + [InlineData("Pbit/s", BitRateUnit.PetabitPerSecond)] + [InlineData("Pbps", BitRateUnit.PetabitPerSecond)] + [InlineData("PB/s", BitRateUnit.PetabytePerSecond)] + [InlineData("Tibit/s", BitRateUnit.TebibitPerSecond)] + [InlineData("Tibps", BitRateUnit.TebibitPerSecond)] + [InlineData("TiB/s", BitRateUnit.TebibytePerSecond)] + [InlineData("Tbit/s", BitRateUnit.TerabitPerSecond)] + [InlineData("Tbps", BitRateUnit.TerabitPerSecond)] + [InlineData("TB/s", BitRateUnit.TerabytePerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, BitRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(BitRate.TryParseUnit(abbreviation, out BitRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "bit/s", BitRateUnit.BitPerSecond)] + [InlineData("en-US", "bps", BitRateUnit.BitPerSecond)] + [InlineData("en-US", "B/s", BitRateUnit.BytePerSecond)] + [InlineData("en-US", "Ebit/s", BitRateUnit.ExabitPerSecond)] + [InlineData("en-US", "Ebps", BitRateUnit.ExabitPerSecond)] + [InlineData("en-US", "EB/s", BitRateUnit.ExabytePerSecond)] + [InlineData("en-US", "Eibit/s", BitRateUnit.ExbibitPerSecond)] + [InlineData("en-US", "Eibps", BitRateUnit.ExbibitPerSecond)] + [InlineData("en-US", "EiB/s", BitRateUnit.ExbibytePerSecond)] + [InlineData("en-US", "Gibit/s", BitRateUnit.GibibitPerSecond)] + [InlineData("en-US", "Gibps", BitRateUnit.GibibitPerSecond)] + [InlineData("en-US", "GiB/s", BitRateUnit.GibibytePerSecond)] + [InlineData("en-US", "Gbit/s", BitRateUnit.GigabitPerSecond)] + [InlineData("en-US", "Gbps", BitRateUnit.GigabitPerSecond)] + [InlineData("en-US", "GB/s", BitRateUnit.GigabytePerSecond)] + [InlineData("en-US", "Kibit/s", BitRateUnit.KibibitPerSecond)] + [InlineData("en-US", "Kibps", BitRateUnit.KibibitPerSecond)] + [InlineData("en-US", "KiB/s", BitRateUnit.KibibytePerSecond)] + [InlineData("en-US", "kbit/s", BitRateUnit.KilobitPerSecond)] + [InlineData("en-US", "kbps", BitRateUnit.KilobitPerSecond)] + [InlineData("en-US", "kB/s", BitRateUnit.KilobytePerSecond)] + [InlineData("en-US", "Mibit/s", BitRateUnit.MebibitPerSecond)] + [InlineData("en-US", "Mibps", BitRateUnit.MebibitPerSecond)] + [InlineData("en-US", "MiB/s", BitRateUnit.MebibytePerSecond)] + [InlineData("en-US", "Mbit/s", BitRateUnit.MegabitPerSecond)] + [InlineData("en-US", "Mbps", BitRateUnit.MegabitPerSecond)] + [InlineData("en-US", "MB/s", BitRateUnit.MegabytePerSecond)] + [InlineData("en-US", "Pibit/s", BitRateUnit.PebibitPerSecond)] + [InlineData("en-US", "Pibps", BitRateUnit.PebibitPerSecond)] + [InlineData("en-US", "PiB/s", BitRateUnit.PebibytePerSecond)] + [InlineData("en-US", "Pbit/s", BitRateUnit.PetabitPerSecond)] + [InlineData("en-US", "Pbps", BitRateUnit.PetabitPerSecond)] + [InlineData("en-US", "PB/s", BitRateUnit.PetabytePerSecond)] + [InlineData("en-US", "Tibit/s", BitRateUnit.TebibitPerSecond)] + [InlineData("en-US", "Tibps", BitRateUnit.TebibitPerSecond)] + [InlineData("en-US", "TiB/s", BitRateUnit.TebibytePerSecond)] + [InlineData("en-US", "Tbit/s", BitRateUnit.TerabitPerSecond)] + [InlineData("en-US", "Tbps", BitRateUnit.TerabitPerSecond)] + [InlineData("en-US", "TB/s", BitRateUnit.TerabytePerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, BitRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(BitRate.TryParseUnit(abbreviation, out BitRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1124,7 +1317,7 @@ public void TryParseUnit(string abbreviation, BitRateUnit expectedUnit) [InlineData("en-US", "Tbit/s", BitRateUnit.TerabitPerSecond)] [InlineData("en-US", "Tbps", BitRateUnit.TerabitPerSecond)] [InlineData("en-US", "TB/s", BitRateUnit.TerabytePerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, BitRateUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, BitRateUnit expectedUnit) { Assert.True(BitRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out BitRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs index 421941a2fa..6728b21ed7 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/BrakeSpecificFuelConsumptionTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -250,10 +251,23 @@ public void TryParse() [InlineData("g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] [InlineData("kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] [InlineData("lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] - public void ParseUnit(string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - BrakeSpecificFuelConsumptionUnit parsedUnit = BrakeSpecificFuelConsumption.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + BrakeSpecificFuelConsumptionUnit parsedUnit = BrakeSpecificFuelConsumption.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] + [InlineData("kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] + [InlineData("lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + BrakeSpecificFuelConsumptionUnit parsedUnit = BrakeSpecificFuelConsumption.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -261,7 +275,18 @@ public void ParseUnit(string abbreviation, BrakeSpecificFuelConsumptionUnit expe [InlineData("en-US", "g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] [InlineData("en-US", "kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] [InlineData("en-US", "lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] - public void ParseUnitWithCulture(string culture, string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) + { + using var _ = new CultureScope(culture); + BrakeSpecificFuelConsumptionUnit parsedUnit = BrakeSpecificFuelConsumption.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] + [InlineData("en-US", "kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] + [InlineData("en-US", "lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] + public void ParseUnit_WithCulture(string culture, string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) { BrakeSpecificFuelConsumptionUnit parsedUnit = BrakeSpecificFuelConsumption.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -271,9 +296,33 @@ public void ParseUnitWithCulture(string culture, string abbreviation, BrakeSpeci [InlineData("g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] [InlineData("kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] [InlineData("lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] - public void TryParseUnit(string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(BrakeSpecificFuelConsumption.TryParseUnit(abbreviation, out BrakeSpecificFuelConsumptionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] + [InlineData("kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] + [InlineData("lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(BrakeSpecificFuelConsumption.TryParseUnit(abbreviation, out BrakeSpecificFuelConsumptionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] + [InlineData("en-US", "kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] + [InlineData("en-US", "lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(BrakeSpecificFuelConsumption.TryParseUnit(abbreviation, out BrakeSpecificFuelConsumptionUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -282,7 +331,7 @@ public void TryParseUnit(string abbreviation, BrakeSpecificFuelConsumptionUnit e [InlineData("en-US", "g/kWh", BrakeSpecificFuelConsumptionUnit.GramPerKiloWattHour)] [InlineData("en-US", "kg/J", BrakeSpecificFuelConsumptionUnit.KilogramPerJoule)] [InlineData("en-US", "lb/hph", BrakeSpecificFuelConsumptionUnit.PoundPerMechanicalHorsepowerHour)] - public void TryParseUnitWithCulture(string culture, string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, BrakeSpecificFuelConsumptionUnit expectedUnit) { Assert.True(BrakeSpecificFuelConsumption.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out BrakeSpecificFuelConsumptionUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs index 288238184e..da84dae4c5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CapacitanceTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -334,10 +335,27 @@ public void TryParse() [InlineData("mF", CapacitanceUnit.Millifarad)] [InlineData("nF", CapacitanceUnit.Nanofarad)] [InlineData("pF", CapacitanceUnit.Picofarad)] - public void ParseUnit(string abbreviation, CapacitanceUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, CapacitanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - CapacitanceUnit parsedUnit = Capacitance.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + CapacitanceUnit parsedUnit = Capacitance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("F", CapacitanceUnit.Farad)] + [InlineData("kF", CapacitanceUnit.Kilofarad)] + [InlineData("MF", CapacitanceUnit.Megafarad)] + [InlineData("µF", CapacitanceUnit.Microfarad)] + [InlineData("mF", CapacitanceUnit.Millifarad)] + [InlineData("nF", CapacitanceUnit.Nanofarad)] + [InlineData("pF", CapacitanceUnit.Picofarad)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, CapacitanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + CapacitanceUnit parsedUnit = Capacitance.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -349,7 +367,22 @@ public void ParseUnit(string abbreviation, CapacitanceUnit expectedUnit) [InlineData("en-US", "mF", CapacitanceUnit.Millifarad)] [InlineData("en-US", "nF", CapacitanceUnit.Nanofarad)] [InlineData("en-US", "pF", CapacitanceUnit.Picofarad)] - public void ParseUnitWithCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) + { + using var _ = new CultureScope(culture); + CapacitanceUnit parsedUnit = Capacitance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "F", CapacitanceUnit.Farad)] + [InlineData("en-US", "kF", CapacitanceUnit.Kilofarad)] + [InlineData("en-US", "MF", CapacitanceUnit.Megafarad)] + [InlineData("en-US", "µF", CapacitanceUnit.Microfarad)] + [InlineData("en-US", "mF", CapacitanceUnit.Millifarad)] + [InlineData("en-US", "nF", CapacitanceUnit.Nanofarad)] + [InlineData("en-US", "pF", CapacitanceUnit.Picofarad)] + public void ParseUnit_WithCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) { CapacitanceUnit parsedUnit = Capacitance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -363,9 +396,41 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Capacitanc [InlineData("mF", CapacitanceUnit.Millifarad)] [InlineData("nF", CapacitanceUnit.Nanofarad)] [InlineData("pF", CapacitanceUnit.Picofarad)] - public void TryParseUnit(string abbreviation, CapacitanceUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, CapacitanceUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Capacitance.TryParseUnit(abbreviation, out CapacitanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("F", CapacitanceUnit.Farad)] + [InlineData("kF", CapacitanceUnit.Kilofarad)] + [InlineData("MF", CapacitanceUnit.Megafarad)] + [InlineData("µF", CapacitanceUnit.Microfarad)] + [InlineData("mF", CapacitanceUnit.Millifarad)] + [InlineData("nF", CapacitanceUnit.Nanofarad)] + [InlineData("pF", CapacitanceUnit.Picofarad)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, CapacitanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Capacitance.TryParseUnit(abbreviation, out CapacitanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "F", CapacitanceUnit.Farad)] + [InlineData("en-US", "kF", CapacitanceUnit.Kilofarad)] + [InlineData("en-US", "MF", CapacitanceUnit.Megafarad)] + [InlineData("en-US", "µF", CapacitanceUnit.Microfarad)] + [InlineData("en-US", "mF", CapacitanceUnit.Millifarad)] + [InlineData("en-US", "nF", CapacitanceUnit.Nanofarad)] + [InlineData("en-US", "pF", CapacitanceUnit.Picofarad)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Capacitance.TryParseUnit(abbreviation, out CapacitanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -378,7 +443,7 @@ public void TryParseUnit(string abbreviation, CapacitanceUnit expectedUnit) [InlineData("en-US", "mF", CapacitanceUnit.Millifarad)] [InlineData("en-US", "nF", CapacitanceUnit.Nanofarad)] [InlineData("en-US", "pF", CapacitanceUnit.Picofarad)] - public void TryParseUnitWithCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, CapacitanceUnit expectedUnit) { Assert.True(Capacitance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out CapacitanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs index 925c4f0825..66af81c78c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CoefficientOfThermalExpansionTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -322,10 +323,26 @@ public void TryParse() [InlineData("ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] [InlineData("ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] [InlineData("ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] - public void ParseUnit(string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - CoefficientOfThermalExpansionUnit parsedUnit = CoefficientOfThermalExpansion.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + CoefficientOfThermalExpansionUnit parsedUnit = CoefficientOfThermalExpansion.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("°C⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeCelsius)] + [InlineData("°F⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit)] + [InlineData("K⁻¹", CoefficientOfThermalExpansionUnit.PerKelvin)] + [InlineData("ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] + [InlineData("ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] + [InlineData("ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + CoefficientOfThermalExpansionUnit parsedUnit = CoefficientOfThermalExpansion.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -336,7 +353,21 @@ public void ParseUnit(string abbreviation, CoefficientOfThermalExpansionUnit exp [InlineData("en-US", "ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] [InlineData("en-US", "ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] [InlineData("en-US", "ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] - public void ParseUnitWithCulture(string culture, string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) + { + using var _ = new CultureScope(culture); + CoefficientOfThermalExpansionUnit parsedUnit = CoefficientOfThermalExpansion.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "°C⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeCelsius)] + [InlineData("en-US", "°F⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit)] + [InlineData("en-US", "K⁻¹", CoefficientOfThermalExpansionUnit.PerKelvin)] + [InlineData("en-US", "ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] + [InlineData("en-US", "ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] + [InlineData("en-US", "ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] + public void ParseUnit_WithCulture(string culture, string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) { CoefficientOfThermalExpansionUnit parsedUnit = CoefficientOfThermalExpansion.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -349,9 +380,39 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Coefficien [InlineData("ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] [InlineData("ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] [InlineData("ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] - public void TryParseUnit(string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(CoefficientOfThermalExpansion.TryParseUnit(abbreviation, out CoefficientOfThermalExpansionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("°C⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeCelsius)] + [InlineData("°F⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit)] + [InlineData("K⁻¹", CoefficientOfThermalExpansionUnit.PerKelvin)] + [InlineData("ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] + [InlineData("ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] + [InlineData("ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(CoefficientOfThermalExpansion.TryParseUnit(abbreviation, out CoefficientOfThermalExpansionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "°C⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeCelsius)] + [InlineData("en-US", "°F⁻¹", CoefficientOfThermalExpansionUnit.PerDegreeFahrenheit)] + [InlineData("en-US", "K⁻¹", CoefficientOfThermalExpansionUnit.PerKelvin)] + [InlineData("en-US", "ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] + [InlineData("en-US", "ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] + [InlineData("en-US", "ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(CoefficientOfThermalExpansion.TryParseUnit(abbreviation, out CoefficientOfThermalExpansionUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -363,7 +424,7 @@ public void TryParseUnit(string abbreviation, CoefficientOfThermalExpansionUnit [InlineData("en-US", "ppm/°C", CoefficientOfThermalExpansionUnit.PpmPerDegreeCelsius)] [InlineData("en-US", "ppm/°F", CoefficientOfThermalExpansionUnit.PpmPerDegreeFahrenheit)] [InlineData("en-US", "ppm/K", CoefficientOfThermalExpansionUnit.PpmPerKelvin)] - public void TryParseUnitWithCulture(string culture, string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, CoefficientOfThermalExpansionUnit expectedUnit) { Assert.True(CoefficientOfThermalExpansion.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out CoefficientOfThermalExpansionUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs index 10ed669227..4c6f55a3bf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/CompressibilityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -444,10 +445,34 @@ public void TryParse() [InlineData("1/Pa", CompressibilityUnit.InversePascal)] [InlineData("psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] [InlineData("1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] - public void ParseUnit(string abbreviation, CompressibilityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, CompressibilityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - CompressibilityUnit parsedUnit = Compressibility.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + CompressibilityUnit parsedUnit = Compressibility.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("atm⁻¹", CompressibilityUnit.InverseAtmosphere)] + [InlineData("1/atm", CompressibilityUnit.InverseAtmosphere)] + [InlineData("bar⁻¹", CompressibilityUnit.InverseBar)] + [InlineData("1/bar", CompressibilityUnit.InverseBar)] + [InlineData("kPa⁻¹", CompressibilityUnit.InverseKilopascal)] + [InlineData("1/kPa", CompressibilityUnit.InverseKilopascal)] + [InlineData("MPa⁻¹", CompressibilityUnit.InverseMegapascal)] + [InlineData("1/MPa", CompressibilityUnit.InverseMegapascal)] + [InlineData("mbar⁻¹", CompressibilityUnit.InverseMillibar)] + [InlineData("1/mbar", CompressibilityUnit.InverseMillibar)] + [InlineData("Pa⁻¹", CompressibilityUnit.InversePascal)] + [InlineData("1/Pa", CompressibilityUnit.InversePascal)] + [InlineData("psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] + [InlineData("1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, CompressibilityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + CompressibilityUnit parsedUnit = Compressibility.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -466,7 +491,29 @@ public void ParseUnit(string abbreviation, CompressibilityUnit expectedUnit) [InlineData("en-US", "1/Pa", CompressibilityUnit.InversePascal)] [InlineData("en-US", "psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] [InlineData("en-US", "1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] - public void ParseUnitWithCulture(string culture, string abbreviation, CompressibilityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, CompressibilityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + CompressibilityUnit parsedUnit = Compressibility.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "atm⁻¹", CompressibilityUnit.InverseAtmosphere)] + [InlineData("en-US", "1/atm", CompressibilityUnit.InverseAtmosphere)] + [InlineData("en-US", "bar⁻¹", CompressibilityUnit.InverseBar)] + [InlineData("en-US", "1/bar", CompressibilityUnit.InverseBar)] + [InlineData("en-US", "kPa⁻¹", CompressibilityUnit.InverseKilopascal)] + [InlineData("en-US", "1/kPa", CompressibilityUnit.InverseKilopascal)] + [InlineData("en-US", "MPa⁻¹", CompressibilityUnit.InverseMegapascal)] + [InlineData("en-US", "1/MPa", CompressibilityUnit.InverseMegapascal)] + [InlineData("en-US", "mbar⁻¹", CompressibilityUnit.InverseMillibar)] + [InlineData("en-US", "1/mbar", CompressibilityUnit.InverseMillibar)] + [InlineData("en-US", "Pa⁻¹", CompressibilityUnit.InversePascal)] + [InlineData("en-US", "1/Pa", CompressibilityUnit.InversePascal)] + [InlineData("en-US", "psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] + [InlineData("en-US", "1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] + public void ParseUnit_WithCulture(string culture, string abbreviation, CompressibilityUnit expectedUnit) { CompressibilityUnit parsedUnit = Compressibility.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -487,9 +534,55 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Compressib [InlineData("1/Pa", CompressibilityUnit.InversePascal)] [InlineData("psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] [InlineData("1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] - public void TryParseUnit(string abbreviation, CompressibilityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, CompressibilityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Compressibility.TryParseUnit(abbreviation, out CompressibilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("atm⁻¹", CompressibilityUnit.InverseAtmosphere)] + [InlineData("1/atm", CompressibilityUnit.InverseAtmosphere)] + [InlineData("bar⁻¹", CompressibilityUnit.InverseBar)] + [InlineData("1/bar", CompressibilityUnit.InverseBar)] + [InlineData("kPa⁻¹", CompressibilityUnit.InverseKilopascal)] + [InlineData("1/kPa", CompressibilityUnit.InverseKilopascal)] + [InlineData("MPa⁻¹", CompressibilityUnit.InverseMegapascal)] + [InlineData("1/MPa", CompressibilityUnit.InverseMegapascal)] + [InlineData("mbar⁻¹", CompressibilityUnit.InverseMillibar)] + [InlineData("1/mbar", CompressibilityUnit.InverseMillibar)] + [InlineData("Pa⁻¹", CompressibilityUnit.InversePascal)] + [InlineData("1/Pa", CompressibilityUnit.InversePascal)] + [InlineData("psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] + [InlineData("1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, CompressibilityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Compressibility.TryParseUnit(abbreviation, out CompressibilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "atm⁻¹", CompressibilityUnit.InverseAtmosphere)] + [InlineData("en-US", "1/atm", CompressibilityUnit.InverseAtmosphere)] + [InlineData("en-US", "bar⁻¹", CompressibilityUnit.InverseBar)] + [InlineData("en-US", "1/bar", CompressibilityUnit.InverseBar)] + [InlineData("en-US", "kPa⁻¹", CompressibilityUnit.InverseKilopascal)] + [InlineData("en-US", "1/kPa", CompressibilityUnit.InverseKilopascal)] + [InlineData("en-US", "MPa⁻¹", CompressibilityUnit.InverseMegapascal)] + [InlineData("en-US", "1/MPa", CompressibilityUnit.InverseMegapascal)] + [InlineData("en-US", "mbar⁻¹", CompressibilityUnit.InverseMillibar)] + [InlineData("en-US", "1/mbar", CompressibilityUnit.InverseMillibar)] + [InlineData("en-US", "Pa⁻¹", CompressibilityUnit.InversePascal)] + [InlineData("en-US", "1/Pa", CompressibilityUnit.InversePascal)] + [InlineData("en-US", "psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] + [InlineData("en-US", "1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, CompressibilityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Compressibility.TryParseUnit(abbreviation, out CompressibilityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -509,7 +602,7 @@ public void TryParseUnit(string abbreviation, CompressibilityUnit expectedUnit) [InlineData("en-US", "1/Pa", CompressibilityUnit.InversePascal)] [InlineData("en-US", "psi⁻¹", CompressibilityUnit.InversePoundForcePerSquareInch)] [InlineData("en-US", "1/psi", CompressibilityUnit.InversePoundForcePerSquareInch)] - public void TryParseUnitWithCulture(string culture, string abbreviation, CompressibilityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, CompressibilityUnit expectedUnit) { Assert.True(Compressibility.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out CompressibilityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs index 1028f7da0a..64e48ef54d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DensityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1574,10 +1575,76 @@ public void TryParse() [InlineData("t/in³", DensityUnit.TonnePerCubicInch)] [InlineData("t/m³", DensityUnit.TonnePerCubicMeter)] [InlineData("t/mm³", DensityUnit.TonnePerCubicMillimeter)] - public void ParseUnit(string abbreviation, DensityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, DensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - DensityUnit parsedUnit = Density.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + DensityUnit parsedUnit = Density.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg/dl", DensityUnit.CentigramPerDeciliter)] + [InlineData("cg/l", DensityUnit.CentigramPerLiter)] + [InlineData("cg/ml", DensityUnit.CentigramPerMilliliter)] + [InlineData("dg/dl", DensityUnit.DecigramPerDeciliter)] + [InlineData("dg/l", DensityUnit.DecigramPerLiter)] + [InlineData("dg/ml", DensityUnit.DecigramPerMilliliter)] + [InlineData("fg/dl", DensityUnit.FemtogramPerDeciliter)] + [InlineData("fg/l", DensityUnit.FemtogramPerLiter)] + [InlineData("fg/ml", DensityUnit.FemtogramPerMilliliter)] + [InlineData("g/cm³", DensityUnit.GramPerCubicCentimeter)] + [InlineData("g/ft³", DensityUnit.GramPerCubicFoot)] + [InlineData("g/in³", DensityUnit.GramPerCubicInch)] + [InlineData("g/m³", DensityUnit.GramPerCubicMeter)] + [InlineData("g/mm³", DensityUnit.GramPerCubicMillimeter)] + [InlineData("g/dl", DensityUnit.GramPerDeciliter)] + [InlineData("g/l", DensityUnit.GramPerLiter)] + [InlineData("g/ml", DensityUnit.GramPerMilliliter)] + [InlineData("kg/cm³", DensityUnit.KilogramPerCubicCentimeter)] + [InlineData("kg/m³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("kg/mm³", DensityUnit.KilogramPerCubicMillimeter)] + [InlineData("kg/l", DensityUnit.KilogramPerLiter)] + [InlineData("kip/ft³", DensityUnit.KilopoundPerCubicFoot)] + [InlineData("kip/in³", DensityUnit.KilopoundPerCubicInch)] + [InlineData("kip/yd³", DensityUnit.KilopoundPerCubicYard)] + [InlineData("µg/m³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("µg/dl", DensityUnit.MicrogramPerDeciliter)] + [InlineData("µg/l", DensityUnit.MicrogramPerLiter)] + [InlineData("µg/ml", DensityUnit.MicrogramPerMilliliter)] + [InlineData("mg/m³", DensityUnit.MilligramPerCubicMeter)] + [InlineData("mg/dl", DensityUnit.MilligramPerDeciliter)] + [InlineData("mg/l", DensityUnit.MilligramPerLiter)] + [InlineData("mg/ml", DensityUnit.MilligramPerMilliliter)] + [InlineData("ng/dl", DensityUnit.NanogramPerDeciliter)] + [InlineData("ng/l", DensityUnit.NanogramPerLiter)] + [InlineData("ng/ml", DensityUnit.NanogramPerMilliliter)] + [InlineData("pg/dl", DensityUnit.PicogramPerDeciliter)] + [InlineData("pg/l", DensityUnit.PicogramPerLiter)] + [InlineData("pg/ml", DensityUnit.PicogramPerMilliliter)] + [InlineData("lb/cm³", DensityUnit.PoundPerCubicCentimeter)] + [InlineData("lb/ft³", DensityUnit.PoundPerCubicFoot)] + [InlineData("lb/in³", DensityUnit.PoundPerCubicInch)] + [InlineData("lb/m³", DensityUnit.PoundPerCubicMeter)] + [InlineData("lb/mm³", DensityUnit.PoundPerCubicMillimeter)] + [InlineData("lb/yd³", DensityUnit.PoundPerCubicYard)] + [InlineData("ppg (imp.)", DensityUnit.PoundPerImperialGallon)] + [InlineData("ppg (U.S.)", DensityUnit.PoundPerUSGallon)] + [InlineData("slug/cm³", DensityUnit.SlugPerCubicCentimeter)] + [InlineData("slug/ft³", DensityUnit.SlugPerCubicFoot)] + [InlineData("slug/in³", DensityUnit.SlugPerCubicInch)] + [InlineData("slug/m³", DensityUnit.SlugPerCubicMeter)] + [InlineData("slug/mm³", DensityUnit.SlugPerCubicMillimeter)] + [InlineData("t/cm³", DensityUnit.TonnePerCubicCentimeter)] + [InlineData("t/ft³", DensityUnit.TonnePerCubicFoot)] + [InlineData("t/in³", DensityUnit.TonnePerCubicInch)] + [InlineData("t/m³", DensityUnit.TonnePerCubicMeter)] + [InlineData("t/mm³", DensityUnit.TonnePerCubicMillimeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, DensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + DensityUnit parsedUnit = Density.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1642,7 +1709,75 @@ public void ParseUnit(string abbreviation, DensityUnit expectedUnit) [InlineData("ru-RU", "кг/м³", DensityUnit.KilogramPerCubicMeter)] [InlineData("ru-RU", "мкг/м³", DensityUnit.MicrogramPerCubicMeter)] [InlineData("ru-RU", "мг/м³", DensityUnit.MilligramPerCubicMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, DensityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, DensityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + DensityUnit parsedUnit = Density.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg/dl", DensityUnit.CentigramPerDeciliter)] + [InlineData("en-US", "cg/l", DensityUnit.CentigramPerLiter)] + [InlineData("en-US", "cg/ml", DensityUnit.CentigramPerMilliliter)] + [InlineData("en-US", "dg/dl", DensityUnit.DecigramPerDeciliter)] + [InlineData("en-US", "dg/l", DensityUnit.DecigramPerLiter)] + [InlineData("en-US", "dg/ml", DensityUnit.DecigramPerMilliliter)] + [InlineData("en-US", "fg/dl", DensityUnit.FemtogramPerDeciliter)] + [InlineData("en-US", "fg/l", DensityUnit.FemtogramPerLiter)] + [InlineData("en-US", "fg/ml", DensityUnit.FemtogramPerMilliliter)] + [InlineData("en-US", "g/cm³", DensityUnit.GramPerCubicCentimeter)] + [InlineData("en-US", "g/ft³", DensityUnit.GramPerCubicFoot)] + [InlineData("en-US", "g/in³", DensityUnit.GramPerCubicInch)] + [InlineData("en-US", "g/m³", DensityUnit.GramPerCubicMeter)] + [InlineData("en-US", "g/mm³", DensityUnit.GramPerCubicMillimeter)] + [InlineData("en-US", "g/dl", DensityUnit.GramPerDeciliter)] + [InlineData("en-US", "g/l", DensityUnit.GramPerLiter)] + [InlineData("en-US", "g/ml", DensityUnit.GramPerMilliliter)] + [InlineData("en-US", "kg/cm³", DensityUnit.KilogramPerCubicCentimeter)] + [InlineData("en-US", "kg/m³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("en-US", "kg/mm³", DensityUnit.KilogramPerCubicMillimeter)] + [InlineData("en-US", "kg/l", DensityUnit.KilogramPerLiter)] + [InlineData("en-US", "kip/ft³", DensityUnit.KilopoundPerCubicFoot)] + [InlineData("en-US", "kip/in³", DensityUnit.KilopoundPerCubicInch)] + [InlineData("en-US", "kip/yd³", DensityUnit.KilopoundPerCubicYard)] + [InlineData("en-US", "µg/m³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("en-US", "µg/dl", DensityUnit.MicrogramPerDeciliter)] + [InlineData("en-US", "µg/l", DensityUnit.MicrogramPerLiter)] + [InlineData("en-US", "µg/ml", DensityUnit.MicrogramPerMilliliter)] + [InlineData("en-US", "mg/m³", DensityUnit.MilligramPerCubicMeter)] + [InlineData("en-US", "mg/dl", DensityUnit.MilligramPerDeciliter)] + [InlineData("en-US", "mg/l", DensityUnit.MilligramPerLiter)] + [InlineData("en-US", "mg/ml", DensityUnit.MilligramPerMilliliter)] + [InlineData("en-US", "ng/dl", DensityUnit.NanogramPerDeciliter)] + [InlineData("en-US", "ng/l", DensityUnit.NanogramPerLiter)] + [InlineData("en-US", "ng/ml", DensityUnit.NanogramPerMilliliter)] + [InlineData("en-US", "pg/dl", DensityUnit.PicogramPerDeciliter)] + [InlineData("en-US", "pg/l", DensityUnit.PicogramPerLiter)] + [InlineData("en-US", "pg/ml", DensityUnit.PicogramPerMilliliter)] + [InlineData("en-US", "lb/cm³", DensityUnit.PoundPerCubicCentimeter)] + [InlineData("en-US", "lb/ft³", DensityUnit.PoundPerCubicFoot)] + [InlineData("en-US", "lb/in³", DensityUnit.PoundPerCubicInch)] + [InlineData("en-US", "lb/m³", DensityUnit.PoundPerCubicMeter)] + [InlineData("en-US", "lb/mm³", DensityUnit.PoundPerCubicMillimeter)] + [InlineData("en-US", "lb/yd³", DensityUnit.PoundPerCubicYard)] + [InlineData("en-US", "ppg (imp.)", DensityUnit.PoundPerImperialGallon)] + [InlineData("en-US", "ppg (U.S.)", DensityUnit.PoundPerUSGallon)] + [InlineData("en-US", "slug/cm³", DensityUnit.SlugPerCubicCentimeter)] + [InlineData("en-US", "slug/ft³", DensityUnit.SlugPerCubicFoot)] + [InlineData("en-US", "slug/in³", DensityUnit.SlugPerCubicInch)] + [InlineData("en-US", "slug/m³", DensityUnit.SlugPerCubicMeter)] + [InlineData("en-US", "slug/mm³", DensityUnit.SlugPerCubicMillimeter)] + [InlineData("en-US", "t/cm³", DensityUnit.TonnePerCubicCentimeter)] + [InlineData("en-US", "t/ft³", DensityUnit.TonnePerCubicFoot)] + [InlineData("en-US", "t/in³", DensityUnit.TonnePerCubicInch)] + [InlineData("en-US", "t/m³", DensityUnit.TonnePerCubicMeter)] + [InlineData("en-US", "t/mm³", DensityUnit.TonnePerCubicMillimeter)] + [InlineData("ru-RU", "г/м³", DensityUnit.GramPerCubicMeter)] + [InlineData("ru-RU", "кг/м³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("ru-RU", "мкг/м³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("ru-RU", "мг/м³", DensityUnit.MilligramPerCubicMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, DensityUnit expectedUnit) { DensityUnit parsedUnit = Density.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1705,9 +1840,143 @@ public void ParseUnitWithCulture(string culture, string abbreviation, DensityUni [InlineData("t/in³", DensityUnit.TonnePerCubicInch)] [InlineData("t/m³", DensityUnit.TonnePerCubicMeter)] [InlineData("t/mm³", DensityUnit.TonnePerCubicMillimeter)] - public void TryParseUnit(string abbreviation, DensityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, DensityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Density.TryParseUnit(abbreviation, out DensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg/dl", DensityUnit.CentigramPerDeciliter)] + [InlineData("cg/l", DensityUnit.CentigramPerLiter)] + [InlineData("cg/ml", DensityUnit.CentigramPerMilliliter)] + [InlineData("dg/dl", DensityUnit.DecigramPerDeciliter)] + [InlineData("dg/l", DensityUnit.DecigramPerLiter)] + [InlineData("dg/ml", DensityUnit.DecigramPerMilliliter)] + [InlineData("fg/dl", DensityUnit.FemtogramPerDeciliter)] + [InlineData("fg/l", DensityUnit.FemtogramPerLiter)] + [InlineData("fg/ml", DensityUnit.FemtogramPerMilliliter)] + [InlineData("g/cm³", DensityUnit.GramPerCubicCentimeter)] + [InlineData("g/ft³", DensityUnit.GramPerCubicFoot)] + [InlineData("g/in³", DensityUnit.GramPerCubicInch)] + [InlineData("g/m³", DensityUnit.GramPerCubicMeter)] + [InlineData("g/mm³", DensityUnit.GramPerCubicMillimeter)] + [InlineData("g/dl", DensityUnit.GramPerDeciliter)] + [InlineData("g/l", DensityUnit.GramPerLiter)] + [InlineData("g/ml", DensityUnit.GramPerMilliliter)] + [InlineData("kg/cm³", DensityUnit.KilogramPerCubicCentimeter)] + [InlineData("kg/m³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("kg/mm³", DensityUnit.KilogramPerCubicMillimeter)] + [InlineData("kg/l", DensityUnit.KilogramPerLiter)] + [InlineData("kip/ft³", DensityUnit.KilopoundPerCubicFoot)] + [InlineData("kip/in³", DensityUnit.KilopoundPerCubicInch)] + [InlineData("kip/yd³", DensityUnit.KilopoundPerCubicYard)] + [InlineData("µg/m³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("µg/dl", DensityUnit.MicrogramPerDeciliter)] + [InlineData("µg/l", DensityUnit.MicrogramPerLiter)] + [InlineData("µg/ml", DensityUnit.MicrogramPerMilliliter)] + [InlineData("mg/m³", DensityUnit.MilligramPerCubicMeter)] + [InlineData("mg/dl", DensityUnit.MilligramPerDeciliter)] + [InlineData("mg/l", DensityUnit.MilligramPerLiter)] + [InlineData("mg/ml", DensityUnit.MilligramPerMilliliter)] + [InlineData("ng/dl", DensityUnit.NanogramPerDeciliter)] + [InlineData("ng/l", DensityUnit.NanogramPerLiter)] + [InlineData("ng/ml", DensityUnit.NanogramPerMilliliter)] + [InlineData("pg/dl", DensityUnit.PicogramPerDeciliter)] + [InlineData("pg/l", DensityUnit.PicogramPerLiter)] + [InlineData("pg/ml", DensityUnit.PicogramPerMilliliter)] + [InlineData("lb/cm³", DensityUnit.PoundPerCubicCentimeter)] + [InlineData("lb/ft³", DensityUnit.PoundPerCubicFoot)] + [InlineData("lb/in³", DensityUnit.PoundPerCubicInch)] + [InlineData("lb/m³", DensityUnit.PoundPerCubicMeter)] + [InlineData("lb/mm³", DensityUnit.PoundPerCubicMillimeter)] + [InlineData("lb/yd³", DensityUnit.PoundPerCubicYard)] + [InlineData("ppg (imp.)", DensityUnit.PoundPerImperialGallon)] + [InlineData("ppg (U.S.)", DensityUnit.PoundPerUSGallon)] + [InlineData("slug/cm³", DensityUnit.SlugPerCubicCentimeter)] + [InlineData("slug/ft³", DensityUnit.SlugPerCubicFoot)] + [InlineData("slug/in³", DensityUnit.SlugPerCubicInch)] + [InlineData("slug/m³", DensityUnit.SlugPerCubicMeter)] + [InlineData("slug/mm³", DensityUnit.SlugPerCubicMillimeter)] + [InlineData("t/cm³", DensityUnit.TonnePerCubicCentimeter)] + [InlineData("t/ft³", DensityUnit.TonnePerCubicFoot)] + [InlineData("t/in³", DensityUnit.TonnePerCubicInch)] + [InlineData("t/m³", DensityUnit.TonnePerCubicMeter)] + [InlineData("t/mm³", DensityUnit.TonnePerCubicMillimeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, DensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Density.TryParseUnit(abbreviation, out DensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg/dl", DensityUnit.CentigramPerDeciliter)] + [InlineData("en-US", "cg/l", DensityUnit.CentigramPerLiter)] + [InlineData("en-US", "cg/ml", DensityUnit.CentigramPerMilliliter)] + [InlineData("en-US", "dg/dl", DensityUnit.DecigramPerDeciliter)] + [InlineData("en-US", "dg/l", DensityUnit.DecigramPerLiter)] + [InlineData("en-US", "dg/ml", DensityUnit.DecigramPerMilliliter)] + [InlineData("en-US", "fg/dl", DensityUnit.FemtogramPerDeciliter)] + [InlineData("en-US", "fg/l", DensityUnit.FemtogramPerLiter)] + [InlineData("en-US", "fg/ml", DensityUnit.FemtogramPerMilliliter)] + [InlineData("en-US", "g/cm³", DensityUnit.GramPerCubicCentimeter)] + [InlineData("en-US", "g/ft³", DensityUnit.GramPerCubicFoot)] + [InlineData("en-US", "g/in³", DensityUnit.GramPerCubicInch)] + [InlineData("en-US", "g/m³", DensityUnit.GramPerCubicMeter)] + [InlineData("en-US", "g/mm³", DensityUnit.GramPerCubicMillimeter)] + [InlineData("en-US", "g/dl", DensityUnit.GramPerDeciliter)] + [InlineData("en-US", "g/l", DensityUnit.GramPerLiter)] + [InlineData("en-US", "g/ml", DensityUnit.GramPerMilliliter)] + [InlineData("en-US", "kg/cm³", DensityUnit.KilogramPerCubicCentimeter)] + [InlineData("en-US", "kg/m³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("en-US", "kg/mm³", DensityUnit.KilogramPerCubicMillimeter)] + [InlineData("en-US", "kg/l", DensityUnit.KilogramPerLiter)] + [InlineData("en-US", "kip/ft³", DensityUnit.KilopoundPerCubicFoot)] + [InlineData("en-US", "kip/in³", DensityUnit.KilopoundPerCubicInch)] + [InlineData("en-US", "kip/yd³", DensityUnit.KilopoundPerCubicYard)] + [InlineData("en-US", "µg/m³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("en-US", "µg/dl", DensityUnit.MicrogramPerDeciliter)] + [InlineData("en-US", "µg/l", DensityUnit.MicrogramPerLiter)] + [InlineData("en-US", "µg/ml", DensityUnit.MicrogramPerMilliliter)] + [InlineData("en-US", "mg/m³", DensityUnit.MilligramPerCubicMeter)] + [InlineData("en-US", "mg/dl", DensityUnit.MilligramPerDeciliter)] + [InlineData("en-US", "mg/l", DensityUnit.MilligramPerLiter)] + [InlineData("en-US", "mg/ml", DensityUnit.MilligramPerMilliliter)] + [InlineData("en-US", "ng/dl", DensityUnit.NanogramPerDeciliter)] + [InlineData("en-US", "ng/l", DensityUnit.NanogramPerLiter)] + [InlineData("en-US", "ng/ml", DensityUnit.NanogramPerMilliliter)] + [InlineData("en-US", "pg/dl", DensityUnit.PicogramPerDeciliter)] + [InlineData("en-US", "pg/l", DensityUnit.PicogramPerLiter)] + [InlineData("en-US", "pg/ml", DensityUnit.PicogramPerMilliliter)] + [InlineData("en-US", "lb/cm³", DensityUnit.PoundPerCubicCentimeter)] + [InlineData("en-US", "lb/ft³", DensityUnit.PoundPerCubicFoot)] + [InlineData("en-US", "lb/in³", DensityUnit.PoundPerCubicInch)] + [InlineData("en-US", "lb/m³", DensityUnit.PoundPerCubicMeter)] + [InlineData("en-US", "lb/mm³", DensityUnit.PoundPerCubicMillimeter)] + [InlineData("en-US", "lb/yd³", DensityUnit.PoundPerCubicYard)] + [InlineData("en-US", "ppg (imp.)", DensityUnit.PoundPerImperialGallon)] + [InlineData("en-US", "ppg (U.S.)", DensityUnit.PoundPerUSGallon)] + [InlineData("en-US", "slug/cm³", DensityUnit.SlugPerCubicCentimeter)] + [InlineData("en-US", "slug/ft³", DensityUnit.SlugPerCubicFoot)] + [InlineData("en-US", "slug/in³", DensityUnit.SlugPerCubicInch)] + [InlineData("en-US", "slug/m³", DensityUnit.SlugPerCubicMeter)] + [InlineData("en-US", "slug/mm³", DensityUnit.SlugPerCubicMillimeter)] + [InlineData("en-US", "t/cm³", DensityUnit.TonnePerCubicCentimeter)] + [InlineData("en-US", "t/ft³", DensityUnit.TonnePerCubicFoot)] + [InlineData("en-US", "t/in³", DensityUnit.TonnePerCubicInch)] + [InlineData("en-US", "t/m³", DensityUnit.TonnePerCubicMeter)] + [InlineData("en-US", "t/mm³", DensityUnit.TonnePerCubicMillimeter)] + [InlineData("ru-RU", "г/м³", DensityUnit.GramPerCubicMeter)] + [InlineData("ru-RU", "кг/м³", DensityUnit.KilogramPerCubicMeter)] + [InlineData("ru-RU", "мкг/м³", DensityUnit.MicrogramPerCubicMeter)] + [InlineData("ru-RU", "мг/м³", DensityUnit.MilligramPerCubicMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, DensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Density.TryParseUnit(abbreviation, out DensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1773,7 +2042,7 @@ public void TryParseUnit(string abbreviation, DensityUnit expectedUnit) [InlineData("ru-RU", "кг/м³", DensityUnit.KilogramPerCubicMeter)] [InlineData("ru-RU", "мкг/м³", DensityUnit.MicrogramPerCubicMeter)] [InlineData("ru-RU", "мг/м³", DensityUnit.MilligramPerCubicMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, DensityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, DensityUnit expectedUnit) { Assert.True(Density.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out DensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs index 716698ce5b..287ad048a5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DurationTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1136,10 +1137,65 @@ public void TryParse() [InlineData("yr", DurationUnit.Year365)] [InlineData("year", DurationUnit.Year365)] [InlineData("years", DurationUnit.Year365)] - public void ParseUnit(string abbreviation, DurationUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, DurationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - DurationUnit parsedUnit = Duration.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + DurationUnit parsedUnit = Duration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("d", DurationUnit.Day)] + [InlineData("day", DurationUnit.Day)] + [InlineData("days", DurationUnit.Day)] + [InlineData("h", DurationUnit.Hour)] + [InlineData("hr", DurationUnit.Hour)] + [InlineData("hrs", DurationUnit.Hour)] + [InlineData("hour", DurationUnit.Hour)] + [InlineData("hours", DurationUnit.Hour)] + [InlineData("jyr", DurationUnit.JulianYear)] + [InlineData("jyear", DurationUnit.JulianYear)] + [InlineData("jyears", DurationUnit.JulianYear)] + [InlineData("µs", DurationUnit.Microsecond)] + [InlineData("µsec", DurationUnit.Microsecond)] + [InlineData("µsecs", DurationUnit.Microsecond)] + [InlineData("µsecond", DurationUnit.Microsecond)] + [InlineData("µseconds", DurationUnit.Microsecond)] + [InlineData("ms", DurationUnit.Millisecond)] + [InlineData("msec", DurationUnit.Millisecond)] + [InlineData("msecs", DurationUnit.Millisecond)] + [InlineData("msecond", DurationUnit.Millisecond)] + [InlineData("mseconds", DurationUnit.Millisecond)] + [InlineData("m", DurationUnit.Minute)] + [InlineData("min", DurationUnit.Minute)] + [InlineData("minute", DurationUnit.Minute)] + [InlineData("minutes", DurationUnit.Minute)] + [InlineData("mo", DurationUnit.Month30)] + [InlineData("month", DurationUnit.Month30)] + [InlineData("months", DurationUnit.Month30)] + [InlineData("ns", DurationUnit.Nanosecond)] + [InlineData("nsec", DurationUnit.Nanosecond)] + [InlineData("nsecs", DurationUnit.Nanosecond)] + [InlineData("nsecond", DurationUnit.Nanosecond)] + [InlineData("nseconds", DurationUnit.Nanosecond)] + [InlineData("s", DurationUnit.Second)] + [InlineData("sec", DurationUnit.Second)] + [InlineData("secs", DurationUnit.Second)] + [InlineData("second", DurationUnit.Second)] + [InlineData("seconds", DurationUnit.Second)] + [InlineData("sol", DurationUnit.Sol)] + [InlineData("wk", DurationUnit.Week)] + [InlineData("week", DurationUnit.Week)] + [InlineData("weeks", DurationUnit.Week)] + [InlineData("yr", DurationUnit.Year365)] + [InlineData("year", DurationUnit.Year365)] + [InlineData("years", DurationUnit.Year365)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, DurationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + DurationUnit parsedUnit = Duration.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1205,7 +1261,76 @@ public void ParseUnit(string abbreviation, DurationUnit expectedUnit) [InlineData("ru-RU", "с", DurationUnit.Second)] [InlineData("ru-RU", "нед", DurationUnit.Week)] [InlineData("ru-RU", "год", DurationUnit.Year365)] - public void ParseUnitWithCulture(string culture, string abbreviation, DurationUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, DurationUnit expectedUnit) + { + using var _ = new CultureScope(culture); + DurationUnit parsedUnit = Duration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "d", DurationUnit.Day)] + [InlineData("en-US", "day", DurationUnit.Day)] + [InlineData("en-US", "days", DurationUnit.Day)] + [InlineData("en-US", "h", DurationUnit.Hour)] + [InlineData("en-US", "hr", DurationUnit.Hour)] + [InlineData("en-US", "hrs", DurationUnit.Hour)] + [InlineData("en-US", "hour", DurationUnit.Hour)] + [InlineData("en-US", "hours", DurationUnit.Hour)] + [InlineData("en-US", "jyr", DurationUnit.JulianYear)] + [InlineData("en-US", "jyear", DurationUnit.JulianYear)] + [InlineData("en-US", "jyears", DurationUnit.JulianYear)] + [InlineData("en-US", "µs", DurationUnit.Microsecond)] + [InlineData("en-US", "µsec", DurationUnit.Microsecond)] + [InlineData("en-US", "µsecs", DurationUnit.Microsecond)] + [InlineData("en-US", "µsecond", DurationUnit.Microsecond)] + [InlineData("en-US", "µseconds", DurationUnit.Microsecond)] + [InlineData("en-US", "ms", DurationUnit.Millisecond)] + [InlineData("en-US", "msec", DurationUnit.Millisecond)] + [InlineData("en-US", "msecs", DurationUnit.Millisecond)] + [InlineData("en-US", "msecond", DurationUnit.Millisecond)] + [InlineData("en-US", "mseconds", DurationUnit.Millisecond)] + [InlineData("en-US", "m", DurationUnit.Minute)] + [InlineData("en-US", "min", DurationUnit.Minute)] + [InlineData("en-US", "minute", DurationUnit.Minute)] + [InlineData("en-US", "minutes", DurationUnit.Minute)] + [InlineData("en-US", "mo", DurationUnit.Month30)] + [InlineData("en-US", "month", DurationUnit.Month30)] + [InlineData("en-US", "months", DurationUnit.Month30)] + [InlineData("en-US", "ns", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsec", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsecs", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsecond", DurationUnit.Nanosecond)] + [InlineData("en-US", "nseconds", DurationUnit.Nanosecond)] + [InlineData("en-US", "s", DurationUnit.Second)] + [InlineData("en-US", "sec", DurationUnit.Second)] + [InlineData("en-US", "secs", DurationUnit.Second)] + [InlineData("en-US", "second", DurationUnit.Second)] + [InlineData("en-US", "seconds", DurationUnit.Second)] + [InlineData("en-US", "sol", DurationUnit.Sol)] + [InlineData("en-US", "wk", DurationUnit.Week)] + [InlineData("en-US", "week", DurationUnit.Week)] + [InlineData("en-US", "weeks", DurationUnit.Week)] + [InlineData("en-US", "yr", DurationUnit.Year365)] + [InlineData("en-US", "year", DurationUnit.Year365)] + [InlineData("en-US", "years", DurationUnit.Year365)] + [InlineData("ru-RU", "сут", DurationUnit.Day)] + [InlineData("ru-RU", "д", DurationUnit.Day)] + [InlineData("ru-RU", "ч", DurationUnit.Hour)] + [InlineData("ru-RU", "час", DurationUnit.Hour)] + [InlineData("ru-RU", "мксек", DurationUnit.Microsecond)] + [InlineData("ru-RU", "мкс", DurationUnit.Microsecond)] + [InlineData("ru-RU", "мсек", DurationUnit.Millisecond)] + [InlineData("ru-RU", "мс", DurationUnit.Millisecond)] + [InlineData("ru-RU", "мин", DurationUnit.Minute)] + [InlineData("ru-RU", "месяц", DurationUnit.Month30)] + [InlineData("ru-RU", "нсек", DurationUnit.Nanosecond)] + [InlineData("ru-RU", "нс", DurationUnit.Nanosecond)] + [InlineData("ru-RU", "сек", DurationUnit.Second)] + [InlineData("ru-RU", "с", DurationUnit.Second)] + [InlineData("ru-RU", "нед", DurationUnit.Week)] + [InlineData("ru-RU", "год", DurationUnit.Year365)] + public void ParseUnit_WithCulture(string culture, string abbreviation, DurationUnit expectedUnit) { DurationUnit parsedUnit = Duration.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1257,9 +1382,133 @@ public void ParseUnitWithCulture(string culture, string abbreviation, DurationUn [InlineData("yr", DurationUnit.Year365)] [InlineData("year", DurationUnit.Year365)] [InlineData("years", DurationUnit.Year365)] - public void TryParseUnit(string abbreviation, DurationUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, DurationUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Duration.TryParseUnit(abbreviation, out DurationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("d", DurationUnit.Day)] + [InlineData("day", DurationUnit.Day)] + [InlineData("days", DurationUnit.Day)] + [InlineData("h", DurationUnit.Hour)] + [InlineData("hr", DurationUnit.Hour)] + [InlineData("hrs", DurationUnit.Hour)] + [InlineData("hour", DurationUnit.Hour)] + [InlineData("hours", DurationUnit.Hour)] + [InlineData("jyr", DurationUnit.JulianYear)] + [InlineData("jyear", DurationUnit.JulianYear)] + [InlineData("jyears", DurationUnit.JulianYear)] + [InlineData("µs", DurationUnit.Microsecond)] + [InlineData("µsec", DurationUnit.Microsecond)] + [InlineData("µsecs", DurationUnit.Microsecond)] + [InlineData("µsecond", DurationUnit.Microsecond)] + [InlineData("µseconds", DurationUnit.Microsecond)] + [InlineData("ms", DurationUnit.Millisecond)] + [InlineData("msec", DurationUnit.Millisecond)] + [InlineData("msecs", DurationUnit.Millisecond)] + [InlineData("msecond", DurationUnit.Millisecond)] + [InlineData("mseconds", DurationUnit.Millisecond)] + [InlineData("m", DurationUnit.Minute)] + [InlineData("min", DurationUnit.Minute)] + [InlineData("minute", DurationUnit.Minute)] + [InlineData("minutes", DurationUnit.Minute)] + [InlineData("mo", DurationUnit.Month30)] + [InlineData("month", DurationUnit.Month30)] + [InlineData("months", DurationUnit.Month30)] + [InlineData("ns", DurationUnit.Nanosecond)] + [InlineData("nsec", DurationUnit.Nanosecond)] + [InlineData("nsecs", DurationUnit.Nanosecond)] + [InlineData("nsecond", DurationUnit.Nanosecond)] + [InlineData("nseconds", DurationUnit.Nanosecond)] + [InlineData("s", DurationUnit.Second)] + [InlineData("sec", DurationUnit.Second)] + [InlineData("secs", DurationUnit.Second)] + [InlineData("second", DurationUnit.Second)] + [InlineData("seconds", DurationUnit.Second)] + [InlineData("sol", DurationUnit.Sol)] + [InlineData("wk", DurationUnit.Week)] + [InlineData("week", DurationUnit.Week)] + [InlineData("weeks", DurationUnit.Week)] + [InlineData("yr", DurationUnit.Year365)] + [InlineData("year", DurationUnit.Year365)] + [InlineData("years", DurationUnit.Year365)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, DurationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Duration.TryParseUnit(abbreviation, out DurationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "d", DurationUnit.Day)] + [InlineData("en-US", "day", DurationUnit.Day)] + [InlineData("en-US", "days", DurationUnit.Day)] + [InlineData("en-US", "h", DurationUnit.Hour)] + [InlineData("en-US", "hr", DurationUnit.Hour)] + [InlineData("en-US", "hrs", DurationUnit.Hour)] + [InlineData("en-US", "hour", DurationUnit.Hour)] + [InlineData("en-US", "hours", DurationUnit.Hour)] + [InlineData("en-US", "jyr", DurationUnit.JulianYear)] + [InlineData("en-US", "jyear", DurationUnit.JulianYear)] + [InlineData("en-US", "jyears", DurationUnit.JulianYear)] + [InlineData("en-US", "µs", DurationUnit.Microsecond)] + [InlineData("en-US", "µsec", DurationUnit.Microsecond)] + [InlineData("en-US", "µsecs", DurationUnit.Microsecond)] + [InlineData("en-US", "µsecond", DurationUnit.Microsecond)] + [InlineData("en-US", "µseconds", DurationUnit.Microsecond)] + [InlineData("en-US", "ms", DurationUnit.Millisecond)] + [InlineData("en-US", "msec", DurationUnit.Millisecond)] + [InlineData("en-US", "msecs", DurationUnit.Millisecond)] + [InlineData("en-US", "msecond", DurationUnit.Millisecond)] + [InlineData("en-US", "mseconds", DurationUnit.Millisecond)] + [InlineData("en-US", "m", DurationUnit.Minute)] + [InlineData("en-US", "min", DurationUnit.Minute)] + [InlineData("en-US", "minute", DurationUnit.Minute)] + [InlineData("en-US", "minutes", DurationUnit.Minute)] + [InlineData("en-US", "mo", DurationUnit.Month30)] + [InlineData("en-US", "month", DurationUnit.Month30)] + [InlineData("en-US", "months", DurationUnit.Month30)] + [InlineData("en-US", "ns", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsec", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsecs", DurationUnit.Nanosecond)] + [InlineData("en-US", "nsecond", DurationUnit.Nanosecond)] + [InlineData("en-US", "nseconds", DurationUnit.Nanosecond)] + [InlineData("en-US", "s", DurationUnit.Second)] + [InlineData("en-US", "sec", DurationUnit.Second)] + [InlineData("en-US", "secs", DurationUnit.Second)] + [InlineData("en-US", "second", DurationUnit.Second)] + [InlineData("en-US", "seconds", DurationUnit.Second)] + [InlineData("en-US", "sol", DurationUnit.Sol)] + [InlineData("en-US", "wk", DurationUnit.Week)] + [InlineData("en-US", "week", DurationUnit.Week)] + [InlineData("en-US", "weeks", DurationUnit.Week)] + [InlineData("en-US", "yr", DurationUnit.Year365)] + [InlineData("en-US", "year", DurationUnit.Year365)] + [InlineData("en-US", "years", DurationUnit.Year365)] + [InlineData("ru-RU", "сут", DurationUnit.Day)] + [InlineData("ru-RU", "д", DurationUnit.Day)] + [InlineData("ru-RU", "ч", DurationUnit.Hour)] + [InlineData("ru-RU", "час", DurationUnit.Hour)] + [InlineData("ru-RU", "мксек", DurationUnit.Microsecond)] + [InlineData("ru-RU", "мкс", DurationUnit.Microsecond)] + [InlineData("ru-RU", "мсек", DurationUnit.Millisecond)] + [InlineData("ru-RU", "мс", DurationUnit.Millisecond)] + [InlineData("ru-RU", "мин", DurationUnit.Minute)] + [InlineData("ru-RU", "месяц", DurationUnit.Month30)] + [InlineData("ru-RU", "нсек", DurationUnit.Nanosecond)] + [InlineData("ru-RU", "нс", DurationUnit.Nanosecond)] + [InlineData("ru-RU", "сек", DurationUnit.Second)] + [InlineData("ru-RU", "с", DurationUnit.Second)] + [InlineData("ru-RU", "нед", DurationUnit.Week)] + [InlineData("ru-RU", "год", DurationUnit.Year365)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, DurationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Duration.TryParseUnit(abbreviation, out DurationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1326,7 +1575,7 @@ public void TryParseUnit(string abbreviation, DurationUnit expectedUnit) [InlineData("ru-RU", "с", DurationUnit.Second)] [InlineData("ru-RU", "нед", DurationUnit.Week)] [InlineData("ru-RU", "год", DurationUnit.Year365)] - public void TryParseUnitWithCulture(string culture, string abbreviation, DurationUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, DurationUnit expectedUnit) { Assert.True(Duration.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out DurationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs index 25dc2dd620..32f8f7f84a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/DynamicViscosityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -460,10 +461,33 @@ public void TryParse() [InlineData("lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] [InlineData("lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] [InlineData("reyn", DynamicViscosityUnit.Reyn)] - public void ParseUnit(string abbreviation, DynamicViscosityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, DynamicViscosityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - DynamicViscosityUnit parsedUnit = DynamicViscosity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + DynamicViscosityUnit parsedUnit = DynamicViscosity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cP", DynamicViscosityUnit.Centipoise)] + [InlineData("µPa·s", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("µPaS", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("mPa·s", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("mPaS", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("Ns/m²", DynamicViscosityUnit.NewtonSecondPerMeterSquared)] + [InlineData("Pa·s", DynamicViscosityUnit.PascalSecond)] + [InlineData("PaS", DynamicViscosityUnit.PascalSecond)] + [InlineData("P", DynamicViscosityUnit.Poise)] + [InlineData("lbf·s/ft²", DynamicViscosityUnit.PoundForceSecondPerSquareFoot)] + [InlineData("lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] + [InlineData("lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] + [InlineData("reyn", DynamicViscosityUnit.Reyn)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, DynamicViscosityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + DynamicViscosityUnit parsedUnit = DynamicViscosity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -481,7 +505,28 @@ public void ParseUnit(string abbreviation, DynamicViscosityUnit expectedUnit) [InlineData("en-US", "lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] [InlineData("en-US", "lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] [InlineData("en-US", "reyn", DynamicViscosityUnit.Reyn)] - public void ParseUnitWithCulture(string culture, string abbreviation, DynamicViscosityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, DynamicViscosityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + DynamicViscosityUnit parsedUnit = DynamicViscosity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cP", DynamicViscosityUnit.Centipoise)] + [InlineData("en-US", "µPa·s", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("en-US", "µPaS", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("en-US", "mPa·s", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("en-US", "mPaS", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("en-US", "Ns/m²", DynamicViscosityUnit.NewtonSecondPerMeterSquared)] + [InlineData("en-US", "Pa·s", DynamicViscosityUnit.PascalSecond)] + [InlineData("en-US", "PaS", DynamicViscosityUnit.PascalSecond)] + [InlineData("en-US", "P", DynamicViscosityUnit.Poise)] + [InlineData("en-US", "lbf·s/ft²", DynamicViscosityUnit.PoundForceSecondPerSquareFoot)] + [InlineData("en-US", "lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] + [InlineData("en-US", "lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] + [InlineData("en-US", "reyn", DynamicViscosityUnit.Reyn)] + public void ParseUnit_WithCulture(string culture, string abbreviation, DynamicViscosityUnit expectedUnit) { DynamicViscosityUnit parsedUnit = DynamicViscosity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -501,9 +546,53 @@ public void ParseUnitWithCulture(string culture, string abbreviation, DynamicVis [InlineData("lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] [InlineData("lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] [InlineData("reyn", DynamicViscosityUnit.Reyn)] - public void TryParseUnit(string abbreviation, DynamicViscosityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, DynamicViscosityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(DynamicViscosity.TryParseUnit(abbreviation, out DynamicViscosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cP", DynamicViscosityUnit.Centipoise)] + [InlineData("µPa·s", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("µPaS", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("mPa·s", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("mPaS", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("Ns/m²", DynamicViscosityUnit.NewtonSecondPerMeterSquared)] + [InlineData("Pa·s", DynamicViscosityUnit.PascalSecond)] + [InlineData("PaS", DynamicViscosityUnit.PascalSecond)] + [InlineData("P", DynamicViscosityUnit.Poise)] + [InlineData("lbf·s/ft²", DynamicViscosityUnit.PoundForceSecondPerSquareFoot)] + [InlineData("lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] + [InlineData("lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] + [InlineData("reyn", DynamicViscosityUnit.Reyn)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, DynamicViscosityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(DynamicViscosity.TryParseUnit(abbreviation, out DynamicViscosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cP", DynamicViscosityUnit.Centipoise)] + [InlineData("en-US", "µPa·s", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("en-US", "µPaS", DynamicViscosityUnit.MicropascalSecond)] + [InlineData("en-US", "mPa·s", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("en-US", "mPaS", DynamicViscosityUnit.MillipascalSecond)] + [InlineData("en-US", "Ns/m²", DynamicViscosityUnit.NewtonSecondPerMeterSquared)] + [InlineData("en-US", "Pa·s", DynamicViscosityUnit.PascalSecond)] + [InlineData("en-US", "PaS", DynamicViscosityUnit.PascalSecond)] + [InlineData("en-US", "P", DynamicViscosityUnit.Poise)] + [InlineData("en-US", "lbf·s/ft²", DynamicViscosityUnit.PoundForceSecondPerSquareFoot)] + [InlineData("en-US", "lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] + [InlineData("en-US", "lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] + [InlineData("en-US", "reyn", DynamicViscosityUnit.Reyn)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, DynamicViscosityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(DynamicViscosity.TryParseUnit(abbreviation, out DynamicViscosityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -522,7 +611,7 @@ public void TryParseUnit(string abbreviation, DynamicViscosityUnit expectedUnit) [InlineData("en-US", "lbf·s/in²", DynamicViscosityUnit.PoundForceSecondPerSquareInch)] [InlineData("en-US", "lb/(ft·s)", DynamicViscosityUnit.PoundPerFootSecond)] [InlineData("en-US", "reyn", DynamicViscosityUnit.Reyn)] - public void TryParseUnitWithCulture(string culture, string abbreviation, DynamicViscosityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, DynamicViscosityUnit expectedUnit) { Assert.True(DynamicViscosity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out DynamicViscosityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs index f67851c508..84cc030d3c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricAdmittanceTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -274,10 +275,24 @@ public void TryParse() [InlineData("mS", ElectricAdmittanceUnit.Millisiemens)] [InlineData("nS", ElectricAdmittanceUnit.Nanosiemens)] [InlineData("S", ElectricAdmittanceUnit.Siemens)] - public void ParseUnit(string abbreviation, ElectricAdmittanceUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricAdmittanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricAdmittanceUnit parsedUnit = ElectricAdmittance.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricAdmittanceUnit parsedUnit = ElectricAdmittance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("µS", ElectricAdmittanceUnit.Microsiemens)] + [InlineData("mS", ElectricAdmittanceUnit.Millisiemens)] + [InlineData("nS", ElectricAdmittanceUnit.Nanosiemens)] + [InlineData("S", ElectricAdmittanceUnit.Siemens)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricAdmittanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricAdmittanceUnit parsedUnit = ElectricAdmittance.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -286,7 +301,19 @@ public void ParseUnit(string abbreviation, ElectricAdmittanceUnit expectedUnit) [InlineData("en-US", "mS", ElectricAdmittanceUnit.Millisiemens)] [InlineData("en-US", "nS", ElectricAdmittanceUnit.Nanosiemens)] [InlineData("en-US", "S", ElectricAdmittanceUnit.Siemens)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricAdmittanceUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricAdmittanceUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricAdmittanceUnit parsedUnit = ElectricAdmittance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "µS", ElectricAdmittanceUnit.Microsiemens)] + [InlineData("en-US", "mS", ElectricAdmittanceUnit.Millisiemens)] + [InlineData("en-US", "nS", ElectricAdmittanceUnit.Nanosiemens)] + [InlineData("en-US", "S", ElectricAdmittanceUnit.Siemens)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricAdmittanceUnit expectedUnit) { ElectricAdmittanceUnit parsedUnit = ElectricAdmittance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -297,9 +324,35 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricAd [InlineData("mS", ElectricAdmittanceUnit.Millisiemens)] [InlineData("nS", ElectricAdmittanceUnit.Nanosiemens)] [InlineData("S", ElectricAdmittanceUnit.Siemens)] - public void TryParseUnit(string abbreviation, ElectricAdmittanceUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricAdmittanceUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricAdmittance.TryParseUnit(abbreviation, out ElectricAdmittanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("µS", ElectricAdmittanceUnit.Microsiemens)] + [InlineData("mS", ElectricAdmittanceUnit.Millisiemens)] + [InlineData("nS", ElectricAdmittanceUnit.Nanosiemens)] + [InlineData("S", ElectricAdmittanceUnit.Siemens)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricAdmittanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricAdmittance.TryParseUnit(abbreviation, out ElectricAdmittanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "µS", ElectricAdmittanceUnit.Microsiemens)] + [InlineData("en-US", "mS", ElectricAdmittanceUnit.Millisiemens)] + [InlineData("en-US", "nS", ElectricAdmittanceUnit.Nanosiemens)] + [InlineData("en-US", "S", ElectricAdmittanceUnit.Siemens)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricAdmittanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricAdmittance.TryParseUnit(abbreviation, out ElectricAdmittanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -309,7 +362,7 @@ public void TryParseUnit(string abbreviation, ElectricAdmittanceUnit expectedUni [InlineData("en-US", "mS", ElectricAdmittanceUnit.Millisiemens)] [InlineData("en-US", "nS", ElectricAdmittanceUnit.Nanosiemens)] [InlineData("en-US", "S", ElectricAdmittanceUnit.Siemens)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricAdmittanceUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricAdmittanceUnit expectedUnit) { Assert.True(ElectricAdmittance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricAdmittanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs index f8fcf4d545..e47a2afb14 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeDensityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] - public void ParseUnit(string abbreviation, ElectricChargeDensityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricChargeDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricChargeDensityUnit parsedUnit = ElectricChargeDensity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricChargeDensityUnit parsedUnit = ElectricChargeDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricChargeDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricChargeDensityUnit parsedUnit = ElectricChargeDensity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricChargeDensityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricChargeDensityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricChargeDensityUnit parsedUnit = ElectricChargeDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricChargeDensityUnit expectedUnit) { ElectricChargeDensityUnit parsedUnit = ElectricChargeDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCh [Theory] [InlineData("C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] - public void TryParseUnit(string abbreviation, ElectricChargeDensityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricChargeDensityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricChargeDensity.TryParseUnit(abbreviation, out ElectricChargeDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricChargeDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricChargeDensity.TryParseUnit(abbreviation, out ElectricChargeDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricChargeDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricChargeDensity.TryParseUnit(abbreviation, out ElectricChargeDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "C/m³", ElectricChargeDensityUnit.CoulombPerCubicMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricChargeDensityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricChargeDensityUnit expectedUnit) { Assert.True(ElectricChargeDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricChargeDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs index ead7fe2bb6..e3a1553900 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricChargeTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -462,10 +463,35 @@ public void TryParse() [InlineData("mC", ElectricChargeUnit.Millicoulomb)] [InlineData("nC", ElectricChargeUnit.Nanocoulomb)] [InlineData("pC", ElectricChargeUnit.Picocoulomb)] - public void ParseUnit(string abbreviation, ElectricChargeUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricChargeUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricChargeUnit parsedUnit = ElectricCharge.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricChargeUnit parsedUnit = ElectricCharge.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("A-h", ElectricChargeUnit.AmpereHour)] + [InlineData("Ah", ElectricChargeUnit.AmpereHour)] + [InlineData("C", ElectricChargeUnit.Coulomb)] + [InlineData("kA-h", ElectricChargeUnit.KiloampereHour)] + [InlineData("kAh", ElectricChargeUnit.KiloampereHour)] + [InlineData("kC", ElectricChargeUnit.Kilocoulomb)] + [InlineData("MA-h", ElectricChargeUnit.MegaampereHour)] + [InlineData("MAh", ElectricChargeUnit.MegaampereHour)] + [InlineData("MC", ElectricChargeUnit.Megacoulomb)] + [InlineData("µC", ElectricChargeUnit.Microcoulomb)] + [InlineData("mA-h", ElectricChargeUnit.MilliampereHour)] + [InlineData("mAh", ElectricChargeUnit.MilliampereHour)] + [InlineData("mC", ElectricChargeUnit.Millicoulomb)] + [InlineData("nC", ElectricChargeUnit.Nanocoulomb)] + [InlineData("pC", ElectricChargeUnit.Picocoulomb)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricChargeUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricChargeUnit parsedUnit = ElectricCharge.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -485,7 +511,30 @@ public void ParseUnit(string abbreviation, ElectricChargeUnit expectedUnit) [InlineData("en-US", "mC", ElectricChargeUnit.Millicoulomb)] [InlineData("en-US", "nC", ElectricChargeUnit.Nanocoulomb)] [InlineData("en-US", "pC", ElectricChargeUnit.Picocoulomb)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricChargeUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricChargeUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricChargeUnit parsedUnit = ElectricCharge.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "A-h", ElectricChargeUnit.AmpereHour)] + [InlineData("en-US", "Ah", ElectricChargeUnit.AmpereHour)] + [InlineData("en-US", "C", ElectricChargeUnit.Coulomb)] + [InlineData("en-US", "kA-h", ElectricChargeUnit.KiloampereHour)] + [InlineData("en-US", "kAh", ElectricChargeUnit.KiloampereHour)] + [InlineData("en-US", "kC", ElectricChargeUnit.Kilocoulomb)] + [InlineData("en-US", "MA-h", ElectricChargeUnit.MegaampereHour)] + [InlineData("en-US", "MAh", ElectricChargeUnit.MegaampereHour)] + [InlineData("en-US", "MC", ElectricChargeUnit.Megacoulomb)] + [InlineData("en-US", "µC", ElectricChargeUnit.Microcoulomb)] + [InlineData("en-US", "mA-h", ElectricChargeUnit.MilliampereHour)] + [InlineData("en-US", "mAh", ElectricChargeUnit.MilliampereHour)] + [InlineData("en-US", "mC", ElectricChargeUnit.Millicoulomb)] + [InlineData("en-US", "nC", ElectricChargeUnit.Nanocoulomb)] + [InlineData("en-US", "pC", ElectricChargeUnit.Picocoulomb)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricChargeUnit expectedUnit) { ElectricChargeUnit parsedUnit = ElectricCharge.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -507,9 +556,57 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCh [InlineData("mC", ElectricChargeUnit.Millicoulomb)] [InlineData("nC", ElectricChargeUnit.Nanocoulomb)] [InlineData("pC", ElectricChargeUnit.Picocoulomb)] - public void TryParseUnit(string abbreviation, ElectricChargeUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricChargeUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricCharge.TryParseUnit(abbreviation, out ElectricChargeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("A-h", ElectricChargeUnit.AmpereHour)] + [InlineData("Ah", ElectricChargeUnit.AmpereHour)] + [InlineData("C", ElectricChargeUnit.Coulomb)] + [InlineData("kA-h", ElectricChargeUnit.KiloampereHour)] + [InlineData("kAh", ElectricChargeUnit.KiloampereHour)] + [InlineData("kC", ElectricChargeUnit.Kilocoulomb)] + [InlineData("MA-h", ElectricChargeUnit.MegaampereHour)] + [InlineData("MAh", ElectricChargeUnit.MegaampereHour)] + [InlineData("MC", ElectricChargeUnit.Megacoulomb)] + [InlineData("µC", ElectricChargeUnit.Microcoulomb)] + [InlineData("mA-h", ElectricChargeUnit.MilliampereHour)] + [InlineData("mAh", ElectricChargeUnit.MilliampereHour)] + [InlineData("mC", ElectricChargeUnit.Millicoulomb)] + [InlineData("nC", ElectricChargeUnit.Nanocoulomb)] + [InlineData("pC", ElectricChargeUnit.Picocoulomb)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricChargeUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricCharge.TryParseUnit(abbreviation, out ElectricChargeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "A-h", ElectricChargeUnit.AmpereHour)] + [InlineData("en-US", "Ah", ElectricChargeUnit.AmpereHour)] + [InlineData("en-US", "C", ElectricChargeUnit.Coulomb)] + [InlineData("en-US", "kA-h", ElectricChargeUnit.KiloampereHour)] + [InlineData("en-US", "kAh", ElectricChargeUnit.KiloampereHour)] + [InlineData("en-US", "kC", ElectricChargeUnit.Kilocoulomb)] + [InlineData("en-US", "MA-h", ElectricChargeUnit.MegaampereHour)] + [InlineData("en-US", "MAh", ElectricChargeUnit.MegaampereHour)] + [InlineData("en-US", "MC", ElectricChargeUnit.Megacoulomb)] + [InlineData("en-US", "µC", ElectricChargeUnit.Microcoulomb)] + [InlineData("en-US", "mA-h", ElectricChargeUnit.MilliampereHour)] + [InlineData("en-US", "mAh", ElectricChargeUnit.MilliampereHour)] + [InlineData("en-US", "mC", ElectricChargeUnit.Millicoulomb)] + [InlineData("en-US", "nC", ElectricChargeUnit.Nanocoulomb)] + [InlineData("en-US", "pC", ElectricChargeUnit.Picocoulomb)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricChargeUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricCharge.TryParseUnit(abbreviation, out ElectricChargeUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -530,7 +627,7 @@ public void TryParseUnit(string abbreviation, ElectricChargeUnit expectedUnit) [InlineData("en-US", "mC", ElectricChargeUnit.Millicoulomb)] [InlineData("en-US", "nC", ElectricChargeUnit.Nanocoulomb)] [InlineData("en-US", "pC", ElectricChargeUnit.Picocoulomb)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricChargeUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricChargeUnit expectedUnit) { Assert.True(ElectricCharge.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricChargeUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs index ab6a456dc7..3b24243e69 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductanceTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -298,10 +299,25 @@ public void TryParse() [InlineData("mS", ElectricConductanceUnit.Millisiemens)] [InlineData("nS", ElectricConductanceUnit.Nanosiemens)] [InlineData("S", ElectricConductanceUnit.Siemens)] - public void ParseUnit(string abbreviation, ElectricConductanceUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricConductanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricConductanceUnit parsedUnit = ElectricConductance.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricConductanceUnit parsedUnit = ElectricConductance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kS", ElectricConductanceUnit.Kilosiemens)] + [InlineData("µS", ElectricConductanceUnit.Microsiemens)] + [InlineData("mS", ElectricConductanceUnit.Millisiemens)] + [InlineData("nS", ElectricConductanceUnit.Nanosiemens)] + [InlineData("S", ElectricConductanceUnit.Siemens)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricConductanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricConductanceUnit parsedUnit = ElectricConductance.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -311,7 +327,20 @@ public void ParseUnit(string abbreviation, ElectricConductanceUnit expectedUnit) [InlineData("en-US", "mS", ElectricConductanceUnit.Millisiemens)] [InlineData("en-US", "nS", ElectricConductanceUnit.Nanosiemens)] [InlineData("en-US", "S", ElectricConductanceUnit.Siemens)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricConductanceUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricConductanceUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricConductanceUnit parsedUnit = ElectricConductance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kS", ElectricConductanceUnit.Kilosiemens)] + [InlineData("en-US", "µS", ElectricConductanceUnit.Microsiemens)] + [InlineData("en-US", "mS", ElectricConductanceUnit.Millisiemens)] + [InlineData("en-US", "nS", ElectricConductanceUnit.Nanosiemens)] + [InlineData("en-US", "S", ElectricConductanceUnit.Siemens)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricConductanceUnit expectedUnit) { ElectricConductanceUnit parsedUnit = ElectricConductance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -323,9 +352,37 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCo [InlineData("mS", ElectricConductanceUnit.Millisiemens)] [InlineData("nS", ElectricConductanceUnit.Nanosiemens)] [InlineData("S", ElectricConductanceUnit.Siemens)] - public void TryParseUnit(string abbreviation, ElectricConductanceUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricConductanceUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricConductance.TryParseUnit(abbreviation, out ElectricConductanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kS", ElectricConductanceUnit.Kilosiemens)] + [InlineData("µS", ElectricConductanceUnit.Microsiemens)] + [InlineData("mS", ElectricConductanceUnit.Millisiemens)] + [InlineData("nS", ElectricConductanceUnit.Nanosiemens)] + [InlineData("S", ElectricConductanceUnit.Siemens)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricConductanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricConductance.TryParseUnit(abbreviation, out ElectricConductanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kS", ElectricConductanceUnit.Kilosiemens)] + [InlineData("en-US", "µS", ElectricConductanceUnit.Microsiemens)] + [InlineData("en-US", "mS", ElectricConductanceUnit.Millisiemens)] + [InlineData("en-US", "nS", ElectricConductanceUnit.Nanosiemens)] + [InlineData("en-US", "S", ElectricConductanceUnit.Siemens)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricConductanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricConductance.TryParseUnit(abbreviation, out ElectricConductanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -336,7 +393,7 @@ public void TryParseUnit(string abbreviation, ElectricConductanceUnit expectedUn [InlineData("en-US", "mS", ElectricConductanceUnit.Millisiemens)] [InlineData("en-US", "nS", ElectricConductanceUnit.Nanosiemens)] [InlineData("en-US", "S", ElectricConductanceUnit.Siemens)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricConductanceUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricConductanceUnit expectedUnit) { Assert.True(ElectricConductance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricConductanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs index fa0876324a..e98d9b7c26 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricConductivityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -322,10 +323,26 @@ public void TryParse() [InlineData("S/ft", ElectricConductivityUnit.SiemensPerFoot)] [InlineData("S/in", ElectricConductivityUnit.SiemensPerInch)] [InlineData("S/m", ElectricConductivityUnit.SiemensPerMeter)] - public void ParseUnit(string abbreviation, ElectricConductivityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricConductivityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricConductivityUnit parsedUnit = ElectricConductivity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricConductivityUnit parsedUnit = ElectricConductivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("µS/cm", ElectricConductivityUnit.MicrosiemensPerCentimeter)] + [InlineData("mS/cm", ElectricConductivityUnit.MillisiemensPerCentimeter)] + [InlineData("S/cm", ElectricConductivityUnit.SiemensPerCentimeter)] + [InlineData("S/ft", ElectricConductivityUnit.SiemensPerFoot)] + [InlineData("S/in", ElectricConductivityUnit.SiemensPerInch)] + [InlineData("S/m", ElectricConductivityUnit.SiemensPerMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricConductivityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricConductivityUnit parsedUnit = ElectricConductivity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -336,7 +353,21 @@ public void ParseUnit(string abbreviation, ElectricConductivityUnit expectedUnit [InlineData("en-US", "S/ft", ElectricConductivityUnit.SiemensPerFoot)] [InlineData("en-US", "S/in", ElectricConductivityUnit.SiemensPerInch)] [InlineData("en-US", "S/m", ElectricConductivityUnit.SiemensPerMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricConductivityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricConductivityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricConductivityUnit parsedUnit = ElectricConductivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "µS/cm", ElectricConductivityUnit.MicrosiemensPerCentimeter)] + [InlineData("en-US", "mS/cm", ElectricConductivityUnit.MillisiemensPerCentimeter)] + [InlineData("en-US", "S/cm", ElectricConductivityUnit.SiemensPerCentimeter)] + [InlineData("en-US", "S/ft", ElectricConductivityUnit.SiemensPerFoot)] + [InlineData("en-US", "S/in", ElectricConductivityUnit.SiemensPerInch)] + [InlineData("en-US", "S/m", ElectricConductivityUnit.SiemensPerMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricConductivityUnit expectedUnit) { ElectricConductivityUnit parsedUnit = ElectricConductivity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -349,9 +380,39 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCo [InlineData("S/ft", ElectricConductivityUnit.SiemensPerFoot)] [InlineData("S/in", ElectricConductivityUnit.SiemensPerInch)] [InlineData("S/m", ElectricConductivityUnit.SiemensPerMeter)] - public void TryParseUnit(string abbreviation, ElectricConductivityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricConductivityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricConductivity.TryParseUnit(abbreviation, out ElectricConductivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("µS/cm", ElectricConductivityUnit.MicrosiemensPerCentimeter)] + [InlineData("mS/cm", ElectricConductivityUnit.MillisiemensPerCentimeter)] + [InlineData("S/cm", ElectricConductivityUnit.SiemensPerCentimeter)] + [InlineData("S/ft", ElectricConductivityUnit.SiemensPerFoot)] + [InlineData("S/in", ElectricConductivityUnit.SiemensPerInch)] + [InlineData("S/m", ElectricConductivityUnit.SiemensPerMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricConductivityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricConductivity.TryParseUnit(abbreviation, out ElectricConductivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "µS/cm", ElectricConductivityUnit.MicrosiemensPerCentimeter)] + [InlineData("en-US", "mS/cm", ElectricConductivityUnit.MillisiemensPerCentimeter)] + [InlineData("en-US", "S/cm", ElectricConductivityUnit.SiemensPerCentimeter)] + [InlineData("en-US", "S/ft", ElectricConductivityUnit.SiemensPerFoot)] + [InlineData("en-US", "S/in", ElectricConductivityUnit.SiemensPerInch)] + [InlineData("en-US", "S/m", ElectricConductivityUnit.SiemensPerMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricConductivityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricConductivity.TryParseUnit(abbreviation, out ElectricConductivityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -363,7 +424,7 @@ public void TryParseUnit(string abbreviation, ElectricConductivityUnit expectedU [InlineData("en-US", "S/ft", ElectricConductivityUnit.SiemensPerFoot)] [InlineData("en-US", "S/in", ElectricConductivityUnit.SiemensPerInch)] [InlineData("en-US", "S/m", ElectricConductivityUnit.SiemensPerMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricConductivityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricConductivityUnit expectedUnit) { Assert.True(ElectricConductivity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricConductivityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs index 87579b81fd..5685a0180e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentDensityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -250,10 +251,23 @@ public void TryParse() [InlineData("A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] [InlineData("A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] [InlineData("A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] - public void ParseUnit(string abbreviation, ElectricCurrentDensityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricCurrentDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricCurrentDensityUnit parsedUnit = ElectricCurrentDensity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricCurrentDensityUnit parsedUnit = ElectricCurrentDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] + [InlineData("A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] + [InlineData("A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricCurrentDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricCurrentDensityUnit parsedUnit = ElectricCurrentDensity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -261,7 +275,18 @@ public void ParseUnit(string abbreviation, ElectricCurrentDensityUnit expectedUn [InlineData("en-US", "A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] [InlineData("en-US", "A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] [InlineData("en-US", "A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentDensityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricCurrentDensityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricCurrentDensityUnit parsedUnit = ElectricCurrentDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] + [InlineData("en-US", "A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] + [InlineData("en-US", "A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricCurrentDensityUnit expectedUnit) { ElectricCurrentDensityUnit parsedUnit = ElectricCurrentDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -271,9 +296,33 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCu [InlineData("A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] [InlineData("A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] [InlineData("A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] - public void TryParseUnit(string abbreviation, ElectricCurrentDensityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricCurrentDensityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricCurrentDensity.TryParseUnit(abbreviation, out ElectricCurrentDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] + [InlineData("A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] + [InlineData("A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricCurrentDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricCurrentDensity.TryParseUnit(abbreviation, out ElectricCurrentDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] + [InlineData("en-US", "A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] + [InlineData("en-US", "A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricCurrentDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricCurrentDensity.TryParseUnit(abbreviation, out ElectricCurrentDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -282,7 +331,7 @@ public void TryParseUnit(string abbreviation, ElectricCurrentDensityUnit expecte [InlineData("en-US", "A/ft²", ElectricCurrentDensityUnit.AmperePerSquareFoot)] [InlineData("en-US", "A/in²", ElectricCurrentDensityUnit.AmperePerSquareInch)] [InlineData("en-US", "A/m²", ElectricCurrentDensityUnit.AmperePerSquareMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentDensityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricCurrentDensityUnit expectedUnit) { Assert.True(ElectricCurrentDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricCurrentDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs index 836aecb346..fbde868f1c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentGradientTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -346,10 +347,27 @@ public void TryParse() [InlineData("A/s", ElectricCurrentGradientUnit.AmperePerSecond)] [InlineData("mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] [InlineData("mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] - public void ParseUnit(string abbreviation, ElectricCurrentGradientUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricCurrentGradientUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricCurrentGradientUnit parsedUnit = ElectricCurrentGradient.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricCurrentGradientUnit parsedUnit = ElectricCurrentGradient.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("A/μs", ElectricCurrentGradientUnit.AmperePerMicrosecond)] + [InlineData("A/ms", ElectricCurrentGradientUnit.AmperePerMillisecond)] + [InlineData("A/min", ElectricCurrentGradientUnit.AmperePerMinute)] + [InlineData("A/ns", ElectricCurrentGradientUnit.AmperePerNanosecond)] + [InlineData("A/s", ElectricCurrentGradientUnit.AmperePerSecond)] + [InlineData("mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] + [InlineData("mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricCurrentGradientUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricCurrentGradientUnit parsedUnit = ElectricCurrentGradient.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -361,7 +379,22 @@ public void ParseUnit(string abbreviation, ElectricCurrentGradientUnit expectedU [InlineData("en-US", "A/s", ElectricCurrentGradientUnit.AmperePerSecond)] [InlineData("en-US", "mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] [InlineData("en-US", "mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentGradientUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricCurrentGradientUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricCurrentGradientUnit parsedUnit = ElectricCurrentGradient.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "A/μs", ElectricCurrentGradientUnit.AmperePerMicrosecond)] + [InlineData("en-US", "A/ms", ElectricCurrentGradientUnit.AmperePerMillisecond)] + [InlineData("en-US", "A/min", ElectricCurrentGradientUnit.AmperePerMinute)] + [InlineData("en-US", "A/ns", ElectricCurrentGradientUnit.AmperePerNanosecond)] + [InlineData("en-US", "A/s", ElectricCurrentGradientUnit.AmperePerSecond)] + [InlineData("en-US", "mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] + [InlineData("en-US", "mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricCurrentGradientUnit expectedUnit) { ElectricCurrentGradientUnit parsedUnit = ElectricCurrentGradient.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -375,9 +408,41 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCu [InlineData("A/s", ElectricCurrentGradientUnit.AmperePerSecond)] [InlineData("mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] [InlineData("mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] - public void TryParseUnit(string abbreviation, ElectricCurrentGradientUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricCurrentGradientUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricCurrentGradient.TryParseUnit(abbreviation, out ElectricCurrentGradientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("A/μs", ElectricCurrentGradientUnit.AmperePerMicrosecond)] + [InlineData("A/ms", ElectricCurrentGradientUnit.AmperePerMillisecond)] + [InlineData("A/min", ElectricCurrentGradientUnit.AmperePerMinute)] + [InlineData("A/ns", ElectricCurrentGradientUnit.AmperePerNanosecond)] + [InlineData("A/s", ElectricCurrentGradientUnit.AmperePerSecond)] + [InlineData("mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] + [InlineData("mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricCurrentGradientUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricCurrentGradient.TryParseUnit(abbreviation, out ElectricCurrentGradientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "A/μs", ElectricCurrentGradientUnit.AmperePerMicrosecond)] + [InlineData("en-US", "A/ms", ElectricCurrentGradientUnit.AmperePerMillisecond)] + [InlineData("en-US", "A/min", ElectricCurrentGradientUnit.AmperePerMinute)] + [InlineData("en-US", "A/ns", ElectricCurrentGradientUnit.AmperePerNanosecond)] + [InlineData("en-US", "A/s", ElectricCurrentGradientUnit.AmperePerSecond)] + [InlineData("en-US", "mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] + [InlineData("en-US", "mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricCurrentGradientUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricCurrentGradient.TryParseUnit(abbreviation, out ElectricCurrentGradientUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -390,7 +455,7 @@ public void TryParseUnit(string abbreviation, ElectricCurrentGradientUnit expect [InlineData("en-US", "A/s", ElectricCurrentGradientUnit.AmperePerSecond)] [InlineData("en-US", "mA/min", ElectricCurrentGradientUnit.MilliamperePerMinute)] [InlineData("en-US", "mA/s", ElectricCurrentGradientUnit.MilliamperePerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentGradientUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricCurrentGradientUnit expectedUnit) { Assert.True(ElectricCurrentGradient.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricCurrentGradientUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs index 418bddb157..700ccefb6e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricCurrentTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -382,10 +383,29 @@ public void TryParse() [InlineData("mA", ElectricCurrentUnit.Milliampere)] [InlineData("nA", ElectricCurrentUnit.Nanoampere)] [InlineData("pA", ElectricCurrentUnit.Picoampere)] - public void ParseUnit(string abbreviation, ElectricCurrentUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricCurrentUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricCurrentUnit parsedUnit = ElectricCurrent.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricCurrentUnit parsedUnit = ElectricCurrent.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("A", ElectricCurrentUnit.Ampere)] + [InlineData("cA", ElectricCurrentUnit.Centiampere)] + [InlineData("fA", ElectricCurrentUnit.Femtoampere)] + [InlineData("kA", ElectricCurrentUnit.Kiloampere)] + [InlineData("MA", ElectricCurrentUnit.Megaampere)] + [InlineData("µA", ElectricCurrentUnit.Microampere)] + [InlineData("mA", ElectricCurrentUnit.Milliampere)] + [InlineData("nA", ElectricCurrentUnit.Nanoampere)] + [InlineData("pA", ElectricCurrentUnit.Picoampere)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricCurrentUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricCurrentUnit parsedUnit = ElectricCurrent.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -399,7 +419,24 @@ public void ParseUnit(string abbreviation, ElectricCurrentUnit expectedUnit) [InlineData("en-US", "mA", ElectricCurrentUnit.Milliampere)] [InlineData("en-US", "nA", ElectricCurrentUnit.Nanoampere)] [InlineData("en-US", "pA", ElectricCurrentUnit.Picoampere)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricCurrentUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricCurrentUnit parsedUnit = ElectricCurrent.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "A", ElectricCurrentUnit.Ampere)] + [InlineData("en-US", "cA", ElectricCurrentUnit.Centiampere)] + [InlineData("en-US", "fA", ElectricCurrentUnit.Femtoampere)] + [InlineData("en-US", "kA", ElectricCurrentUnit.Kiloampere)] + [InlineData("en-US", "MA", ElectricCurrentUnit.Megaampere)] + [InlineData("en-US", "µA", ElectricCurrentUnit.Microampere)] + [InlineData("en-US", "mA", ElectricCurrentUnit.Milliampere)] + [InlineData("en-US", "nA", ElectricCurrentUnit.Nanoampere)] + [InlineData("en-US", "pA", ElectricCurrentUnit.Picoampere)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricCurrentUnit expectedUnit) { ElectricCurrentUnit parsedUnit = ElectricCurrent.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -415,9 +452,45 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricCu [InlineData("mA", ElectricCurrentUnit.Milliampere)] [InlineData("nA", ElectricCurrentUnit.Nanoampere)] [InlineData("pA", ElectricCurrentUnit.Picoampere)] - public void TryParseUnit(string abbreviation, ElectricCurrentUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricCurrentUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricCurrent.TryParseUnit(abbreviation, out ElectricCurrentUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("A", ElectricCurrentUnit.Ampere)] + [InlineData("cA", ElectricCurrentUnit.Centiampere)] + [InlineData("fA", ElectricCurrentUnit.Femtoampere)] + [InlineData("kA", ElectricCurrentUnit.Kiloampere)] + [InlineData("MA", ElectricCurrentUnit.Megaampere)] + [InlineData("µA", ElectricCurrentUnit.Microampere)] + [InlineData("mA", ElectricCurrentUnit.Milliampere)] + [InlineData("nA", ElectricCurrentUnit.Nanoampere)] + [InlineData("pA", ElectricCurrentUnit.Picoampere)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricCurrentUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricCurrent.TryParseUnit(abbreviation, out ElectricCurrentUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "A", ElectricCurrentUnit.Ampere)] + [InlineData("en-US", "cA", ElectricCurrentUnit.Centiampere)] + [InlineData("en-US", "fA", ElectricCurrentUnit.Femtoampere)] + [InlineData("en-US", "kA", ElectricCurrentUnit.Kiloampere)] + [InlineData("en-US", "MA", ElectricCurrentUnit.Megaampere)] + [InlineData("en-US", "µA", ElectricCurrentUnit.Microampere)] + [InlineData("en-US", "mA", ElectricCurrentUnit.Milliampere)] + [InlineData("en-US", "nA", ElectricCurrentUnit.Nanoampere)] + [InlineData("en-US", "pA", ElectricCurrentUnit.Picoampere)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricCurrentUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricCurrent.TryParseUnit(abbreviation, out ElectricCurrentUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -432,7 +505,7 @@ public void TryParseUnit(string abbreviation, ElectricCurrentUnit expectedUnit) [InlineData("en-US", "mA", ElectricCurrentUnit.Milliampere)] [InlineData("en-US", "nA", ElectricCurrentUnit.Nanoampere)] [InlineData("en-US", "pA", ElectricCurrentUnit.Picoampere)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricCurrentUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricCurrentUnit expectedUnit) { Assert.True(ElectricCurrent.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricCurrentUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs index 2ac12fd273..071cbddb96 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricFieldTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("V/m", ElectricFieldUnit.VoltPerMeter)] - public void ParseUnit(string abbreviation, ElectricFieldUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricFieldUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricFieldUnit parsedUnit = ElectricField.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricFieldUnit parsedUnit = ElectricField.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("V/m", ElectricFieldUnit.VoltPerMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricFieldUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricFieldUnit parsedUnit = ElectricField.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "V/m", ElectricFieldUnit.VoltPerMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricFieldUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricFieldUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricFieldUnit parsedUnit = ElectricField.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "V/m", ElectricFieldUnit.VoltPerMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricFieldUnit expectedUnit) { ElectricFieldUnit parsedUnit = ElectricField.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricFi [Theory] [InlineData("V/m", ElectricFieldUnit.VoltPerMeter)] - public void TryParseUnit(string abbreviation, ElectricFieldUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricFieldUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricField.TryParseUnit(abbreviation, out ElectricFieldUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("V/m", ElectricFieldUnit.VoltPerMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricFieldUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricField.TryParseUnit(abbreviation, out ElectricFieldUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "V/m", ElectricFieldUnit.VoltPerMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricFieldUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricField.TryParseUnit(abbreviation, out ElectricFieldUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "V/m", ElectricFieldUnit.VoltPerMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricFieldUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricFieldUnit expectedUnit) { Assert.True(ElectricField.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricFieldUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs index a3b77ef90d..76aa1475b2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricInductanceTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -298,10 +299,25 @@ public void TryParse() [InlineData("mH", ElectricInductanceUnit.Millihenry)] [InlineData("nH", ElectricInductanceUnit.Nanohenry)] [InlineData("pH", ElectricInductanceUnit.Picohenry)] - public void ParseUnit(string abbreviation, ElectricInductanceUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricInductanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricInductanceUnit parsedUnit = ElectricInductance.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricInductanceUnit parsedUnit = ElectricInductance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("H", ElectricInductanceUnit.Henry)] + [InlineData("µH", ElectricInductanceUnit.Microhenry)] + [InlineData("mH", ElectricInductanceUnit.Millihenry)] + [InlineData("nH", ElectricInductanceUnit.Nanohenry)] + [InlineData("pH", ElectricInductanceUnit.Picohenry)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricInductanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricInductanceUnit parsedUnit = ElectricInductance.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -311,7 +327,20 @@ public void ParseUnit(string abbreviation, ElectricInductanceUnit expectedUnit) [InlineData("en-US", "mH", ElectricInductanceUnit.Millihenry)] [InlineData("en-US", "nH", ElectricInductanceUnit.Nanohenry)] [InlineData("en-US", "pH", ElectricInductanceUnit.Picohenry)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricInductanceUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricInductanceUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricInductanceUnit parsedUnit = ElectricInductance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "H", ElectricInductanceUnit.Henry)] + [InlineData("en-US", "µH", ElectricInductanceUnit.Microhenry)] + [InlineData("en-US", "mH", ElectricInductanceUnit.Millihenry)] + [InlineData("en-US", "nH", ElectricInductanceUnit.Nanohenry)] + [InlineData("en-US", "pH", ElectricInductanceUnit.Picohenry)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricInductanceUnit expectedUnit) { ElectricInductanceUnit parsedUnit = ElectricInductance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -323,9 +352,37 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricIn [InlineData("mH", ElectricInductanceUnit.Millihenry)] [InlineData("nH", ElectricInductanceUnit.Nanohenry)] [InlineData("pH", ElectricInductanceUnit.Picohenry)] - public void TryParseUnit(string abbreviation, ElectricInductanceUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricInductanceUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricInductance.TryParseUnit(abbreviation, out ElectricInductanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("H", ElectricInductanceUnit.Henry)] + [InlineData("µH", ElectricInductanceUnit.Microhenry)] + [InlineData("mH", ElectricInductanceUnit.Millihenry)] + [InlineData("nH", ElectricInductanceUnit.Nanohenry)] + [InlineData("pH", ElectricInductanceUnit.Picohenry)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricInductanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricInductance.TryParseUnit(abbreviation, out ElectricInductanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "H", ElectricInductanceUnit.Henry)] + [InlineData("en-US", "µH", ElectricInductanceUnit.Microhenry)] + [InlineData("en-US", "mH", ElectricInductanceUnit.Millihenry)] + [InlineData("en-US", "nH", ElectricInductanceUnit.Nanohenry)] + [InlineData("en-US", "pH", ElectricInductanceUnit.Picohenry)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricInductanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricInductance.TryParseUnit(abbreviation, out ElectricInductanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -336,7 +393,7 @@ public void TryParseUnit(string abbreviation, ElectricInductanceUnit expectedUni [InlineData("en-US", "mH", ElectricInductanceUnit.Millihenry)] [InlineData("en-US", "nH", ElectricInductanceUnit.Nanohenry)] [InlineData("en-US", "pH", ElectricInductanceUnit.Picohenry)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricInductanceUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricInductanceUnit expectedUnit) { Assert.True(ElectricInductance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricInductanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs index e9e2f855a0..4a5ca7bab8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialAcTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -286,10 +287,25 @@ public void TryParse() [InlineData("µVac", ElectricPotentialAcUnit.MicrovoltAc)] [InlineData("mVac", ElectricPotentialAcUnit.MillivoltAc)] [InlineData("Vac", ElectricPotentialAcUnit.VoltAc)] - public void ParseUnit(string abbreviation, ElectricPotentialAcUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialAcUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricPotentialAcUnit parsedUnit = ElectricPotentialAc.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricPotentialAcUnit parsedUnit = ElectricPotentialAc.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kVac", ElectricPotentialAcUnit.KilovoltAc)] + [InlineData("MVac", ElectricPotentialAcUnit.MegavoltAc)] + [InlineData("µVac", ElectricPotentialAcUnit.MicrovoltAc)] + [InlineData("mVac", ElectricPotentialAcUnit.MillivoltAc)] + [InlineData("Vac", ElectricPotentialAcUnit.VoltAc)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialAcUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricPotentialAcUnit parsedUnit = ElectricPotentialAc.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -299,7 +315,20 @@ public void ParseUnit(string abbreviation, ElectricPotentialAcUnit expectedUnit) [InlineData("en-US", "µVac", ElectricPotentialAcUnit.MicrovoltAc)] [InlineData("en-US", "mVac", ElectricPotentialAcUnit.MillivoltAc)] [InlineData("en-US", "Vac", ElectricPotentialAcUnit.VoltAc)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricPotentialAcUnit parsedUnit = ElectricPotentialAc.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kVac", ElectricPotentialAcUnit.KilovoltAc)] + [InlineData("en-US", "MVac", ElectricPotentialAcUnit.MegavoltAc)] + [InlineData("en-US", "µVac", ElectricPotentialAcUnit.MicrovoltAc)] + [InlineData("en-US", "mVac", ElectricPotentialAcUnit.MillivoltAc)] + [InlineData("en-US", "Vac", ElectricPotentialAcUnit.VoltAc)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) { ElectricPotentialAcUnit parsedUnit = ElectricPotentialAc.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -311,9 +340,37 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPo [InlineData("µVac", ElectricPotentialAcUnit.MicrovoltAc)] [InlineData("mVac", ElectricPotentialAcUnit.MillivoltAc)] [InlineData("Vac", ElectricPotentialAcUnit.VoltAc)] - public void TryParseUnit(string abbreviation, ElectricPotentialAcUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialAcUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricPotentialAc.TryParseUnit(abbreviation, out ElectricPotentialAcUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kVac", ElectricPotentialAcUnit.KilovoltAc)] + [InlineData("MVac", ElectricPotentialAcUnit.MegavoltAc)] + [InlineData("µVac", ElectricPotentialAcUnit.MicrovoltAc)] + [InlineData("mVac", ElectricPotentialAcUnit.MillivoltAc)] + [InlineData("Vac", ElectricPotentialAcUnit.VoltAc)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialAcUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricPotentialAc.TryParseUnit(abbreviation, out ElectricPotentialAcUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kVac", ElectricPotentialAcUnit.KilovoltAc)] + [InlineData("en-US", "MVac", ElectricPotentialAcUnit.MegavoltAc)] + [InlineData("en-US", "µVac", ElectricPotentialAcUnit.MicrovoltAc)] + [InlineData("en-US", "mVac", ElectricPotentialAcUnit.MillivoltAc)] + [InlineData("en-US", "Vac", ElectricPotentialAcUnit.VoltAc)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricPotentialAc.TryParseUnit(abbreviation, out ElectricPotentialAcUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -324,7 +381,7 @@ public void TryParseUnit(string abbreviation, ElectricPotentialAcUnit expectedUn [InlineData("en-US", "µVac", ElectricPotentialAcUnit.MicrovoltAc)] [InlineData("en-US", "mVac", ElectricPotentialAcUnit.MillivoltAc)] [InlineData("en-US", "Vac", ElectricPotentialAcUnit.VoltAc)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialAcUnit expectedUnit) { Assert.True(ElectricPotentialAc.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricPotentialAcUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs index 7a6e7c27b5..d729cdb81c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialChangeRateTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -610,10 +611,40 @@ public void TryParse() [InlineData("V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] [InlineData("V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] [InlineData("V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] - public void ParseUnit(string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricPotentialChangeRateUnit parsedUnit = ElectricPotentialChangeRate.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricPotentialChangeRateUnit parsedUnit = ElectricPotentialChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kV/h", ElectricPotentialChangeRateUnit.KilovoltPerHour)] + [InlineData("kV/μs", ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond)] + [InlineData("kV/min", ElectricPotentialChangeRateUnit.KilovoltPerMinute)] + [InlineData("kV/s", ElectricPotentialChangeRateUnit.KilovoltPerSecond)] + [InlineData("MV/h", ElectricPotentialChangeRateUnit.MegavoltPerHour)] + [InlineData("MV/μs", ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond)] + [InlineData("MV/min", ElectricPotentialChangeRateUnit.MegavoltPerMinute)] + [InlineData("MV/s", ElectricPotentialChangeRateUnit.MegavoltPerSecond)] + [InlineData("µV/h", ElectricPotentialChangeRateUnit.MicrovoltPerHour)] + [InlineData("µV/μs", ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond)] + [InlineData("µV/min", ElectricPotentialChangeRateUnit.MicrovoltPerMinute)] + [InlineData("µV/s", ElectricPotentialChangeRateUnit.MicrovoltPerSecond)] + [InlineData("mV/h", ElectricPotentialChangeRateUnit.MillivoltPerHour)] + [InlineData("mV/μs", ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond)] + [InlineData("mV/min", ElectricPotentialChangeRateUnit.MillivoltPerMinute)] + [InlineData("mV/s", ElectricPotentialChangeRateUnit.MillivoltPerSecond)] + [InlineData("V/h", ElectricPotentialChangeRateUnit.VoltPerHour)] + [InlineData("V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] + [InlineData("V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] + [InlineData("V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricPotentialChangeRateUnit parsedUnit = ElectricPotentialChangeRate.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -638,7 +669,35 @@ public void ParseUnit(string abbreviation, ElectricPotentialChangeRateUnit expec [InlineData("en-US", "V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] [InlineData("en-US", "V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] [InlineData("en-US", "V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricPotentialChangeRateUnit parsedUnit = ElectricPotentialChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kV/h", ElectricPotentialChangeRateUnit.KilovoltPerHour)] + [InlineData("en-US", "kV/μs", ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond)] + [InlineData("en-US", "kV/min", ElectricPotentialChangeRateUnit.KilovoltPerMinute)] + [InlineData("en-US", "kV/s", ElectricPotentialChangeRateUnit.KilovoltPerSecond)] + [InlineData("en-US", "MV/h", ElectricPotentialChangeRateUnit.MegavoltPerHour)] + [InlineData("en-US", "MV/μs", ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond)] + [InlineData("en-US", "MV/min", ElectricPotentialChangeRateUnit.MegavoltPerMinute)] + [InlineData("en-US", "MV/s", ElectricPotentialChangeRateUnit.MegavoltPerSecond)] + [InlineData("en-US", "µV/h", ElectricPotentialChangeRateUnit.MicrovoltPerHour)] + [InlineData("en-US", "µV/μs", ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond)] + [InlineData("en-US", "µV/min", ElectricPotentialChangeRateUnit.MicrovoltPerMinute)] + [InlineData("en-US", "µV/s", ElectricPotentialChangeRateUnit.MicrovoltPerSecond)] + [InlineData("en-US", "mV/h", ElectricPotentialChangeRateUnit.MillivoltPerHour)] + [InlineData("en-US", "mV/μs", ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond)] + [InlineData("en-US", "mV/min", ElectricPotentialChangeRateUnit.MillivoltPerMinute)] + [InlineData("en-US", "mV/s", ElectricPotentialChangeRateUnit.MillivoltPerSecond)] + [InlineData("en-US", "V/h", ElectricPotentialChangeRateUnit.VoltPerHour)] + [InlineData("en-US", "V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] + [InlineData("en-US", "V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] + [InlineData("en-US", "V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) { ElectricPotentialChangeRateUnit parsedUnit = ElectricPotentialChangeRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -665,9 +724,67 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPo [InlineData("V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] [InlineData("V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] [InlineData("V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] - public void TryParseUnit(string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricPotentialChangeRate.TryParseUnit(abbreviation, out ElectricPotentialChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kV/h", ElectricPotentialChangeRateUnit.KilovoltPerHour)] + [InlineData("kV/μs", ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond)] + [InlineData("kV/min", ElectricPotentialChangeRateUnit.KilovoltPerMinute)] + [InlineData("kV/s", ElectricPotentialChangeRateUnit.KilovoltPerSecond)] + [InlineData("MV/h", ElectricPotentialChangeRateUnit.MegavoltPerHour)] + [InlineData("MV/μs", ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond)] + [InlineData("MV/min", ElectricPotentialChangeRateUnit.MegavoltPerMinute)] + [InlineData("MV/s", ElectricPotentialChangeRateUnit.MegavoltPerSecond)] + [InlineData("µV/h", ElectricPotentialChangeRateUnit.MicrovoltPerHour)] + [InlineData("µV/μs", ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond)] + [InlineData("µV/min", ElectricPotentialChangeRateUnit.MicrovoltPerMinute)] + [InlineData("µV/s", ElectricPotentialChangeRateUnit.MicrovoltPerSecond)] + [InlineData("mV/h", ElectricPotentialChangeRateUnit.MillivoltPerHour)] + [InlineData("mV/μs", ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond)] + [InlineData("mV/min", ElectricPotentialChangeRateUnit.MillivoltPerMinute)] + [InlineData("mV/s", ElectricPotentialChangeRateUnit.MillivoltPerSecond)] + [InlineData("V/h", ElectricPotentialChangeRateUnit.VoltPerHour)] + [InlineData("V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] + [InlineData("V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] + [InlineData("V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricPotentialChangeRate.TryParseUnit(abbreviation, out ElectricPotentialChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kV/h", ElectricPotentialChangeRateUnit.KilovoltPerHour)] + [InlineData("en-US", "kV/μs", ElectricPotentialChangeRateUnit.KilovoltPerMicrosecond)] + [InlineData("en-US", "kV/min", ElectricPotentialChangeRateUnit.KilovoltPerMinute)] + [InlineData("en-US", "kV/s", ElectricPotentialChangeRateUnit.KilovoltPerSecond)] + [InlineData("en-US", "MV/h", ElectricPotentialChangeRateUnit.MegavoltPerHour)] + [InlineData("en-US", "MV/μs", ElectricPotentialChangeRateUnit.MegavoltPerMicrosecond)] + [InlineData("en-US", "MV/min", ElectricPotentialChangeRateUnit.MegavoltPerMinute)] + [InlineData("en-US", "MV/s", ElectricPotentialChangeRateUnit.MegavoltPerSecond)] + [InlineData("en-US", "µV/h", ElectricPotentialChangeRateUnit.MicrovoltPerHour)] + [InlineData("en-US", "µV/μs", ElectricPotentialChangeRateUnit.MicrovoltPerMicrosecond)] + [InlineData("en-US", "µV/min", ElectricPotentialChangeRateUnit.MicrovoltPerMinute)] + [InlineData("en-US", "µV/s", ElectricPotentialChangeRateUnit.MicrovoltPerSecond)] + [InlineData("en-US", "mV/h", ElectricPotentialChangeRateUnit.MillivoltPerHour)] + [InlineData("en-US", "mV/μs", ElectricPotentialChangeRateUnit.MillivoltPerMicrosecond)] + [InlineData("en-US", "mV/min", ElectricPotentialChangeRateUnit.MillivoltPerMinute)] + [InlineData("en-US", "mV/s", ElectricPotentialChangeRateUnit.MillivoltPerSecond)] + [InlineData("en-US", "V/h", ElectricPotentialChangeRateUnit.VoltPerHour)] + [InlineData("en-US", "V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] + [InlineData("en-US", "V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] + [InlineData("en-US", "V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricPotentialChangeRate.TryParseUnit(abbreviation, out ElectricPotentialChangeRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -693,7 +810,7 @@ public void TryParseUnit(string abbreviation, ElectricPotentialChangeRateUnit ex [InlineData("en-US", "V/μs", ElectricPotentialChangeRateUnit.VoltPerMicrosecond)] [InlineData("en-US", "V/min", ElectricPotentialChangeRateUnit.VoltPerMinute)] [InlineData("en-US", "V/s", ElectricPotentialChangeRateUnit.VoltPerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialChangeRateUnit expectedUnit) { Assert.True(ElectricPotentialChangeRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricPotentialChangeRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs index 4095b47e21..3c9f9800ba 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialDcTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -286,10 +287,25 @@ public void TryParse() [InlineData("µVdc", ElectricPotentialDcUnit.MicrovoltDc)] [InlineData("mVdc", ElectricPotentialDcUnit.MillivoltDc)] [InlineData("Vdc", ElectricPotentialDcUnit.VoltDc)] - public void ParseUnit(string abbreviation, ElectricPotentialDcUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialDcUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricPotentialDcUnit parsedUnit = ElectricPotentialDc.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricPotentialDcUnit parsedUnit = ElectricPotentialDc.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kVdc", ElectricPotentialDcUnit.KilovoltDc)] + [InlineData("MVdc", ElectricPotentialDcUnit.MegavoltDc)] + [InlineData("µVdc", ElectricPotentialDcUnit.MicrovoltDc)] + [InlineData("mVdc", ElectricPotentialDcUnit.MillivoltDc)] + [InlineData("Vdc", ElectricPotentialDcUnit.VoltDc)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialDcUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricPotentialDcUnit parsedUnit = ElectricPotentialDc.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -299,7 +315,20 @@ public void ParseUnit(string abbreviation, ElectricPotentialDcUnit expectedUnit) [InlineData("en-US", "µVdc", ElectricPotentialDcUnit.MicrovoltDc)] [InlineData("en-US", "mVdc", ElectricPotentialDcUnit.MillivoltDc)] [InlineData("en-US", "Vdc", ElectricPotentialDcUnit.VoltDc)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricPotentialDcUnit parsedUnit = ElectricPotentialDc.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kVdc", ElectricPotentialDcUnit.KilovoltDc)] + [InlineData("en-US", "MVdc", ElectricPotentialDcUnit.MegavoltDc)] + [InlineData("en-US", "µVdc", ElectricPotentialDcUnit.MicrovoltDc)] + [InlineData("en-US", "mVdc", ElectricPotentialDcUnit.MillivoltDc)] + [InlineData("en-US", "Vdc", ElectricPotentialDcUnit.VoltDc)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) { ElectricPotentialDcUnit parsedUnit = ElectricPotentialDc.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -311,9 +340,37 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPo [InlineData("µVdc", ElectricPotentialDcUnit.MicrovoltDc)] [InlineData("mVdc", ElectricPotentialDcUnit.MillivoltDc)] [InlineData("Vdc", ElectricPotentialDcUnit.VoltDc)] - public void TryParseUnit(string abbreviation, ElectricPotentialDcUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialDcUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricPotentialDc.TryParseUnit(abbreviation, out ElectricPotentialDcUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kVdc", ElectricPotentialDcUnit.KilovoltDc)] + [InlineData("MVdc", ElectricPotentialDcUnit.MegavoltDc)] + [InlineData("µVdc", ElectricPotentialDcUnit.MicrovoltDc)] + [InlineData("mVdc", ElectricPotentialDcUnit.MillivoltDc)] + [InlineData("Vdc", ElectricPotentialDcUnit.VoltDc)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialDcUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricPotentialDc.TryParseUnit(abbreviation, out ElectricPotentialDcUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kVdc", ElectricPotentialDcUnit.KilovoltDc)] + [InlineData("en-US", "MVdc", ElectricPotentialDcUnit.MegavoltDc)] + [InlineData("en-US", "µVdc", ElectricPotentialDcUnit.MicrovoltDc)] + [InlineData("en-US", "mVdc", ElectricPotentialDcUnit.MillivoltDc)] + [InlineData("en-US", "Vdc", ElectricPotentialDcUnit.VoltDc)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricPotentialDc.TryParseUnit(abbreviation, out ElectricPotentialDcUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -324,7 +381,7 @@ public void TryParseUnit(string abbreviation, ElectricPotentialDcUnit expectedUn [InlineData("en-US", "µVdc", ElectricPotentialDcUnit.MicrovoltDc)] [InlineData("en-US", "mVdc", ElectricPotentialDcUnit.MillivoltDc)] [InlineData("en-US", "Vdc", ElectricPotentialDcUnit.VoltDc)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialDcUnit expectedUnit) { Assert.True(ElectricPotentialDc.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricPotentialDcUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs index fc80b707d9..0849327756 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricPotentialTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -376,10 +377,26 @@ public void TryParse() [InlineData("mV", ElectricPotentialUnit.Millivolt)] [InlineData("nV", ElectricPotentialUnit.Nanovolt)] [InlineData("V", ElectricPotentialUnit.Volt)] - public void ParseUnit(string abbreviation, ElectricPotentialUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricPotentialUnit parsedUnit = ElectricPotential.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricPotentialUnit parsedUnit = ElectricPotential.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kV", ElectricPotentialUnit.Kilovolt)] + [InlineData("MV", ElectricPotentialUnit.Megavolt)] + [InlineData("µV", ElectricPotentialUnit.Microvolt)] + [InlineData("mV", ElectricPotentialUnit.Millivolt)] + [InlineData("nV", ElectricPotentialUnit.Nanovolt)] + [InlineData("V", ElectricPotentialUnit.Volt)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricPotentialUnit parsedUnit = ElectricPotential.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -396,7 +413,27 @@ public void ParseUnit(string abbreviation, ElectricPotentialUnit expectedUnit) [InlineData("ru-RU", "мВ", ElectricPotentialUnit.Millivolt)] [InlineData("ru-RU", "нВ", ElectricPotentialUnit.Nanovolt)] [InlineData("ru-RU", "В", ElectricPotentialUnit.Volt)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricPotentialUnit parsedUnit = ElectricPotential.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kV", ElectricPotentialUnit.Kilovolt)] + [InlineData("en-US", "MV", ElectricPotentialUnit.Megavolt)] + [InlineData("en-US", "µV", ElectricPotentialUnit.Microvolt)] + [InlineData("en-US", "mV", ElectricPotentialUnit.Millivolt)] + [InlineData("en-US", "nV", ElectricPotentialUnit.Nanovolt)] + [InlineData("en-US", "V", ElectricPotentialUnit.Volt)] + [InlineData("ru-RU", "кВ", ElectricPotentialUnit.Kilovolt)] + [InlineData("ru-RU", "МВ", ElectricPotentialUnit.Megavolt)] + [InlineData("ru-RU", "мкВ", ElectricPotentialUnit.Microvolt)] + [InlineData("ru-RU", "мВ", ElectricPotentialUnit.Millivolt)] + [InlineData("ru-RU", "нВ", ElectricPotentialUnit.Nanovolt)] + [InlineData("ru-RU", "В", ElectricPotentialUnit.Volt)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialUnit expectedUnit) { ElectricPotentialUnit parsedUnit = ElectricPotential.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -409,9 +446,45 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricPo [InlineData("mV", ElectricPotentialUnit.Millivolt)] [InlineData("nV", ElectricPotentialUnit.Nanovolt)] [InlineData("V", ElectricPotentialUnit.Volt)] - public void TryParseUnit(string abbreviation, ElectricPotentialUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricPotentialUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricPotential.TryParseUnit(abbreviation, out ElectricPotentialUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kV", ElectricPotentialUnit.Kilovolt)] + [InlineData("MV", ElectricPotentialUnit.Megavolt)] + [InlineData("µV", ElectricPotentialUnit.Microvolt)] + [InlineData("mV", ElectricPotentialUnit.Millivolt)] + [InlineData("nV", ElectricPotentialUnit.Nanovolt)] + [InlineData("V", ElectricPotentialUnit.Volt)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricPotentialUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricPotential.TryParseUnit(abbreviation, out ElectricPotentialUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kV", ElectricPotentialUnit.Kilovolt)] + [InlineData("en-US", "MV", ElectricPotentialUnit.Megavolt)] + [InlineData("en-US", "µV", ElectricPotentialUnit.Microvolt)] + [InlineData("en-US", "mV", ElectricPotentialUnit.Millivolt)] + [InlineData("en-US", "nV", ElectricPotentialUnit.Nanovolt)] + [InlineData("en-US", "V", ElectricPotentialUnit.Volt)] + [InlineData("ru-RU", "кВ", ElectricPotentialUnit.Kilovolt)] + [InlineData("ru-RU", "МВ", ElectricPotentialUnit.Megavolt)] + [InlineData("ru-RU", "мкВ", ElectricPotentialUnit.Microvolt)] + [InlineData("ru-RU", "мВ", ElectricPotentialUnit.Millivolt)] + [InlineData("ru-RU", "нВ", ElectricPotentialUnit.Nanovolt)] + [InlineData("ru-RU", "В", ElectricPotentialUnit.Volt)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricPotentialUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricPotential.TryParseUnit(abbreviation, out ElectricPotentialUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -429,7 +502,7 @@ public void TryParseUnit(string abbreviation, ElectricPotentialUnit expectedUnit [InlineData("ru-RU", "мВ", ElectricPotentialUnit.Millivolt)] [InlineData("ru-RU", "нВ", ElectricPotentialUnit.Nanovolt)] [InlineData("ru-RU", "В", ElectricPotentialUnit.Volt)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricPotentialUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricPotentialUnit expectedUnit) { Assert.True(ElectricPotential.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricPotentialUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs index 2604e0d10e..8448e8feaf 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistanceTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -334,10 +335,27 @@ public void TryParse() [InlineData("mΩ", ElectricResistanceUnit.Milliohm)] [InlineData("Ω", ElectricResistanceUnit.Ohm)] [InlineData("TΩ", ElectricResistanceUnit.Teraohm)] - public void ParseUnit(string abbreviation, ElectricResistanceUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricResistanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricResistanceUnit parsedUnit = ElectricResistance.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricResistanceUnit parsedUnit = ElectricResistance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("GΩ", ElectricResistanceUnit.Gigaohm)] + [InlineData("kΩ", ElectricResistanceUnit.Kiloohm)] + [InlineData("MΩ", ElectricResistanceUnit.Megaohm)] + [InlineData("µΩ", ElectricResistanceUnit.Microohm)] + [InlineData("mΩ", ElectricResistanceUnit.Milliohm)] + [InlineData("Ω", ElectricResistanceUnit.Ohm)] + [InlineData("TΩ", ElectricResistanceUnit.Teraohm)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricResistanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricResistanceUnit parsedUnit = ElectricResistance.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -349,7 +367,22 @@ public void ParseUnit(string abbreviation, ElectricResistanceUnit expectedUnit) [InlineData("en-US", "mΩ", ElectricResistanceUnit.Milliohm)] [InlineData("en-US", "Ω", ElectricResistanceUnit.Ohm)] [InlineData("en-US", "TΩ", ElectricResistanceUnit.Teraohm)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricResistanceUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricResistanceUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricResistanceUnit parsedUnit = ElectricResistance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "GΩ", ElectricResistanceUnit.Gigaohm)] + [InlineData("en-US", "kΩ", ElectricResistanceUnit.Kiloohm)] + [InlineData("en-US", "MΩ", ElectricResistanceUnit.Megaohm)] + [InlineData("en-US", "µΩ", ElectricResistanceUnit.Microohm)] + [InlineData("en-US", "mΩ", ElectricResistanceUnit.Milliohm)] + [InlineData("en-US", "Ω", ElectricResistanceUnit.Ohm)] + [InlineData("en-US", "TΩ", ElectricResistanceUnit.Teraohm)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricResistanceUnit expectedUnit) { ElectricResistanceUnit parsedUnit = ElectricResistance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -363,9 +396,41 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricRe [InlineData("mΩ", ElectricResistanceUnit.Milliohm)] [InlineData("Ω", ElectricResistanceUnit.Ohm)] [InlineData("TΩ", ElectricResistanceUnit.Teraohm)] - public void TryParseUnit(string abbreviation, ElectricResistanceUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricResistanceUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricResistance.TryParseUnit(abbreviation, out ElectricResistanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("GΩ", ElectricResistanceUnit.Gigaohm)] + [InlineData("kΩ", ElectricResistanceUnit.Kiloohm)] + [InlineData("MΩ", ElectricResistanceUnit.Megaohm)] + [InlineData("µΩ", ElectricResistanceUnit.Microohm)] + [InlineData("mΩ", ElectricResistanceUnit.Milliohm)] + [InlineData("Ω", ElectricResistanceUnit.Ohm)] + [InlineData("TΩ", ElectricResistanceUnit.Teraohm)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricResistanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricResistance.TryParseUnit(abbreviation, out ElectricResistanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "GΩ", ElectricResistanceUnit.Gigaohm)] + [InlineData("en-US", "kΩ", ElectricResistanceUnit.Kiloohm)] + [InlineData("en-US", "MΩ", ElectricResistanceUnit.Megaohm)] + [InlineData("en-US", "µΩ", ElectricResistanceUnit.Microohm)] + [InlineData("en-US", "mΩ", ElectricResistanceUnit.Milliohm)] + [InlineData("en-US", "Ω", ElectricResistanceUnit.Ohm)] + [InlineData("en-US", "TΩ", ElectricResistanceUnit.Teraohm)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricResistanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricResistance.TryParseUnit(abbreviation, out ElectricResistanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -378,7 +443,7 @@ public void TryParseUnit(string abbreviation, ElectricResistanceUnit expectedUni [InlineData("en-US", "mΩ", ElectricResistanceUnit.Milliohm)] [InlineData("en-US", "Ω", ElectricResistanceUnit.Ohm)] [InlineData("en-US", "TΩ", ElectricResistanceUnit.Teraohm)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricResistanceUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricResistanceUnit expectedUnit) { Assert.True(ElectricResistance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricResistanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs index 1e5d211855..068db42a1e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricResistivityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -490,10 +491,34 @@ public void TryParse() [InlineData("Ω·m", ElectricResistivityUnit.OhmMeter)] [InlineData("pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] [InlineData("pΩ·m", ElectricResistivityUnit.PicoohmMeter)] - public void ParseUnit(string abbreviation, ElectricResistivityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricResistivityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricResistivityUnit parsedUnit = ElectricResistivity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricResistivityUnit parsedUnit = ElectricResistivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kΩ·cm", ElectricResistivityUnit.KiloohmCentimeter)] + [InlineData("kΩ·m", ElectricResistivityUnit.KiloohmMeter)] + [InlineData("MΩ·cm", ElectricResistivityUnit.MegaohmCentimeter)] + [InlineData("MΩ·m", ElectricResistivityUnit.MegaohmMeter)] + [InlineData("µΩ·cm", ElectricResistivityUnit.MicroohmCentimeter)] + [InlineData("µΩ·m", ElectricResistivityUnit.MicroohmMeter)] + [InlineData("mΩ·cm", ElectricResistivityUnit.MilliohmCentimeter)] + [InlineData("mΩ·m", ElectricResistivityUnit.MilliohmMeter)] + [InlineData("nΩ·cm", ElectricResistivityUnit.NanoohmCentimeter)] + [InlineData("nΩ·m", ElectricResistivityUnit.NanoohmMeter)] + [InlineData("Ω·cm", ElectricResistivityUnit.OhmCentimeter)] + [InlineData("Ω·m", ElectricResistivityUnit.OhmMeter)] + [InlineData("pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] + [InlineData("pΩ·m", ElectricResistivityUnit.PicoohmMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricResistivityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricResistivityUnit parsedUnit = ElectricResistivity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -512,7 +537,29 @@ public void ParseUnit(string abbreviation, ElectricResistivityUnit expectedUnit) [InlineData("en-US", "Ω·m", ElectricResistivityUnit.OhmMeter)] [InlineData("en-US", "pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] [InlineData("en-US", "pΩ·m", ElectricResistivityUnit.PicoohmMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricResistivityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricResistivityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricResistivityUnit parsedUnit = ElectricResistivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kΩ·cm", ElectricResistivityUnit.KiloohmCentimeter)] + [InlineData("en-US", "kΩ·m", ElectricResistivityUnit.KiloohmMeter)] + [InlineData("en-US", "MΩ·cm", ElectricResistivityUnit.MegaohmCentimeter)] + [InlineData("en-US", "MΩ·m", ElectricResistivityUnit.MegaohmMeter)] + [InlineData("en-US", "µΩ·cm", ElectricResistivityUnit.MicroohmCentimeter)] + [InlineData("en-US", "µΩ·m", ElectricResistivityUnit.MicroohmMeter)] + [InlineData("en-US", "mΩ·cm", ElectricResistivityUnit.MilliohmCentimeter)] + [InlineData("en-US", "mΩ·m", ElectricResistivityUnit.MilliohmMeter)] + [InlineData("en-US", "nΩ·cm", ElectricResistivityUnit.NanoohmCentimeter)] + [InlineData("en-US", "nΩ·m", ElectricResistivityUnit.NanoohmMeter)] + [InlineData("en-US", "Ω·cm", ElectricResistivityUnit.OhmCentimeter)] + [InlineData("en-US", "Ω·m", ElectricResistivityUnit.OhmMeter)] + [InlineData("en-US", "pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] + [InlineData("en-US", "pΩ·m", ElectricResistivityUnit.PicoohmMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricResistivityUnit expectedUnit) { ElectricResistivityUnit parsedUnit = ElectricResistivity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -533,9 +580,55 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricRe [InlineData("Ω·m", ElectricResistivityUnit.OhmMeter)] [InlineData("pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] [InlineData("pΩ·m", ElectricResistivityUnit.PicoohmMeter)] - public void TryParseUnit(string abbreviation, ElectricResistivityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricResistivityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricResistivity.TryParseUnit(abbreviation, out ElectricResistivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kΩ·cm", ElectricResistivityUnit.KiloohmCentimeter)] + [InlineData("kΩ·m", ElectricResistivityUnit.KiloohmMeter)] + [InlineData("MΩ·cm", ElectricResistivityUnit.MegaohmCentimeter)] + [InlineData("MΩ·m", ElectricResistivityUnit.MegaohmMeter)] + [InlineData("µΩ·cm", ElectricResistivityUnit.MicroohmCentimeter)] + [InlineData("µΩ·m", ElectricResistivityUnit.MicroohmMeter)] + [InlineData("mΩ·cm", ElectricResistivityUnit.MilliohmCentimeter)] + [InlineData("mΩ·m", ElectricResistivityUnit.MilliohmMeter)] + [InlineData("nΩ·cm", ElectricResistivityUnit.NanoohmCentimeter)] + [InlineData("nΩ·m", ElectricResistivityUnit.NanoohmMeter)] + [InlineData("Ω·cm", ElectricResistivityUnit.OhmCentimeter)] + [InlineData("Ω·m", ElectricResistivityUnit.OhmMeter)] + [InlineData("pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] + [InlineData("pΩ·m", ElectricResistivityUnit.PicoohmMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricResistivityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricResistivity.TryParseUnit(abbreviation, out ElectricResistivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kΩ·cm", ElectricResistivityUnit.KiloohmCentimeter)] + [InlineData("en-US", "kΩ·m", ElectricResistivityUnit.KiloohmMeter)] + [InlineData("en-US", "MΩ·cm", ElectricResistivityUnit.MegaohmCentimeter)] + [InlineData("en-US", "MΩ·m", ElectricResistivityUnit.MegaohmMeter)] + [InlineData("en-US", "µΩ·cm", ElectricResistivityUnit.MicroohmCentimeter)] + [InlineData("en-US", "µΩ·m", ElectricResistivityUnit.MicroohmMeter)] + [InlineData("en-US", "mΩ·cm", ElectricResistivityUnit.MilliohmCentimeter)] + [InlineData("en-US", "mΩ·m", ElectricResistivityUnit.MilliohmMeter)] + [InlineData("en-US", "nΩ·cm", ElectricResistivityUnit.NanoohmCentimeter)] + [InlineData("en-US", "nΩ·m", ElectricResistivityUnit.NanoohmMeter)] + [InlineData("en-US", "Ω·cm", ElectricResistivityUnit.OhmCentimeter)] + [InlineData("en-US", "Ω·m", ElectricResistivityUnit.OhmMeter)] + [InlineData("en-US", "pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] + [InlineData("en-US", "pΩ·m", ElectricResistivityUnit.PicoohmMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricResistivityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricResistivity.TryParseUnit(abbreviation, out ElectricResistivityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -555,7 +648,7 @@ public void TryParseUnit(string abbreviation, ElectricResistivityUnit expectedUn [InlineData("en-US", "Ω·m", ElectricResistivityUnit.OhmMeter)] [InlineData("en-US", "pΩ·cm", ElectricResistivityUnit.PicoohmCentimeter)] [InlineData("en-US", "pΩ·m", ElectricResistivityUnit.PicoohmMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricResistivityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricResistivityUnit expectedUnit) { Assert.True(ElectricResistivity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricResistivityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs index 9b58daf88c..57cecc25de 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ElectricSurfaceChargeDensityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -250,10 +251,23 @@ public void TryParse() [InlineData("C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] [InlineData("C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] [InlineData("C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] - public void ParseUnit(string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ElectricSurfaceChargeDensityUnit parsedUnit = ElectricSurfaceChargeDensity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ElectricSurfaceChargeDensityUnit parsedUnit = ElectricSurfaceChargeDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] + [InlineData("C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] + [InlineData("C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ElectricSurfaceChargeDensityUnit parsedUnit = ElectricSurfaceChargeDensity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -261,7 +275,18 @@ public void ParseUnit(string abbreviation, ElectricSurfaceChargeDensityUnit expe [InlineData("en-US", "C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] [InlineData("en-US", "C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] [InlineData("en-US", "C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ElectricSurfaceChargeDensityUnit parsedUnit = ElectricSurfaceChargeDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] + [InlineData("en-US", "C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] + [InlineData("en-US", "C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) { ElectricSurfaceChargeDensityUnit parsedUnit = ElectricSurfaceChargeDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -271,9 +296,33 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ElectricSu [InlineData("C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] [InlineData("C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] [InlineData("C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] - public void TryParseUnit(string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ElectricSurfaceChargeDensity.TryParseUnit(abbreviation, out ElectricSurfaceChargeDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] + [InlineData("C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] + [InlineData("C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ElectricSurfaceChargeDensity.TryParseUnit(abbreviation, out ElectricSurfaceChargeDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] + [InlineData("en-US", "C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] + [InlineData("en-US", "C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ElectricSurfaceChargeDensity.TryParseUnit(abbreviation, out ElectricSurfaceChargeDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -282,7 +331,7 @@ public void TryParseUnit(string abbreviation, ElectricSurfaceChargeDensityUnit e [InlineData("en-US", "C/cm²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareCentimeter)] [InlineData("en-US", "C/in²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareInch)] [InlineData("en-US", "C/m²", ElectricSurfaceChargeDensityUnit.CoulombPerSquareMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ElectricSurfaceChargeDensityUnit expectedUnit) { Assert.True(ElectricSurfaceChargeDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ElectricSurfaceChargeDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs index 3c5c8f6b48..eed7ae0b2b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyDensityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -466,10 +467,32 @@ public void TryParse() [InlineData("TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] [InlineData("TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] [InlineData("Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] - public void ParseUnit(string abbreviation, EnergyDensityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, EnergyDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - EnergyDensityUnit parsedUnit = EnergyDensity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + EnergyDensityUnit parsedUnit = EnergyDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("GJ/m³", EnergyDensityUnit.GigajoulePerCubicMeter)] + [InlineData("GWh/m³", EnergyDensityUnit.GigawattHourPerCubicMeter)] + [InlineData("J/m³", EnergyDensityUnit.JoulePerCubicMeter)] + [InlineData("kJ/m³", EnergyDensityUnit.KilojoulePerCubicMeter)] + [InlineData("kWh/m³", EnergyDensityUnit.KilowattHourPerCubicMeter)] + [InlineData("MJ/m³", EnergyDensityUnit.MegajoulePerCubicMeter)] + [InlineData("MWh/m³", EnergyDensityUnit.MegawattHourPerCubicMeter)] + [InlineData("PJ/m³", EnergyDensityUnit.PetajoulePerCubicMeter)] + [InlineData("PWh/m³", EnergyDensityUnit.PetawattHourPerCubicMeter)] + [InlineData("TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] + [InlineData("TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] + [InlineData("Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, EnergyDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + EnergyDensityUnit parsedUnit = EnergyDensity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -486,7 +509,27 @@ public void ParseUnit(string abbreviation, EnergyDensityUnit expectedUnit) [InlineData("en-US", "TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] [InlineData("en-US", "TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] [InlineData("en-US", "Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, EnergyDensityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, EnergyDensityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + EnergyDensityUnit parsedUnit = EnergyDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "GJ/m³", EnergyDensityUnit.GigajoulePerCubicMeter)] + [InlineData("en-US", "GWh/m³", EnergyDensityUnit.GigawattHourPerCubicMeter)] + [InlineData("en-US", "J/m³", EnergyDensityUnit.JoulePerCubicMeter)] + [InlineData("en-US", "kJ/m³", EnergyDensityUnit.KilojoulePerCubicMeter)] + [InlineData("en-US", "kWh/m³", EnergyDensityUnit.KilowattHourPerCubicMeter)] + [InlineData("en-US", "MJ/m³", EnergyDensityUnit.MegajoulePerCubicMeter)] + [InlineData("en-US", "MWh/m³", EnergyDensityUnit.MegawattHourPerCubicMeter)] + [InlineData("en-US", "PJ/m³", EnergyDensityUnit.PetajoulePerCubicMeter)] + [InlineData("en-US", "PWh/m³", EnergyDensityUnit.PetawattHourPerCubicMeter)] + [InlineData("en-US", "TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] + [InlineData("en-US", "TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] + [InlineData("en-US", "Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, EnergyDensityUnit expectedUnit) { EnergyDensityUnit parsedUnit = EnergyDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -505,9 +548,51 @@ public void ParseUnitWithCulture(string culture, string abbreviation, EnergyDens [InlineData("TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] [InlineData("TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] [InlineData("Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] - public void TryParseUnit(string abbreviation, EnergyDensityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, EnergyDensityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(EnergyDensity.TryParseUnit(abbreviation, out EnergyDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("GJ/m³", EnergyDensityUnit.GigajoulePerCubicMeter)] + [InlineData("GWh/m³", EnergyDensityUnit.GigawattHourPerCubicMeter)] + [InlineData("J/m³", EnergyDensityUnit.JoulePerCubicMeter)] + [InlineData("kJ/m³", EnergyDensityUnit.KilojoulePerCubicMeter)] + [InlineData("kWh/m³", EnergyDensityUnit.KilowattHourPerCubicMeter)] + [InlineData("MJ/m³", EnergyDensityUnit.MegajoulePerCubicMeter)] + [InlineData("MWh/m³", EnergyDensityUnit.MegawattHourPerCubicMeter)] + [InlineData("PJ/m³", EnergyDensityUnit.PetajoulePerCubicMeter)] + [InlineData("PWh/m³", EnergyDensityUnit.PetawattHourPerCubicMeter)] + [InlineData("TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] + [InlineData("TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] + [InlineData("Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, EnergyDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(EnergyDensity.TryParseUnit(abbreviation, out EnergyDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "GJ/m³", EnergyDensityUnit.GigajoulePerCubicMeter)] + [InlineData("en-US", "GWh/m³", EnergyDensityUnit.GigawattHourPerCubicMeter)] + [InlineData("en-US", "J/m³", EnergyDensityUnit.JoulePerCubicMeter)] + [InlineData("en-US", "kJ/m³", EnergyDensityUnit.KilojoulePerCubicMeter)] + [InlineData("en-US", "kWh/m³", EnergyDensityUnit.KilowattHourPerCubicMeter)] + [InlineData("en-US", "MJ/m³", EnergyDensityUnit.MegajoulePerCubicMeter)] + [InlineData("en-US", "MWh/m³", EnergyDensityUnit.MegawattHourPerCubicMeter)] + [InlineData("en-US", "PJ/m³", EnergyDensityUnit.PetajoulePerCubicMeter)] + [InlineData("en-US", "PWh/m³", EnergyDensityUnit.PetawattHourPerCubicMeter)] + [InlineData("en-US", "TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] + [InlineData("en-US", "TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] + [InlineData("en-US", "Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, EnergyDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(EnergyDensity.TryParseUnit(abbreviation, out EnergyDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -525,7 +610,7 @@ public void TryParseUnit(string abbreviation, EnergyDensityUnit expectedUnit) [InlineData("en-US", "TJ/m³", EnergyDensityUnit.TerajoulePerCubicMeter)] [InlineData("en-US", "TWh/m³", EnergyDensityUnit.TerawattHourPerCubicMeter)] [InlineData("en-US", "Wh/m³", EnergyDensityUnit.WattHourPerCubicMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, EnergyDensityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, EnergyDensityUnit expectedUnit) { Assert.True(EnergyDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out EnergyDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs index b05ca1f230..63faad4f65 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EnergyTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1399,10 +1400,129 @@ public void TryParse() [InlineData("th (U.S.)", EnergyUnit.ThermUs)] [InlineData("Wd", EnergyUnit.WattDay)] [InlineData("Wh", EnergyUnit.WattHour)] - public void ParseUnit(string abbreviation, EnergyUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, EnergyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - EnergyUnit parsedUnit = Energy.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + EnergyUnit parsedUnit = Energy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("BTU", EnergyUnit.BritishThermalUnit)] + [InlineData("cal", EnergyUnit.Calorie)] + [InlineData("Dth (E.C.)", EnergyUnit.DecathermEc)] + [InlineData("Dth (imp.)", EnergyUnit.DecathermImperial)] + [InlineData("Dth (U.S.)", EnergyUnit.DecathermUs)] + [InlineData("eV", EnergyUnit.ElectronVolt)] + [InlineData("erg", EnergyUnit.Erg)] + [InlineData("ft·lb", EnergyUnit.FootPound)] + [InlineData("GBTU", EnergyUnit.GigabritishThermalUnit)] + [InlineData("GeV", EnergyUnit.GigaelectronVolt)] + [InlineData("GJ", EnergyUnit.Gigajoule)] + [InlineData("GWd", EnergyUnit.GigawattDay)] + [InlineData("GWh", EnergyUnit.GigawattHour)] + [InlineData("hp·h", EnergyUnit.HorsepowerHour)] + [InlineData("J", EnergyUnit.Joule)] + [InlineData("kBTU", EnergyUnit.KilobritishThermalUnit)] + [InlineData("kcal", EnergyUnit.Kilocalorie)] + [InlineData("keV", EnergyUnit.KiloelectronVolt)] + [InlineData("kJ", EnergyUnit.Kilojoule)] + [InlineData("kWd", EnergyUnit.KilowattDay)] + [InlineData("kWh", EnergyUnit.KilowattHour)] + [InlineData("MBTU", EnergyUnit.MegabritishThermalUnit)] + [InlineData("Mcal", EnergyUnit.Megacalorie)] + [InlineData("MeV", EnergyUnit.MegaelectronVolt)] + [InlineData("MJ", EnergyUnit.Megajoule)] + [InlineData("MWd", EnergyUnit.MegawattDay)] + [InlineData("MWh", EnergyUnit.MegawattHour)] + [InlineData("µJ", EnergyUnit.Microjoule)] + [InlineData("mJ", EnergyUnit.Millijoule)] + [InlineData("nJ", EnergyUnit.Nanojoule)] + [InlineData("PJ", EnergyUnit.Petajoule)] + [InlineData("TeV", EnergyUnit.TeraelectronVolt)] + [InlineData("TJ", EnergyUnit.Terajoule)] + [InlineData("TWd", EnergyUnit.TerawattDay)] + [InlineData("TWh", EnergyUnit.TerawattHour)] + [InlineData("th (E.C.)", EnergyUnit.ThermEc)] + [InlineData("th (imp.)", EnergyUnit.ThermImperial)] + [InlineData("th (U.S.)", EnergyUnit.ThermUs)] + [InlineData("Wd", EnergyUnit.WattDay)] + [InlineData("Wh", EnergyUnit.WattHour)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, EnergyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + EnergyUnit parsedUnit = Energy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "BTU", EnergyUnit.BritishThermalUnit)] + [InlineData("en-US", "cal", EnergyUnit.Calorie)] + [InlineData("en-US", "Dth (E.C.)", EnergyUnit.DecathermEc)] + [InlineData("en-US", "Dth (imp.)", EnergyUnit.DecathermImperial)] + [InlineData("en-US", "Dth (U.S.)", EnergyUnit.DecathermUs)] + [InlineData("en-US", "eV", EnergyUnit.ElectronVolt)] + [InlineData("en-US", "erg", EnergyUnit.Erg)] + [InlineData("en-US", "ft·lb", EnergyUnit.FootPound)] + [InlineData("en-US", "GBTU", EnergyUnit.GigabritishThermalUnit)] + [InlineData("en-US", "GeV", EnergyUnit.GigaelectronVolt)] + [InlineData("en-US", "GJ", EnergyUnit.Gigajoule)] + [InlineData("en-US", "GWd", EnergyUnit.GigawattDay)] + [InlineData("en-US", "GWh", EnergyUnit.GigawattHour)] + [InlineData("en-US", "hp·h", EnergyUnit.HorsepowerHour)] + [InlineData("en-US", "J", EnergyUnit.Joule)] + [InlineData("en-US", "kBTU", EnergyUnit.KilobritishThermalUnit)] + [InlineData("en-US", "kcal", EnergyUnit.Kilocalorie)] + [InlineData("en-US", "keV", EnergyUnit.KiloelectronVolt)] + [InlineData("en-US", "kJ", EnergyUnit.Kilojoule)] + [InlineData("en-US", "kWd", EnergyUnit.KilowattDay)] + [InlineData("en-US", "kWh", EnergyUnit.KilowattHour)] + [InlineData("en-US", "MBTU", EnergyUnit.MegabritishThermalUnit)] + [InlineData("en-US", "Mcal", EnergyUnit.Megacalorie)] + [InlineData("en-US", "MeV", EnergyUnit.MegaelectronVolt)] + [InlineData("en-US", "MJ", EnergyUnit.Megajoule)] + [InlineData("en-US", "MWd", EnergyUnit.MegawattDay)] + [InlineData("en-US", "MWh", EnergyUnit.MegawattHour)] + [InlineData("en-US", "µJ", EnergyUnit.Microjoule)] + [InlineData("en-US", "mJ", EnergyUnit.Millijoule)] + [InlineData("en-US", "nJ", EnergyUnit.Nanojoule)] + [InlineData("en-US", "PJ", EnergyUnit.Petajoule)] + [InlineData("en-US", "TeV", EnergyUnit.TeraelectronVolt)] + [InlineData("en-US", "TJ", EnergyUnit.Terajoule)] + [InlineData("en-US", "TWd", EnergyUnit.TerawattDay)] + [InlineData("en-US", "TWh", EnergyUnit.TerawattHour)] + [InlineData("en-US", "th (E.C.)", EnergyUnit.ThermEc)] + [InlineData("en-US", "th (imp.)", EnergyUnit.ThermImperial)] + [InlineData("en-US", "th (U.S.)", EnergyUnit.ThermUs)] + [InlineData("en-US", "Wd", EnergyUnit.WattDay)] + [InlineData("en-US", "Wh", EnergyUnit.WattHour)] + [InlineData("ru-RU", "Европейский декатерм", EnergyUnit.DecathermEc)] + [InlineData("ru-RU", "Английский декатерм", EnergyUnit.DecathermImperial)] + [InlineData("ru-RU", "Американский декатерм", EnergyUnit.DecathermUs)] + [InlineData("ru-RU", "эВ", EnergyUnit.ElectronVolt)] + [InlineData("ru-RU", "ГэВ", EnergyUnit.GigaelectronVolt)] + [InlineData("ru-RU", "ГВт/д", EnergyUnit.GigawattDay)] + [InlineData("ru-RU", "ГВт/ч", EnergyUnit.GigawattHour)] + [InlineData("ru-RU", "кэВ", EnergyUnit.KiloelectronVolt)] + [InlineData("ru-RU", "кВт/д", EnergyUnit.KilowattDay)] + [InlineData("ru-RU", "кВт/ч", EnergyUnit.KilowattHour)] + [InlineData("ru-RU", "МэВ", EnergyUnit.MegaelectronVolt)] + [InlineData("ru-RU", "МВт/д", EnergyUnit.MegawattDay)] + [InlineData("ru-RU", "МВт/ч", EnergyUnit.MegawattHour)] + [InlineData("ru-RU", "ТэВ", EnergyUnit.TeraelectronVolt)] + [InlineData("ru-RU", "ТВт/д", EnergyUnit.TerawattDay)] + [InlineData("ru-RU", "ТВт/ч", EnergyUnit.TerawattHour)] + [InlineData("ru-RU", "Европейский терм", EnergyUnit.ThermEc)] + [InlineData("ru-RU", "Английский терм", EnergyUnit.ThermImperial)] + [InlineData("ru-RU", "Американский терм", EnergyUnit.ThermUs)] + [InlineData("ru-RU", "Вт/д", EnergyUnit.WattDay)] + [InlineData("ru-RU", "Вт/ч", EnergyUnit.WattHour)] + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, EnergyUnit expectedUnit) + { + using var _ = new CultureScope(culture); + EnergyUnit parsedUnit = Energy.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1468,7 +1588,7 @@ public void ParseUnit(string abbreviation, EnergyUnit expectedUnit) [InlineData("ru-RU", "Американский терм", EnergyUnit.ThermUs)] [InlineData("ru-RU", "Вт/д", EnergyUnit.WattDay)] [InlineData("ru-RU", "Вт/ч", EnergyUnit.WattHour)] - public void ParseUnitWithCulture(string culture, string abbreviation, EnergyUnit expectedUnit) + public void ParseUnit_WithCulture(string culture, string abbreviation, EnergyUnit expectedUnit) { EnergyUnit parsedUnit = Energy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1515,9 +1635,128 @@ public void ParseUnitWithCulture(string culture, string abbreviation, EnergyUnit [InlineData("th (U.S.)", EnergyUnit.ThermUs)] [InlineData("Wd", EnergyUnit.WattDay)] [InlineData("Wh", EnergyUnit.WattHour)] - public void TryParseUnit(string abbreviation, EnergyUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, EnergyUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Energy.TryParseUnit(abbreviation, out EnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("BTU", EnergyUnit.BritishThermalUnit)] + [InlineData("cal", EnergyUnit.Calorie)] + [InlineData("Dth (E.C.)", EnergyUnit.DecathermEc)] + [InlineData("Dth (imp.)", EnergyUnit.DecathermImperial)] + [InlineData("Dth (U.S.)", EnergyUnit.DecathermUs)] + [InlineData("eV", EnergyUnit.ElectronVolt)] + [InlineData("erg", EnergyUnit.Erg)] + [InlineData("ft·lb", EnergyUnit.FootPound)] + [InlineData("GBTU", EnergyUnit.GigabritishThermalUnit)] + [InlineData("GeV", EnergyUnit.GigaelectronVolt)] + [InlineData("GJ", EnergyUnit.Gigajoule)] + [InlineData("GWd", EnergyUnit.GigawattDay)] + [InlineData("GWh", EnergyUnit.GigawattHour)] + [InlineData("hp·h", EnergyUnit.HorsepowerHour)] + [InlineData("J", EnergyUnit.Joule)] + [InlineData("kBTU", EnergyUnit.KilobritishThermalUnit)] + [InlineData("kcal", EnergyUnit.Kilocalorie)] + [InlineData("keV", EnergyUnit.KiloelectronVolt)] + [InlineData("kJ", EnergyUnit.Kilojoule)] + [InlineData("kWd", EnergyUnit.KilowattDay)] + [InlineData("kWh", EnergyUnit.KilowattHour)] + [InlineData("MBTU", EnergyUnit.MegabritishThermalUnit)] + [InlineData("Mcal", EnergyUnit.Megacalorie)] + [InlineData("MeV", EnergyUnit.MegaelectronVolt)] + [InlineData("MJ", EnergyUnit.Megajoule)] + [InlineData("MWd", EnergyUnit.MegawattDay)] + [InlineData("MWh", EnergyUnit.MegawattHour)] + [InlineData("µJ", EnergyUnit.Microjoule)] + [InlineData("mJ", EnergyUnit.Millijoule)] + [InlineData("nJ", EnergyUnit.Nanojoule)] + [InlineData("PJ", EnergyUnit.Petajoule)] + [InlineData("TeV", EnergyUnit.TeraelectronVolt)] + [InlineData("TJ", EnergyUnit.Terajoule)] + [InlineData("TWd", EnergyUnit.TerawattDay)] + [InlineData("TWh", EnergyUnit.TerawattHour)] + [InlineData("th (E.C.)", EnergyUnit.ThermEc)] + [InlineData("th (imp.)", EnergyUnit.ThermImperial)] + [InlineData("th (U.S.)", EnergyUnit.ThermUs)] + [InlineData("Wd", EnergyUnit.WattDay)] + [InlineData("Wh", EnergyUnit.WattHour)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, EnergyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Energy.TryParseUnit(abbreviation, out EnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "BTU", EnergyUnit.BritishThermalUnit)] + [InlineData("en-US", "cal", EnergyUnit.Calorie)] + [InlineData("en-US", "Dth (E.C.)", EnergyUnit.DecathermEc)] + [InlineData("en-US", "Dth (imp.)", EnergyUnit.DecathermImperial)] + [InlineData("en-US", "Dth (U.S.)", EnergyUnit.DecathermUs)] + [InlineData("en-US", "eV", EnergyUnit.ElectronVolt)] + [InlineData("en-US", "erg", EnergyUnit.Erg)] + [InlineData("en-US", "ft·lb", EnergyUnit.FootPound)] + [InlineData("en-US", "GBTU", EnergyUnit.GigabritishThermalUnit)] + [InlineData("en-US", "GeV", EnergyUnit.GigaelectronVolt)] + [InlineData("en-US", "GJ", EnergyUnit.Gigajoule)] + [InlineData("en-US", "GWd", EnergyUnit.GigawattDay)] + [InlineData("en-US", "GWh", EnergyUnit.GigawattHour)] + [InlineData("en-US", "hp·h", EnergyUnit.HorsepowerHour)] + [InlineData("en-US", "J", EnergyUnit.Joule)] + [InlineData("en-US", "kBTU", EnergyUnit.KilobritishThermalUnit)] + [InlineData("en-US", "kcal", EnergyUnit.Kilocalorie)] + [InlineData("en-US", "keV", EnergyUnit.KiloelectronVolt)] + [InlineData("en-US", "kJ", EnergyUnit.Kilojoule)] + [InlineData("en-US", "kWd", EnergyUnit.KilowattDay)] + [InlineData("en-US", "kWh", EnergyUnit.KilowattHour)] + [InlineData("en-US", "MBTU", EnergyUnit.MegabritishThermalUnit)] + [InlineData("en-US", "Mcal", EnergyUnit.Megacalorie)] + [InlineData("en-US", "MeV", EnergyUnit.MegaelectronVolt)] + [InlineData("en-US", "MJ", EnergyUnit.Megajoule)] + [InlineData("en-US", "MWd", EnergyUnit.MegawattDay)] + [InlineData("en-US", "MWh", EnergyUnit.MegawattHour)] + [InlineData("en-US", "µJ", EnergyUnit.Microjoule)] + [InlineData("en-US", "mJ", EnergyUnit.Millijoule)] + [InlineData("en-US", "nJ", EnergyUnit.Nanojoule)] + [InlineData("en-US", "PJ", EnergyUnit.Petajoule)] + [InlineData("en-US", "TeV", EnergyUnit.TeraelectronVolt)] + [InlineData("en-US", "TJ", EnergyUnit.Terajoule)] + [InlineData("en-US", "TWd", EnergyUnit.TerawattDay)] + [InlineData("en-US", "TWh", EnergyUnit.TerawattHour)] + [InlineData("en-US", "th (E.C.)", EnergyUnit.ThermEc)] + [InlineData("en-US", "th (imp.)", EnergyUnit.ThermImperial)] + [InlineData("en-US", "th (U.S.)", EnergyUnit.ThermUs)] + [InlineData("en-US", "Wd", EnergyUnit.WattDay)] + [InlineData("en-US", "Wh", EnergyUnit.WattHour)] + [InlineData("ru-RU", "Европейский декатерм", EnergyUnit.DecathermEc)] + [InlineData("ru-RU", "Английский декатерм", EnergyUnit.DecathermImperial)] + [InlineData("ru-RU", "Американский декатерм", EnergyUnit.DecathermUs)] + [InlineData("ru-RU", "эВ", EnergyUnit.ElectronVolt)] + [InlineData("ru-RU", "ГэВ", EnergyUnit.GigaelectronVolt)] + [InlineData("ru-RU", "ГВт/д", EnergyUnit.GigawattDay)] + [InlineData("ru-RU", "ГВт/ч", EnergyUnit.GigawattHour)] + [InlineData("ru-RU", "кэВ", EnergyUnit.KiloelectronVolt)] + [InlineData("ru-RU", "кВт/д", EnergyUnit.KilowattDay)] + [InlineData("ru-RU", "кВт/ч", EnergyUnit.KilowattHour)] + [InlineData("ru-RU", "МэВ", EnergyUnit.MegaelectronVolt)] + [InlineData("ru-RU", "МВт/д", EnergyUnit.MegawattDay)] + [InlineData("ru-RU", "МВт/ч", EnergyUnit.MegawattHour)] + [InlineData("ru-RU", "ТэВ", EnergyUnit.TeraelectronVolt)] + [InlineData("ru-RU", "ТВт/д", EnergyUnit.TerawattDay)] + [InlineData("ru-RU", "ТВт/ч", EnergyUnit.TerawattHour)] + [InlineData("ru-RU", "Европейский терм", EnergyUnit.ThermEc)] + [InlineData("ru-RU", "Английский терм", EnergyUnit.ThermImperial)] + [InlineData("ru-RU", "Американский терм", EnergyUnit.ThermUs)] + [InlineData("ru-RU", "Вт/д", EnergyUnit.WattDay)] + [InlineData("ru-RU", "Вт/ч", EnergyUnit.WattHour)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, EnergyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Energy.TryParseUnit(abbreviation, out EnergyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1584,7 +1823,7 @@ public void TryParseUnit(string abbreviation, EnergyUnit expectedUnit) [InlineData("ru-RU", "Американский терм", EnergyUnit.ThermUs)] [InlineData("ru-RU", "Вт/д", EnergyUnit.WattDay)] [InlineData("ru-RU", "Вт/ч", EnergyUnit.WattHour)] - public void TryParseUnitWithCulture(string culture, string abbreviation, EnergyUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, EnergyUnit expectedUnit) { Assert.True(Energy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out EnergyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs index a24bc97502..cfb0ae0064 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/EntropyTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -346,10 +347,27 @@ public void TryParse() [InlineData("kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] [InlineData("kJ/K", EntropyUnit.KilojoulePerKelvin)] [InlineData("MJ/K", EntropyUnit.MegajoulePerKelvin)] - public void ParseUnit(string abbreviation, EntropyUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, EntropyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - EntropyUnit parsedUnit = Entropy.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + EntropyUnit parsedUnit = Entropy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cal/K", EntropyUnit.CaloriePerKelvin)] + [InlineData("J/C", EntropyUnit.JoulePerDegreeCelsius)] + [InlineData("J/K", EntropyUnit.JoulePerKelvin)] + [InlineData("kcal/K", EntropyUnit.KilocaloriePerKelvin)] + [InlineData("kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] + [InlineData("kJ/K", EntropyUnit.KilojoulePerKelvin)] + [InlineData("MJ/K", EntropyUnit.MegajoulePerKelvin)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, EntropyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + EntropyUnit parsedUnit = Entropy.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -361,7 +379,22 @@ public void ParseUnit(string abbreviation, EntropyUnit expectedUnit) [InlineData("en-US", "kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] [InlineData("en-US", "kJ/K", EntropyUnit.KilojoulePerKelvin)] [InlineData("en-US", "MJ/K", EntropyUnit.MegajoulePerKelvin)] - public void ParseUnitWithCulture(string culture, string abbreviation, EntropyUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, EntropyUnit expectedUnit) + { + using var _ = new CultureScope(culture); + EntropyUnit parsedUnit = Entropy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cal/K", EntropyUnit.CaloriePerKelvin)] + [InlineData("en-US", "J/C", EntropyUnit.JoulePerDegreeCelsius)] + [InlineData("en-US", "J/K", EntropyUnit.JoulePerKelvin)] + [InlineData("en-US", "kcal/K", EntropyUnit.KilocaloriePerKelvin)] + [InlineData("en-US", "kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] + [InlineData("en-US", "kJ/K", EntropyUnit.KilojoulePerKelvin)] + [InlineData("en-US", "MJ/K", EntropyUnit.MegajoulePerKelvin)] + public void ParseUnit_WithCulture(string culture, string abbreviation, EntropyUnit expectedUnit) { EntropyUnit parsedUnit = Entropy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -375,9 +408,41 @@ public void ParseUnitWithCulture(string culture, string abbreviation, EntropyUni [InlineData("kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] [InlineData("kJ/K", EntropyUnit.KilojoulePerKelvin)] [InlineData("MJ/K", EntropyUnit.MegajoulePerKelvin)] - public void TryParseUnit(string abbreviation, EntropyUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, EntropyUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Entropy.TryParseUnit(abbreviation, out EntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cal/K", EntropyUnit.CaloriePerKelvin)] + [InlineData("J/C", EntropyUnit.JoulePerDegreeCelsius)] + [InlineData("J/K", EntropyUnit.JoulePerKelvin)] + [InlineData("kcal/K", EntropyUnit.KilocaloriePerKelvin)] + [InlineData("kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] + [InlineData("kJ/K", EntropyUnit.KilojoulePerKelvin)] + [InlineData("MJ/K", EntropyUnit.MegajoulePerKelvin)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, EntropyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Entropy.TryParseUnit(abbreviation, out EntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cal/K", EntropyUnit.CaloriePerKelvin)] + [InlineData("en-US", "J/C", EntropyUnit.JoulePerDegreeCelsius)] + [InlineData("en-US", "J/K", EntropyUnit.JoulePerKelvin)] + [InlineData("en-US", "kcal/K", EntropyUnit.KilocaloriePerKelvin)] + [InlineData("en-US", "kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] + [InlineData("en-US", "kJ/K", EntropyUnit.KilojoulePerKelvin)] + [InlineData("en-US", "MJ/K", EntropyUnit.MegajoulePerKelvin)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, EntropyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Entropy.TryParseUnit(abbreviation, out EntropyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -390,7 +455,7 @@ public void TryParseUnit(string abbreviation, EntropyUnit expectedUnit) [InlineData("en-US", "kJ/C", EntropyUnit.KilojoulePerDegreeCelsius)] [InlineData("en-US", "kJ/K", EntropyUnit.KilojoulePerKelvin)] [InlineData("en-US", "MJ/K", EntropyUnit.MegajoulePerKelvin)] - public void TryParseUnitWithCulture(string culture, string abbreviation, EntropyUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, EntropyUnit expectedUnit) { Assert.True(Entropy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out EntropyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs index b17de2439a..b03d559796 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceChangeRateTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -594,10 +595,39 @@ public void TryParse() [InlineData("N/s", ForceChangeRateUnit.NewtonPerSecond)] [InlineData("lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] [InlineData("lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] - public void ParseUnit(string abbreviation, ForceChangeRateUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ForceChangeRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ForceChangeRateUnit parsedUnit = ForceChangeRate.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ForceChangeRateUnit parsedUnit = ForceChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cN/s", ForceChangeRateUnit.CentinewtonPerSecond)] + [InlineData("daN/min", ForceChangeRateUnit.DecanewtonPerMinute)] + [InlineData("daN/s", ForceChangeRateUnit.DecanewtonPerSecond)] + [InlineData("dN/s", ForceChangeRateUnit.DecinewtonPerSecond)] + [InlineData("kN/min", ForceChangeRateUnit.KilonewtonPerMinute)] + [InlineData("kN/s", ForceChangeRateUnit.KilonewtonPerSecond)] + [InlineData("kipf/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("kip/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("k/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("kipf/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("kip/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("k/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("µN/s", ForceChangeRateUnit.MicronewtonPerSecond)] + [InlineData("mN/s", ForceChangeRateUnit.MillinewtonPerSecond)] + [InlineData("nN/s", ForceChangeRateUnit.NanonewtonPerSecond)] + [InlineData("N/min", ForceChangeRateUnit.NewtonPerMinute)] + [InlineData("N/s", ForceChangeRateUnit.NewtonPerSecond)] + [InlineData("lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] + [InlineData("lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ForceChangeRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ForceChangeRateUnit parsedUnit = ForceChangeRate.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -621,7 +651,34 @@ public void ParseUnit(string abbreviation, ForceChangeRateUnit expectedUnit) [InlineData("en-US", "N/s", ForceChangeRateUnit.NewtonPerSecond)] [InlineData("en-US", "lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] [InlineData("en-US", "lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, ForceChangeRateUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ForceChangeRateUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ForceChangeRateUnit parsedUnit = ForceChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cN/s", ForceChangeRateUnit.CentinewtonPerSecond)] + [InlineData("en-US", "daN/min", ForceChangeRateUnit.DecanewtonPerMinute)] + [InlineData("en-US", "daN/s", ForceChangeRateUnit.DecanewtonPerSecond)] + [InlineData("en-US", "dN/s", ForceChangeRateUnit.DecinewtonPerSecond)] + [InlineData("en-US", "kN/min", ForceChangeRateUnit.KilonewtonPerMinute)] + [InlineData("en-US", "kN/s", ForceChangeRateUnit.KilonewtonPerSecond)] + [InlineData("en-US", "kipf/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "kip/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "k/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "kipf/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "kip/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "k/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "µN/s", ForceChangeRateUnit.MicronewtonPerSecond)] + [InlineData("en-US", "mN/s", ForceChangeRateUnit.MillinewtonPerSecond)] + [InlineData("en-US", "nN/s", ForceChangeRateUnit.NanonewtonPerSecond)] + [InlineData("en-US", "N/min", ForceChangeRateUnit.NewtonPerMinute)] + [InlineData("en-US", "N/s", ForceChangeRateUnit.NewtonPerSecond)] + [InlineData("en-US", "lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] + [InlineData("en-US", "lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ForceChangeRateUnit expectedUnit) { ForceChangeRateUnit parsedUnit = ForceChangeRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -647,9 +704,65 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ForceChang [InlineData("N/s", ForceChangeRateUnit.NewtonPerSecond)] [InlineData("lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] [InlineData("lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] - public void TryParseUnit(string abbreviation, ForceChangeRateUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ForceChangeRateUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ForceChangeRate.TryParseUnit(abbreviation, out ForceChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cN/s", ForceChangeRateUnit.CentinewtonPerSecond)] + [InlineData("daN/min", ForceChangeRateUnit.DecanewtonPerMinute)] + [InlineData("daN/s", ForceChangeRateUnit.DecanewtonPerSecond)] + [InlineData("dN/s", ForceChangeRateUnit.DecinewtonPerSecond)] + [InlineData("kN/min", ForceChangeRateUnit.KilonewtonPerMinute)] + [InlineData("kN/s", ForceChangeRateUnit.KilonewtonPerSecond)] + [InlineData("kipf/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("kip/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("k/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("kipf/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("kip/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("k/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("µN/s", ForceChangeRateUnit.MicronewtonPerSecond)] + [InlineData("mN/s", ForceChangeRateUnit.MillinewtonPerSecond)] + [InlineData("nN/s", ForceChangeRateUnit.NanonewtonPerSecond)] + [InlineData("N/min", ForceChangeRateUnit.NewtonPerMinute)] + [InlineData("N/s", ForceChangeRateUnit.NewtonPerSecond)] + [InlineData("lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] + [InlineData("lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ForceChangeRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ForceChangeRate.TryParseUnit(abbreviation, out ForceChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cN/s", ForceChangeRateUnit.CentinewtonPerSecond)] + [InlineData("en-US", "daN/min", ForceChangeRateUnit.DecanewtonPerMinute)] + [InlineData("en-US", "daN/s", ForceChangeRateUnit.DecanewtonPerSecond)] + [InlineData("en-US", "dN/s", ForceChangeRateUnit.DecinewtonPerSecond)] + [InlineData("en-US", "kN/min", ForceChangeRateUnit.KilonewtonPerMinute)] + [InlineData("en-US", "kN/s", ForceChangeRateUnit.KilonewtonPerSecond)] + [InlineData("en-US", "kipf/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "kip/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "k/min", ForceChangeRateUnit.KilopoundForcePerMinute)] + [InlineData("en-US", "kipf/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "kip/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "k/s", ForceChangeRateUnit.KilopoundForcePerSecond)] + [InlineData("en-US", "µN/s", ForceChangeRateUnit.MicronewtonPerSecond)] + [InlineData("en-US", "mN/s", ForceChangeRateUnit.MillinewtonPerSecond)] + [InlineData("en-US", "nN/s", ForceChangeRateUnit.NanonewtonPerSecond)] + [InlineData("en-US", "N/min", ForceChangeRateUnit.NewtonPerMinute)] + [InlineData("en-US", "N/s", ForceChangeRateUnit.NewtonPerSecond)] + [InlineData("en-US", "lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] + [InlineData("en-US", "lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ForceChangeRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ForceChangeRate.TryParseUnit(abbreviation, out ForceChangeRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -674,7 +787,7 @@ public void TryParseUnit(string abbreviation, ForceChangeRateUnit expectedUnit) [InlineData("en-US", "N/s", ForceChangeRateUnit.NewtonPerSecond)] [InlineData("en-US", "lbf/min", ForceChangeRateUnit.PoundForcePerMinute)] [InlineData("en-US", "lbf/s", ForceChangeRateUnit.PoundForcePerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ForceChangeRateUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ForceChangeRateUnit expectedUnit) { Assert.True(ForceChangeRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ForceChangeRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs index 7f975cc294..70670e8905 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForcePerLengthTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1188,10 +1189,62 @@ public void TryParse() [InlineData("tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter)] [InlineData("tf/m", ForcePerLengthUnit.TonneForcePerMeter)] [InlineData("tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter)] - public void ParseUnit(string abbreviation, ForcePerLengthUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ForcePerLengthUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ForcePerLengthUnit parsedUnit = ForcePerLength.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ForcePerLengthUnit parsedUnit = ForcePerLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cN/cm", ForcePerLengthUnit.CentinewtonPerCentimeter)] + [InlineData("cN/m", ForcePerLengthUnit.CentinewtonPerMeter)] + [InlineData("cN/mm", ForcePerLengthUnit.CentinewtonPerMillimeter)] + [InlineData("daN/cm", ForcePerLengthUnit.DecanewtonPerCentimeter)] + [InlineData("daN/m", ForcePerLengthUnit.DecanewtonPerMeter)] + [InlineData("daN/mm", ForcePerLengthUnit.DecanewtonPerMillimeter)] + [InlineData("dN/cm", ForcePerLengthUnit.DecinewtonPerCentimeter)] + [InlineData("dN/m", ForcePerLengthUnit.DecinewtonPerMeter)] + [InlineData("dN/mm", ForcePerLengthUnit.DecinewtonPerMillimeter)] + [InlineData("kgf/cm", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("kgf/m", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("kgf/mm", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("kN/cm", ForcePerLengthUnit.KilonewtonPerCentimeter)] + [InlineData("kN/m", ForcePerLengthUnit.KilonewtonPerMeter)] + [InlineData("kN/mm", ForcePerLengthUnit.KilonewtonPerMillimeter)] + [InlineData("kipf/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("kip/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("k/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("kipf/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("kip/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("k/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("MN/cm", ForcePerLengthUnit.MeganewtonPerCentimeter)] + [InlineData("MN/m", ForcePerLengthUnit.MeganewtonPerMeter)] + [InlineData("MN/mm", ForcePerLengthUnit.MeganewtonPerMillimeter)] + [InlineData("µN/cm", ForcePerLengthUnit.MicronewtonPerCentimeter)] + [InlineData("µN/m", ForcePerLengthUnit.MicronewtonPerMeter)] + [InlineData("µN/mm", ForcePerLengthUnit.MicronewtonPerMillimeter)] + [InlineData("mN/cm", ForcePerLengthUnit.MillinewtonPerCentimeter)] + [InlineData("mN/m", ForcePerLengthUnit.MillinewtonPerMeter)] + [InlineData("mN/mm", ForcePerLengthUnit.MillinewtonPerMillimeter)] + [InlineData("nN/cm", ForcePerLengthUnit.NanonewtonPerCentimeter)] + [InlineData("nN/m", ForcePerLengthUnit.NanonewtonPerMeter)] + [InlineData("nN/mm", ForcePerLengthUnit.NanonewtonPerMillimeter)] + [InlineData("N/cm", ForcePerLengthUnit.NewtonPerCentimeter)] + [InlineData("N/m", ForcePerLengthUnit.NewtonPerMeter)] + [InlineData("N/mm", ForcePerLengthUnit.NewtonPerMillimeter)] + [InlineData("lbf/ft", ForcePerLengthUnit.PoundForcePerFoot)] + [InlineData("lbf/in", ForcePerLengthUnit.PoundForcePerInch)] + [InlineData("lbf/yd", ForcePerLengthUnit.PoundForcePerYard)] + [InlineData("tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("tf/m", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ForcePerLengthUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ForcePerLengthUnit parsedUnit = ForcePerLength.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1244,7 +1297,63 @@ public void ParseUnit(string abbreviation, ForcePerLengthUnit expectedUnit) [InlineData("ru-RU", "тс/см", ForcePerLengthUnit.TonneForcePerCentimeter)] [InlineData("ru-RU", "тс/м", ForcePerLengthUnit.TonneForcePerMeter)] [InlineData("ru-RU", "тс/мм", ForcePerLengthUnit.TonneForcePerMillimeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, ForcePerLengthUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ForcePerLengthUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ForcePerLengthUnit parsedUnit = ForcePerLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cN/cm", ForcePerLengthUnit.CentinewtonPerCentimeter)] + [InlineData("en-US", "cN/m", ForcePerLengthUnit.CentinewtonPerMeter)] + [InlineData("en-US", "cN/mm", ForcePerLengthUnit.CentinewtonPerMillimeter)] + [InlineData("en-US", "daN/cm", ForcePerLengthUnit.DecanewtonPerCentimeter)] + [InlineData("en-US", "daN/m", ForcePerLengthUnit.DecanewtonPerMeter)] + [InlineData("en-US", "daN/mm", ForcePerLengthUnit.DecanewtonPerMillimeter)] + [InlineData("en-US", "dN/cm", ForcePerLengthUnit.DecinewtonPerCentimeter)] + [InlineData("en-US", "dN/m", ForcePerLengthUnit.DecinewtonPerMeter)] + [InlineData("en-US", "dN/mm", ForcePerLengthUnit.DecinewtonPerMillimeter)] + [InlineData("en-US", "kgf/cm", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("en-US", "kgf/m", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("en-US", "kgf/mm", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("en-US", "kN/cm", ForcePerLengthUnit.KilonewtonPerCentimeter)] + [InlineData("en-US", "kN/m", ForcePerLengthUnit.KilonewtonPerMeter)] + [InlineData("en-US", "kN/mm", ForcePerLengthUnit.KilonewtonPerMillimeter)] + [InlineData("en-US", "kipf/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "kip/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "k/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "kipf/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "kip/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "k/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "MN/cm", ForcePerLengthUnit.MeganewtonPerCentimeter)] + [InlineData("en-US", "MN/m", ForcePerLengthUnit.MeganewtonPerMeter)] + [InlineData("en-US", "MN/mm", ForcePerLengthUnit.MeganewtonPerMillimeter)] + [InlineData("en-US", "µN/cm", ForcePerLengthUnit.MicronewtonPerCentimeter)] + [InlineData("en-US", "µN/m", ForcePerLengthUnit.MicronewtonPerMeter)] + [InlineData("en-US", "µN/mm", ForcePerLengthUnit.MicronewtonPerMillimeter)] + [InlineData("en-US", "mN/cm", ForcePerLengthUnit.MillinewtonPerCentimeter)] + [InlineData("en-US", "mN/m", ForcePerLengthUnit.MillinewtonPerMeter)] + [InlineData("en-US", "mN/mm", ForcePerLengthUnit.MillinewtonPerMillimeter)] + [InlineData("en-US", "nN/cm", ForcePerLengthUnit.NanonewtonPerCentimeter)] + [InlineData("en-US", "nN/m", ForcePerLengthUnit.NanonewtonPerMeter)] + [InlineData("en-US", "nN/mm", ForcePerLengthUnit.NanonewtonPerMillimeter)] + [InlineData("en-US", "N/cm", ForcePerLengthUnit.NewtonPerCentimeter)] + [InlineData("en-US", "N/m", ForcePerLengthUnit.NewtonPerMeter)] + [InlineData("en-US", "N/mm", ForcePerLengthUnit.NewtonPerMillimeter)] + [InlineData("en-US", "lbf/ft", ForcePerLengthUnit.PoundForcePerFoot)] + [InlineData("en-US", "lbf/in", ForcePerLengthUnit.PoundForcePerInch)] + [InlineData("en-US", "lbf/yd", ForcePerLengthUnit.PoundForcePerYard)] + [InlineData("en-US", "tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("en-US", "tf/m", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("en-US", "tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter)] + [InlineData("ru-RU", "кгс/см", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("ru-RU", "кгс/м", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("ru-RU", "кгс/мм", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("ru-RU", "тс/см", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("ru-RU", "тс/м", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("ru-RU", "тс/мм", ForcePerLengthUnit.TonneForcePerMillimeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ForcePerLengthUnit expectedUnit) { ForcePerLengthUnit parsedUnit = ForcePerLength.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1293,9 +1402,117 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ForcePerLe [InlineData("tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter)] [InlineData("tf/m", ForcePerLengthUnit.TonneForcePerMeter)] [InlineData("tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter)] - public void TryParseUnit(string abbreviation, ForcePerLengthUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ForcePerLengthUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ForcePerLength.TryParseUnit(abbreviation, out ForcePerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cN/cm", ForcePerLengthUnit.CentinewtonPerCentimeter)] + [InlineData("cN/m", ForcePerLengthUnit.CentinewtonPerMeter)] + [InlineData("cN/mm", ForcePerLengthUnit.CentinewtonPerMillimeter)] + [InlineData("daN/cm", ForcePerLengthUnit.DecanewtonPerCentimeter)] + [InlineData("daN/m", ForcePerLengthUnit.DecanewtonPerMeter)] + [InlineData("daN/mm", ForcePerLengthUnit.DecanewtonPerMillimeter)] + [InlineData("dN/cm", ForcePerLengthUnit.DecinewtonPerCentimeter)] + [InlineData("dN/m", ForcePerLengthUnit.DecinewtonPerMeter)] + [InlineData("dN/mm", ForcePerLengthUnit.DecinewtonPerMillimeter)] + [InlineData("kgf/cm", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("kgf/m", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("kgf/mm", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("kN/cm", ForcePerLengthUnit.KilonewtonPerCentimeter)] + [InlineData("kN/m", ForcePerLengthUnit.KilonewtonPerMeter)] + [InlineData("kN/mm", ForcePerLengthUnit.KilonewtonPerMillimeter)] + [InlineData("kipf/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("kip/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("k/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("kipf/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("kip/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("k/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("MN/cm", ForcePerLengthUnit.MeganewtonPerCentimeter)] + [InlineData("MN/m", ForcePerLengthUnit.MeganewtonPerMeter)] + [InlineData("MN/mm", ForcePerLengthUnit.MeganewtonPerMillimeter)] + [InlineData("µN/cm", ForcePerLengthUnit.MicronewtonPerCentimeter)] + [InlineData("µN/m", ForcePerLengthUnit.MicronewtonPerMeter)] + [InlineData("µN/mm", ForcePerLengthUnit.MicronewtonPerMillimeter)] + [InlineData("mN/cm", ForcePerLengthUnit.MillinewtonPerCentimeter)] + [InlineData("mN/m", ForcePerLengthUnit.MillinewtonPerMeter)] + [InlineData("mN/mm", ForcePerLengthUnit.MillinewtonPerMillimeter)] + [InlineData("nN/cm", ForcePerLengthUnit.NanonewtonPerCentimeter)] + [InlineData("nN/m", ForcePerLengthUnit.NanonewtonPerMeter)] + [InlineData("nN/mm", ForcePerLengthUnit.NanonewtonPerMillimeter)] + [InlineData("N/cm", ForcePerLengthUnit.NewtonPerCentimeter)] + [InlineData("N/m", ForcePerLengthUnit.NewtonPerMeter)] + [InlineData("N/mm", ForcePerLengthUnit.NewtonPerMillimeter)] + [InlineData("lbf/ft", ForcePerLengthUnit.PoundForcePerFoot)] + [InlineData("lbf/in", ForcePerLengthUnit.PoundForcePerInch)] + [InlineData("lbf/yd", ForcePerLengthUnit.PoundForcePerYard)] + [InlineData("tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("tf/m", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ForcePerLengthUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ForcePerLength.TryParseUnit(abbreviation, out ForcePerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cN/cm", ForcePerLengthUnit.CentinewtonPerCentimeter)] + [InlineData("en-US", "cN/m", ForcePerLengthUnit.CentinewtonPerMeter)] + [InlineData("en-US", "cN/mm", ForcePerLengthUnit.CentinewtonPerMillimeter)] + [InlineData("en-US", "daN/cm", ForcePerLengthUnit.DecanewtonPerCentimeter)] + [InlineData("en-US", "daN/m", ForcePerLengthUnit.DecanewtonPerMeter)] + [InlineData("en-US", "daN/mm", ForcePerLengthUnit.DecanewtonPerMillimeter)] + [InlineData("en-US", "dN/cm", ForcePerLengthUnit.DecinewtonPerCentimeter)] + [InlineData("en-US", "dN/m", ForcePerLengthUnit.DecinewtonPerMeter)] + [InlineData("en-US", "dN/mm", ForcePerLengthUnit.DecinewtonPerMillimeter)] + [InlineData("en-US", "kgf/cm", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("en-US", "kgf/m", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("en-US", "kgf/mm", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("en-US", "kN/cm", ForcePerLengthUnit.KilonewtonPerCentimeter)] + [InlineData("en-US", "kN/m", ForcePerLengthUnit.KilonewtonPerMeter)] + [InlineData("en-US", "kN/mm", ForcePerLengthUnit.KilonewtonPerMillimeter)] + [InlineData("en-US", "kipf/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "kip/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "k/ft", ForcePerLengthUnit.KilopoundForcePerFoot)] + [InlineData("en-US", "kipf/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "kip/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "k/in", ForcePerLengthUnit.KilopoundForcePerInch)] + [InlineData("en-US", "MN/cm", ForcePerLengthUnit.MeganewtonPerCentimeter)] + [InlineData("en-US", "MN/m", ForcePerLengthUnit.MeganewtonPerMeter)] + [InlineData("en-US", "MN/mm", ForcePerLengthUnit.MeganewtonPerMillimeter)] + [InlineData("en-US", "µN/cm", ForcePerLengthUnit.MicronewtonPerCentimeter)] + [InlineData("en-US", "µN/m", ForcePerLengthUnit.MicronewtonPerMeter)] + [InlineData("en-US", "µN/mm", ForcePerLengthUnit.MicronewtonPerMillimeter)] + [InlineData("en-US", "mN/cm", ForcePerLengthUnit.MillinewtonPerCentimeter)] + [InlineData("en-US", "mN/m", ForcePerLengthUnit.MillinewtonPerMeter)] + [InlineData("en-US", "mN/mm", ForcePerLengthUnit.MillinewtonPerMillimeter)] + [InlineData("en-US", "nN/cm", ForcePerLengthUnit.NanonewtonPerCentimeter)] + [InlineData("en-US", "nN/m", ForcePerLengthUnit.NanonewtonPerMeter)] + [InlineData("en-US", "nN/mm", ForcePerLengthUnit.NanonewtonPerMillimeter)] + [InlineData("en-US", "N/cm", ForcePerLengthUnit.NewtonPerCentimeter)] + [InlineData("en-US", "N/m", ForcePerLengthUnit.NewtonPerMeter)] + [InlineData("en-US", "N/mm", ForcePerLengthUnit.NewtonPerMillimeter)] + [InlineData("en-US", "lbf/ft", ForcePerLengthUnit.PoundForcePerFoot)] + [InlineData("en-US", "lbf/in", ForcePerLengthUnit.PoundForcePerInch)] + [InlineData("en-US", "lbf/yd", ForcePerLengthUnit.PoundForcePerYard)] + [InlineData("en-US", "tf/cm", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("en-US", "tf/m", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("en-US", "tf/mm", ForcePerLengthUnit.TonneForcePerMillimeter)] + [InlineData("ru-RU", "кгс/см", ForcePerLengthUnit.KilogramForcePerCentimeter)] + [InlineData("ru-RU", "кгс/м", ForcePerLengthUnit.KilogramForcePerMeter)] + [InlineData("ru-RU", "кгс/мм", ForcePerLengthUnit.KilogramForcePerMillimeter)] + [InlineData("ru-RU", "тс/см", ForcePerLengthUnit.TonneForcePerCentimeter)] + [InlineData("ru-RU", "тс/м", ForcePerLengthUnit.TonneForcePerMeter)] + [InlineData("ru-RU", "тс/мм", ForcePerLengthUnit.TonneForcePerMillimeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ForcePerLengthUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ForcePerLength.TryParseUnit(abbreviation, out ForcePerLengthUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1349,7 +1566,7 @@ public void TryParseUnit(string abbreviation, ForcePerLengthUnit expectedUnit) [InlineData("ru-RU", "тс/см", ForcePerLengthUnit.TonneForcePerCentimeter)] [InlineData("ru-RU", "тс/м", ForcePerLengthUnit.TonneForcePerMeter)] [InlineData("ru-RU", "тс/мм", ForcePerLengthUnit.TonneForcePerMillimeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ForcePerLengthUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ForcePerLengthUnit expectedUnit) { Assert.True(ForcePerLength.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ForcePerLengthUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs index 8a8fa1d653..245782aa4b 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ForceTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -767,10 +768,81 @@ public void TryParse() [InlineData("short tons-force", ForceUnit.ShortTonForce)] [InlineData("tf", ForceUnit.TonneForce)] [InlineData("Ton", ForceUnit.TonneForce)] - public void ParseUnit(string abbreviation, ForceUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ForceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ForceUnit parsedUnit = Force.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ForceUnit parsedUnit = Force.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("daN", ForceUnit.Decanewton)] + [InlineData("dyn", ForceUnit.Dyn)] + [InlineData("kgf", ForceUnit.KilogramForce)] + [InlineData("kN", ForceUnit.Kilonewton)] + [InlineData("kp", ForceUnit.KiloPond)] + [InlineData("kipf", ForceUnit.KilopoundForce)] + [InlineData("kip", ForceUnit.KilopoundForce)] + [InlineData("k", ForceUnit.KilopoundForce)] + [InlineData("MN", ForceUnit.Meganewton)] + [InlineData("µN", ForceUnit.Micronewton)] + [InlineData("mN", ForceUnit.Millinewton)] + [InlineData("N", ForceUnit.Newton)] + [InlineData("ozf", ForceUnit.OunceForce)] + [InlineData("pdl", ForceUnit.Poundal)] + [InlineData("lbf", ForceUnit.PoundForce)] + [InlineData("tf (short)", ForceUnit.ShortTonForce)] + [InlineData("t (US)f", ForceUnit.ShortTonForce)] + [InlineData("short tons-force", ForceUnit.ShortTonForce)] + [InlineData("tf", ForceUnit.TonneForce)] + [InlineData("Ton", ForceUnit.TonneForce)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ForceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ForceUnit parsedUnit = Force.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "daN", ForceUnit.Decanewton)] + [InlineData("en-US", "dyn", ForceUnit.Dyn)] + [InlineData("en-US", "kgf", ForceUnit.KilogramForce)] + [InlineData("en-US", "kN", ForceUnit.Kilonewton)] + [InlineData("en-US", "kp", ForceUnit.KiloPond)] + [InlineData("en-US", "kipf", ForceUnit.KilopoundForce)] + [InlineData("en-US", "kip", ForceUnit.KilopoundForce)] + [InlineData("en-US", "k", ForceUnit.KilopoundForce)] + [InlineData("en-US", "MN", ForceUnit.Meganewton)] + [InlineData("en-US", "µN", ForceUnit.Micronewton)] + [InlineData("en-US", "mN", ForceUnit.Millinewton)] + [InlineData("en-US", "N", ForceUnit.Newton)] + [InlineData("en-US", "ozf", ForceUnit.OunceForce)] + [InlineData("en-US", "pdl", ForceUnit.Poundal)] + [InlineData("en-US", "lbf", ForceUnit.PoundForce)] + [InlineData("en-US", "tf (short)", ForceUnit.ShortTonForce)] + [InlineData("en-US", "t (US)f", ForceUnit.ShortTonForce)] + [InlineData("en-US", "short tons-force", ForceUnit.ShortTonForce)] + [InlineData("en-US", "tf", ForceUnit.TonneForce)] + [InlineData("en-US", "Ton", ForceUnit.TonneForce)] + [InlineData("ru-RU", "даН", ForceUnit.Decanewton)] + [InlineData("ru-RU", "дин", ForceUnit.Dyn)] + [InlineData("ru-RU", "кН", ForceUnit.Kilonewton)] + [InlineData("ru-RU", "кипф", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "койка", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "К", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "МН", ForceUnit.Meganewton)] + [InlineData("ru-RU", "мкН", ForceUnit.Micronewton)] + [InlineData("ru-RU", "мН", ForceUnit.Millinewton)] + [InlineData("ru-RU", "Н", ForceUnit.Newton)] + [InlineData("ru-RU", "паундаль", ForceUnit.Poundal)] + [InlineData("ru-RU", "фунт-сила", ForceUnit.PoundForce)] + [InlineData("ru-RU", "тс", ForceUnit.TonneForce)] + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ForceUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ForceUnit parsedUnit = Force.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -808,7 +880,7 @@ public void ParseUnit(string abbreviation, ForceUnit expectedUnit) [InlineData("ru-RU", "паундаль", ForceUnit.Poundal)] [InlineData("ru-RU", "фунт-сила", ForceUnit.PoundForce)] [InlineData("ru-RU", "тс", ForceUnit.TonneForce)] - public void ParseUnitWithCulture(string culture, string abbreviation, ForceUnit expectedUnit) + public void ParseUnit_WithCulture(string culture, string abbreviation, ForceUnit expectedUnit) { ForceUnit parsedUnit = Force.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -842,9 +914,80 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati [InlineData("short tons-force", ForceUnit.ShortTonForce)] [InlineData("tf", ForceUnit.TonneForce)] [InlineData("Ton", ForceUnit.TonneForce)] - public void TryParseUnit(string abbreviation, ForceUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ForceUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Force.TryParseUnit(abbreviation, out ForceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("daN", ForceUnit.Decanewton)] + [InlineData("dyn", ForceUnit.Dyn)] + [InlineData("kgf", ForceUnit.KilogramForce)] + [InlineData("kN", ForceUnit.Kilonewton)] + [InlineData("kp", ForceUnit.KiloPond)] + [InlineData("kipf", ForceUnit.KilopoundForce)] + [InlineData("kip", ForceUnit.KilopoundForce)] + [InlineData("k", ForceUnit.KilopoundForce)] + [InlineData("MN", ForceUnit.Meganewton)] + [InlineData("µN", ForceUnit.Micronewton)] + [InlineData("mN", ForceUnit.Millinewton)] + [InlineData("N", ForceUnit.Newton)] + [InlineData("ozf", ForceUnit.OunceForce)] + [InlineData("pdl", ForceUnit.Poundal)] + [InlineData("lbf", ForceUnit.PoundForce)] + [InlineData("tf (short)", ForceUnit.ShortTonForce)] + [InlineData("t (US)f", ForceUnit.ShortTonForce)] + [InlineData("short tons-force", ForceUnit.ShortTonForce)] + [InlineData("tf", ForceUnit.TonneForce)] + [InlineData("Ton", ForceUnit.TonneForce)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ForceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Force.TryParseUnit(abbreviation, out ForceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "daN", ForceUnit.Decanewton)] + [InlineData("en-US", "dyn", ForceUnit.Dyn)] + [InlineData("en-US", "kgf", ForceUnit.KilogramForce)] + [InlineData("en-US", "kN", ForceUnit.Kilonewton)] + [InlineData("en-US", "kp", ForceUnit.KiloPond)] + [InlineData("en-US", "kipf", ForceUnit.KilopoundForce)] + [InlineData("en-US", "kip", ForceUnit.KilopoundForce)] + [InlineData("en-US", "k", ForceUnit.KilopoundForce)] + [InlineData("en-US", "MN", ForceUnit.Meganewton)] + [InlineData("en-US", "µN", ForceUnit.Micronewton)] + [InlineData("en-US", "mN", ForceUnit.Millinewton)] + [InlineData("en-US", "N", ForceUnit.Newton)] + [InlineData("en-US", "ozf", ForceUnit.OunceForce)] + [InlineData("en-US", "pdl", ForceUnit.Poundal)] + [InlineData("en-US", "lbf", ForceUnit.PoundForce)] + [InlineData("en-US", "tf (short)", ForceUnit.ShortTonForce)] + [InlineData("en-US", "t (US)f", ForceUnit.ShortTonForce)] + [InlineData("en-US", "short tons-force", ForceUnit.ShortTonForce)] + [InlineData("en-US", "tf", ForceUnit.TonneForce)] + [InlineData("en-US", "Ton", ForceUnit.TonneForce)] + [InlineData("ru-RU", "даН", ForceUnit.Decanewton)] + [InlineData("ru-RU", "дин", ForceUnit.Dyn)] + [InlineData("ru-RU", "кН", ForceUnit.Kilonewton)] + [InlineData("ru-RU", "кипф", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "койка", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "К", ForceUnit.KilopoundForce)] + [InlineData("ru-RU", "МН", ForceUnit.Meganewton)] + [InlineData("ru-RU", "мкН", ForceUnit.Micronewton)] + [InlineData("ru-RU", "мН", ForceUnit.Millinewton)] + [InlineData("ru-RU", "Н", ForceUnit.Newton)] + [InlineData("ru-RU", "паундаль", ForceUnit.Poundal)] + [InlineData("ru-RU", "фунт-сила", ForceUnit.PoundForce)] + [InlineData("ru-RU", "тс", ForceUnit.TonneForce)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ForceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Force.TryParseUnit(abbreviation, out ForceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -883,7 +1026,7 @@ public void TryParseUnit(string abbreviation, ForceUnit expectedUnit) [InlineData("ru-RU", "паундаль", ForceUnit.Poundal)] [InlineData("ru-RU", "фунт-сила", ForceUnit.PoundForce)] [InlineData("ru-RU", "тс", ForceUnit.TonneForce)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ForceUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ForceUnit expectedUnit) { Assert.True(Force.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ForceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs index 491d123e65..90940a1cdd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FrequencyTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -583,10 +584,63 @@ public void TryParse() [InlineData("s⁻¹", FrequencyUnit.PerSecond)] [InlineData("rad/s", FrequencyUnit.RadianPerSecond)] [InlineData("THz", FrequencyUnit.Terahertz)] - public void ParseUnit(string abbreviation, FrequencyUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, FrequencyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - FrequencyUnit parsedUnit = Frequency.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + FrequencyUnit parsedUnit = Frequency.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("bpm", FrequencyUnit.BeatPerMinute)] + [InlineData("B Units", FrequencyUnit.BUnit)] + [InlineData("cph", FrequencyUnit.CyclePerHour)] + [InlineData("cpm", FrequencyUnit.CyclePerMinute)] + [InlineData("GHz", FrequencyUnit.Gigahertz)] + [InlineData("Hz", FrequencyUnit.Hertz)] + [InlineData("kHz", FrequencyUnit.Kilohertz)] + [InlineData("MHz", FrequencyUnit.Megahertz)] + [InlineData("µHz", FrequencyUnit.Microhertz)] + [InlineData("mHz", FrequencyUnit.Millihertz)] + [InlineData("s⁻¹", FrequencyUnit.PerSecond)] + [InlineData("rad/s", FrequencyUnit.RadianPerSecond)] + [InlineData("THz", FrequencyUnit.Terahertz)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, FrequencyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + FrequencyUnit parsedUnit = Frequency.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "bpm", FrequencyUnit.BeatPerMinute)] + [InlineData("en-US", "B Units", FrequencyUnit.BUnit)] + [InlineData("en-US", "cph", FrequencyUnit.CyclePerHour)] + [InlineData("en-US", "cpm", FrequencyUnit.CyclePerMinute)] + [InlineData("en-US", "GHz", FrequencyUnit.Gigahertz)] + [InlineData("en-US", "Hz", FrequencyUnit.Hertz)] + [InlineData("en-US", "kHz", FrequencyUnit.Kilohertz)] + [InlineData("en-US", "MHz", FrequencyUnit.Megahertz)] + [InlineData("en-US", "µHz", FrequencyUnit.Microhertz)] + [InlineData("en-US", "mHz", FrequencyUnit.Millihertz)] + [InlineData("en-US", "s⁻¹", FrequencyUnit.PerSecond)] + [InlineData("en-US", "rad/s", FrequencyUnit.RadianPerSecond)] + [InlineData("en-US", "THz", FrequencyUnit.Terahertz)] + [InlineData("ru-RU", "ГГц", FrequencyUnit.Gigahertz)] + [InlineData("ru-RU", "Гц", FrequencyUnit.Hertz)] + [InlineData("ru-RU", "кГц", FrequencyUnit.Kilohertz)] + [InlineData("ru-RU", "МГц", FrequencyUnit.Megahertz)] + [InlineData("ru-RU", "мкГц", FrequencyUnit.Microhertz)] + [InlineData("ru-RU", "мГц", FrequencyUnit.Millihertz)] + [InlineData("ru-RU", "с⁻¹", FrequencyUnit.PerSecond)] + [InlineData("ru-RU", "рад/с", FrequencyUnit.RadianPerSecond)] + [InlineData("ru-RU", "ТГц", FrequencyUnit.Terahertz)] + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, FrequencyUnit expectedUnit) + { + using var _ = new CultureScope(culture); + FrequencyUnit parsedUnit = Frequency.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -613,7 +667,7 @@ public void ParseUnit(string abbreviation, FrequencyUnit expectedUnit) [InlineData("ru-RU", "с⁻¹", FrequencyUnit.PerSecond)] [InlineData("ru-RU", "рад/с", FrequencyUnit.RadianPerSecond)] [InlineData("ru-RU", "ТГц", FrequencyUnit.Terahertz)] - public void ParseUnitWithCulture(string culture, string abbreviation, FrequencyUnit expectedUnit) + public void ParseUnit_WithCulture(string culture, string abbreviation, FrequencyUnit expectedUnit) { FrequencyUnit parsedUnit = Frequency.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -633,9 +687,62 @@ public void ParseUnitWithCulture(string culture, string abbreviation, FrequencyU [InlineData("s⁻¹", FrequencyUnit.PerSecond)] [InlineData("rad/s", FrequencyUnit.RadianPerSecond)] [InlineData("THz", FrequencyUnit.Terahertz)] - public void TryParseUnit(string abbreviation, FrequencyUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, FrequencyUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Frequency.TryParseUnit(abbreviation, out FrequencyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("bpm", FrequencyUnit.BeatPerMinute)] + [InlineData("B Units", FrequencyUnit.BUnit)] + [InlineData("cph", FrequencyUnit.CyclePerHour)] + [InlineData("cpm", FrequencyUnit.CyclePerMinute)] + [InlineData("GHz", FrequencyUnit.Gigahertz)] + [InlineData("Hz", FrequencyUnit.Hertz)] + [InlineData("kHz", FrequencyUnit.Kilohertz)] + [InlineData("MHz", FrequencyUnit.Megahertz)] + [InlineData("µHz", FrequencyUnit.Microhertz)] + [InlineData("mHz", FrequencyUnit.Millihertz)] + [InlineData("s⁻¹", FrequencyUnit.PerSecond)] + [InlineData("rad/s", FrequencyUnit.RadianPerSecond)] + [InlineData("THz", FrequencyUnit.Terahertz)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, FrequencyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Frequency.TryParseUnit(abbreviation, out FrequencyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "bpm", FrequencyUnit.BeatPerMinute)] + [InlineData("en-US", "B Units", FrequencyUnit.BUnit)] + [InlineData("en-US", "cph", FrequencyUnit.CyclePerHour)] + [InlineData("en-US", "cpm", FrequencyUnit.CyclePerMinute)] + [InlineData("en-US", "GHz", FrequencyUnit.Gigahertz)] + [InlineData("en-US", "Hz", FrequencyUnit.Hertz)] + [InlineData("en-US", "kHz", FrequencyUnit.Kilohertz)] + [InlineData("en-US", "MHz", FrequencyUnit.Megahertz)] + [InlineData("en-US", "µHz", FrequencyUnit.Microhertz)] + [InlineData("en-US", "mHz", FrequencyUnit.Millihertz)] + [InlineData("en-US", "s⁻¹", FrequencyUnit.PerSecond)] + [InlineData("en-US", "rad/s", FrequencyUnit.RadianPerSecond)] + [InlineData("en-US", "THz", FrequencyUnit.Terahertz)] + [InlineData("ru-RU", "ГГц", FrequencyUnit.Gigahertz)] + [InlineData("ru-RU", "Гц", FrequencyUnit.Hertz)] + [InlineData("ru-RU", "кГц", FrequencyUnit.Kilohertz)] + [InlineData("ru-RU", "МГц", FrequencyUnit.Megahertz)] + [InlineData("ru-RU", "мкГц", FrequencyUnit.Microhertz)] + [InlineData("ru-RU", "мГц", FrequencyUnit.Millihertz)] + [InlineData("ru-RU", "с⁻¹", FrequencyUnit.PerSecond)] + [InlineData("ru-RU", "рад/с", FrequencyUnit.RadianPerSecond)] + [InlineData("ru-RU", "ТГц", FrequencyUnit.Terahertz)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, FrequencyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Frequency.TryParseUnit(abbreviation, out FrequencyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -663,7 +770,7 @@ public void TryParseUnit(string abbreviation, FrequencyUnit expectedUnit) [InlineData("ru-RU", "с⁻¹", FrequencyUnit.PerSecond)] [InlineData("ru-RU", "рад/с", FrequencyUnit.RadianPerSecond)] [InlineData("ru-RU", "ТГц", FrequencyUnit.Terahertz)] - public void TryParseUnitWithCulture(string culture, string abbreviation, FrequencyUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, FrequencyUnit expectedUnit) { Assert.True(Frequency.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out FrequencyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs index 2d782f33b6..da0026a64c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/FuelEfficiencyTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -274,10 +275,24 @@ public void TryParse() [InlineData("l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] [InlineData("mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] [InlineData("mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] - public void ParseUnit(string abbreviation, FuelEfficiencyUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, FuelEfficiencyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - FuelEfficiencyUnit parsedUnit = FuelEfficiency.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + FuelEfficiencyUnit parsedUnit = FuelEfficiency.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("km/l", FuelEfficiencyUnit.KilometerPerLiter)] + [InlineData("l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] + [InlineData("mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] + [InlineData("mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, FuelEfficiencyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + FuelEfficiencyUnit parsedUnit = FuelEfficiency.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -286,7 +301,19 @@ public void ParseUnit(string abbreviation, FuelEfficiencyUnit expectedUnit) [InlineData("en-US", "l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] [InlineData("en-US", "mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] [InlineData("en-US", "mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] - public void ParseUnitWithCulture(string culture, string abbreviation, FuelEfficiencyUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, FuelEfficiencyUnit expectedUnit) + { + using var _ = new CultureScope(culture); + FuelEfficiencyUnit parsedUnit = FuelEfficiency.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "km/l", FuelEfficiencyUnit.KilometerPerLiter)] + [InlineData("en-US", "l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] + [InlineData("en-US", "mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] + [InlineData("en-US", "mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] + public void ParseUnit_WithCulture(string culture, string abbreviation, FuelEfficiencyUnit expectedUnit) { FuelEfficiencyUnit parsedUnit = FuelEfficiency.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -297,9 +324,35 @@ public void ParseUnitWithCulture(string culture, string abbreviation, FuelEffici [InlineData("l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] [InlineData("mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] [InlineData("mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] - public void TryParseUnit(string abbreviation, FuelEfficiencyUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, FuelEfficiencyUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(FuelEfficiency.TryParseUnit(abbreviation, out FuelEfficiencyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("km/l", FuelEfficiencyUnit.KilometerPerLiter)] + [InlineData("l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] + [InlineData("mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] + [InlineData("mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, FuelEfficiencyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(FuelEfficiency.TryParseUnit(abbreviation, out FuelEfficiencyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "km/l", FuelEfficiencyUnit.KilometerPerLiter)] + [InlineData("en-US", "l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] + [InlineData("en-US", "mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] + [InlineData("en-US", "mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, FuelEfficiencyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(FuelEfficiency.TryParseUnit(abbreviation, out FuelEfficiencyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -309,7 +362,7 @@ public void TryParseUnit(string abbreviation, FuelEfficiencyUnit expectedUnit) [InlineData("en-US", "l/100km", FuelEfficiencyUnit.LiterPer100Kilometers)] [InlineData("en-US", "mpg (imp.)", FuelEfficiencyUnit.MilePerUkGallon)] [InlineData("en-US", "mpg (U.S.)", FuelEfficiencyUnit.MilePerUsGallon)] - public void TryParseUnitWithCulture(string culture, string abbreviation, FuelEfficiencyUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, FuelEfficiencyUnit expectedUnit) { Assert.True(FuelEfficiency.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out FuelEfficiencyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs index 8271206842..a9d11fe33c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatFluxTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -624,10 +625,39 @@ public void TryParse() [InlineData("W/ft²", HeatFluxUnit.WattPerSquareFoot)] [InlineData("W/in²", HeatFluxUnit.WattPerSquareInch)] [InlineData("W/m²", HeatFluxUnit.WattPerSquareMeter)] - public void ParseUnit(string abbreviation, HeatFluxUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, HeatFluxUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - HeatFluxUnit parsedUnit = HeatFlux.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + HeatFluxUnit parsedUnit = HeatFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("BTU/(h·ft²)", HeatFluxUnit.BtuPerHourSquareFoot)] + [InlineData("BTU/(min·ft²)", HeatFluxUnit.BtuPerMinuteSquareFoot)] + [InlineData("BTU/(s·ft²)", HeatFluxUnit.BtuPerSecondSquareFoot)] + [InlineData("BTU/(s·in²)", HeatFluxUnit.BtuPerSecondSquareInch)] + [InlineData("cal/(s·cm²)", HeatFluxUnit.CaloriePerSecondSquareCentimeter)] + [InlineData("cW/m²", HeatFluxUnit.CentiwattPerSquareMeter)] + [InlineData("dW/m²", HeatFluxUnit.DeciwattPerSquareMeter)] + [InlineData("kcal/(h·m²)", HeatFluxUnit.KilocaloriePerHourSquareMeter)] + [InlineData("kcal/(s·cm²)", HeatFluxUnit.KilocaloriePerSecondSquareCentimeter)] + [InlineData("kW/m²", HeatFluxUnit.KilowattPerSquareMeter)] + [InlineData("µW/m²", HeatFluxUnit.MicrowattPerSquareMeter)] + [InlineData("mW/m²", HeatFluxUnit.MilliwattPerSquareMeter)] + [InlineData("nW/m²", HeatFluxUnit.NanowattPerSquareMeter)] + [InlineData("lbf/(ft·s)", HeatFluxUnit.PoundForcePerFootSecond)] + [InlineData("lb/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("lbm/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("W/ft²", HeatFluxUnit.WattPerSquareFoot)] + [InlineData("W/in²", HeatFluxUnit.WattPerSquareInch)] + [InlineData("W/m²", HeatFluxUnit.WattPerSquareMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, HeatFluxUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + HeatFluxUnit parsedUnit = HeatFlux.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -651,7 +681,34 @@ public void ParseUnit(string abbreviation, HeatFluxUnit expectedUnit) [InlineData("en-US", "W/ft²", HeatFluxUnit.WattPerSquareFoot)] [InlineData("en-US", "W/in²", HeatFluxUnit.WattPerSquareInch)] [InlineData("en-US", "W/m²", HeatFluxUnit.WattPerSquareMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, HeatFluxUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, HeatFluxUnit expectedUnit) + { + using var _ = new CultureScope(culture); + HeatFluxUnit parsedUnit = HeatFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "BTU/(h·ft²)", HeatFluxUnit.BtuPerHourSquareFoot)] + [InlineData("en-US", "BTU/(min·ft²)", HeatFluxUnit.BtuPerMinuteSquareFoot)] + [InlineData("en-US", "BTU/(s·ft²)", HeatFluxUnit.BtuPerSecondSquareFoot)] + [InlineData("en-US", "BTU/(s·in²)", HeatFluxUnit.BtuPerSecondSquareInch)] + [InlineData("en-US", "cal/(s·cm²)", HeatFluxUnit.CaloriePerSecondSquareCentimeter)] + [InlineData("en-US", "cW/m²", HeatFluxUnit.CentiwattPerSquareMeter)] + [InlineData("en-US", "dW/m²", HeatFluxUnit.DeciwattPerSquareMeter)] + [InlineData("en-US", "kcal/(h·m²)", HeatFluxUnit.KilocaloriePerHourSquareMeter)] + [InlineData("en-US", "kcal/(s·cm²)", HeatFluxUnit.KilocaloriePerSecondSquareCentimeter)] + [InlineData("en-US", "kW/m²", HeatFluxUnit.KilowattPerSquareMeter)] + [InlineData("en-US", "µW/m²", HeatFluxUnit.MicrowattPerSquareMeter)] + [InlineData("en-US", "mW/m²", HeatFluxUnit.MilliwattPerSquareMeter)] + [InlineData("en-US", "nW/m²", HeatFluxUnit.NanowattPerSquareMeter)] + [InlineData("en-US", "lbf/(ft·s)", HeatFluxUnit.PoundForcePerFootSecond)] + [InlineData("en-US", "lb/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("en-US", "lbm/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("en-US", "W/ft²", HeatFluxUnit.WattPerSquareFoot)] + [InlineData("en-US", "W/in²", HeatFluxUnit.WattPerSquareInch)] + [InlineData("en-US", "W/m²", HeatFluxUnit.WattPerSquareMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, HeatFluxUnit expectedUnit) { HeatFluxUnit parsedUnit = HeatFlux.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -677,9 +734,65 @@ public void ParseUnitWithCulture(string culture, string abbreviation, HeatFluxUn [InlineData("W/ft²", HeatFluxUnit.WattPerSquareFoot)] [InlineData("W/in²", HeatFluxUnit.WattPerSquareInch)] [InlineData("W/m²", HeatFluxUnit.WattPerSquareMeter)] - public void TryParseUnit(string abbreviation, HeatFluxUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, HeatFluxUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(HeatFlux.TryParseUnit(abbreviation, out HeatFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("BTU/(h·ft²)", HeatFluxUnit.BtuPerHourSquareFoot)] + [InlineData("BTU/(min·ft²)", HeatFluxUnit.BtuPerMinuteSquareFoot)] + [InlineData("BTU/(s·ft²)", HeatFluxUnit.BtuPerSecondSquareFoot)] + [InlineData("BTU/(s·in²)", HeatFluxUnit.BtuPerSecondSquareInch)] + [InlineData("cal/(s·cm²)", HeatFluxUnit.CaloriePerSecondSquareCentimeter)] + [InlineData("cW/m²", HeatFluxUnit.CentiwattPerSquareMeter)] + [InlineData("dW/m²", HeatFluxUnit.DeciwattPerSquareMeter)] + [InlineData("kcal/(h·m²)", HeatFluxUnit.KilocaloriePerHourSquareMeter)] + [InlineData("kcal/(s·cm²)", HeatFluxUnit.KilocaloriePerSecondSquareCentimeter)] + [InlineData("kW/m²", HeatFluxUnit.KilowattPerSquareMeter)] + [InlineData("µW/m²", HeatFluxUnit.MicrowattPerSquareMeter)] + [InlineData("mW/m²", HeatFluxUnit.MilliwattPerSquareMeter)] + [InlineData("nW/m²", HeatFluxUnit.NanowattPerSquareMeter)] + [InlineData("lbf/(ft·s)", HeatFluxUnit.PoundForcePerFootSecond)] + [InlineData("lb/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("lbm/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("W/ft²", HeatFluxUnit.WattPerSquareFoot)] + [InlineData("W/in²", HeatFluxUnit.WattPerSquareInch)] + [InlineData("W/m²", HeatFluxUnit.WattPerSquareMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, HeatFluxUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(HeatFlux.TryParseUnit(abbreviation, out HeatFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "BTU/(h·ft²)", HeatFluxUnit.BtuPerHourSquareFoot)] + [InlineData("en-US", "BTU/(min·ft²)", HeatFluxUnit.BtuPerMinuteSquareFoot)] + [InlineData("en-US", "BTU/(s·ft²)", HeatFluxUnit.BtuPerSecondSquareFoot)] + [InlineData("en-US", "BTU/(s·in²)", HeatFluxUnit.BtuPerSecondSquareInch)] + [InlineData("en-US", "cal/(s·cm²)", HeatFluxUnit.CaloriePerSecondSquareCentimeter)] + [InlineData("en-US", "cW/m²", HeatFluxUnit.CentiwattPerSquareMeter)] + [InlineData("en-US", "dW/m²", HeatFluxUnit.DeciwattPerSquareMeter)] + [InlineData("en-US", "kcal/(h·m²)", HeatFluxUnit.KilocaloriePerHourSquareMeter)] + [InlineData("en-US", "kcal/(s·cm²)", HeatFluxUnit.KilocaloriePerSecondSquareCentimeter)] + [InlineData("en-US", "kW/m²", HeatFluxUnit.KilowattPerSquareMeter)] + [InlineData("en-US", "µW/m²", HeatFluxUnit.MicrowattPerSquareMeter)] + [InlineData("en-US", "mW/m²", HeatFluxUnit.MilliwattPerSquareMeter)] + [InlineData("en-US", "nW/m²", HeatFluxUnit.NanowattPerSquareMeter)] + [InlineData("en-US", "lbf/(ft·s)", HeatFluxUnit.PoundForcePerFootSecond)] + [InlineData("en-US", "lb/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("en-US", "lbm/s³", HeatFluxUnit.PoundPerSecondCubed)] + [InlineData("en-US", "W/ft²", HeatFluxUnit.WattPerSquareFoot)] + [InlineData("en-US", "W/in²", HeatFluxUnit.WattPerSquareInch)] + [InlineData("en-US", "W/m²", HeatFluxUnit.WattPerSquareMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, HeatFluxUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(HeatFlux.TryParseUnit(abbreviation, out HeatFluxUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -704,7 +817,7 @@ public void TryParseUnit(string abbreviation, HeatFluxUnit expectedUnit) [InlineData("en-US", "W/ft²", HeatFluxUnit.WattPerSquareFoot)] [InlineData("en-US", "W/in²", HeatFluxUnit.WattPerSquareInch)] [InlineData("en-US", "W/m²", HeatFluxUnit.WattPerSquareMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, HeatFluxUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, HeatFluxUnit expectedUnit) { Assert.True(HeatFlux.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out HeatFluxUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs index 2096f31c94..4a0e9e8803 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/HeatTransferCoefficientTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -424,10 +425,34 @@ public void TryParse() [InlineData("kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] [InlineData("W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] [InlineData("W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] - public void ParseUnit(string abbreviation, HeatTransferCoefficientUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, HeatTransferCoefficientUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - HeatTransferCoefficientUnit parsedUnit = HeatTransferCoefficient.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + HeatTransferCoefficientUnit parsedUnit = HeatTransferCoefficient.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Btu/(h·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(ft²·h·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(hr·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(ft²·hr·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("kcal/(h·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(m²·h·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(hr·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(m²·hr·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(h·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(m²·h·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(hr·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] + [InlineData("W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, HeatTransferCoefficientUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + HeatTransferCoefficientUnit parsedUnit = HeatTransferCoefficient.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -446,7 +471,29 @@ public void ParseUnit(string abbreviation, HeatTransferCoefficientUnit expectedU [InlineData("en-US", "kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] [InlineData("en-US", "W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] [InlineData("en-US", "W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] - public void ParseUnitWithCulture(string culture, string abbreviation, HeatTransferCoefficientUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, HeatTransferCoefficientUnit expectedUnit) + { + using var _ = new CultureScope(culture); + HeatTransferCoefficientUnit parsedUnit = HeatTransferCoefficient.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Btu/(h·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(ft²·h·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(hr·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(ft²·hr·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "kcal/(h·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(m²·h·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(hr·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(m²·hr·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(h·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(m²·h·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(hr·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] + [InlineData("en-US", "W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] + public void ParseUnit_WithCulture(string culture, string abbreviation, HeatTransferCoefficientUnit expectedUnit) { HeatTransferCoefficientUnit parsedUnit = HeatTransferCoefficient.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -467,9 +514,55 @@ public void ParseUnitWithCulture(string culture, string abbreviation, HeatTransf [InlineData("kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] [InlineData("W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] [InlineData("W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] - public void TryParseUnit(string abbreviation, HeatTransferCoefficientUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, HeatTransferCoefficientUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(HeatTransferCoefficient.TryParseUnit(abbreviation, out HeatTransferCoefficientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Btu/(h·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(ft²·h·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(hr·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("Btu/(ft²·hr·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("kcal/(h·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(m²·h·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(hr·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kcal/(m²·hr·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(h·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(m²·h·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(hr·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] + [InlineData("W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, HeatTransferCoefficientUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(HeatTransferCoefficient.TryParseUnit(abbreviation, out HeatTransferCoefficientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Btu/(h·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(ft²·h·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(hr·ft²·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "Btu/(ft²·hr·°F)", HeatTransferCoefficientUnit.BtuPerHourSquareFootDegreeFahrenheit)] + [InlineData("en-US", "kcal/(h·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(m²·h·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(hr·m²·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kcal/(m²·hr·°C)", HeatTransferCoefficientUnit.CaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(h·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(m²·h·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(hr·m²·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] + [InlineData("en-US", "W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] + [InlineData("en-US", "W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, HeatTransferCoefficientUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(HeatTransferCoefficient.TryParseUnit(abbreviation, out HeatTransferCoefficientUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -489,7 +582,7 @@ public void TryParseUnit(string abbreviation, HeatTransferCoefficientUnit expect [InlineData("en-US", "kkcal/(m²·hr·°C)", HeatTransferCoefficientUnit.KilocaloriePerHourSquareMeterDegreeCelsius)] [InlineData("en-US", "W/(m²·°C)", HeatTransferCoefficientUnit.WattPerSquareMeterCelsius)] [InlineData("en-US", "W/(m²·K)", HeatTransferCoefficientUnit.WattPerSquareMeterKelvin)] - public void TryParseUnitWithCulture(string culture, string abbreviation, HeatTransferCoefficientUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, HeatTransferCoefficientUnit expectedUnit) { Assert.True(HeatTransferCoefficient.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out HeatTransferCoefficientUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs index 2fab45a263..4a00772a89 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IlluminanceTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -262,10 +263,24 @@ public void TryParse() [InlineData("lx", IlluminanceUnit.Lux)] [InlineData("Mlx", IlluminanceUnit.Megalux)] [InlineData("mlx", IlluminanceUnit.Millilux)] - public void ParseUnit(string abbreviation, IlluminanceUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, IlluminanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - IlluminanceUnit parsedUnit = Illuminance.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + IlluminanceUnit parsedUnit = Illuminance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("klx", IlluminanceUnit.Kilolux)] + [InlineData("lx", IlluminanceUnit.Lux)] + [InlineData("Mlx", IlluminanceUnit.Megalux)] + [InlineData("mlx", IlluminanceUnit.Millilux)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, IlluminanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + IlluminanceUnit parsedUnit = Illuminance.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -274,7 +289,19 @@ public void ParseUnit(string abbreviation, IlluminanceUnit expectedUnit) [InlineData("en-US", "lx", IlluminanceUnit.Lux)] [InlineData("en-US", "Mlx", IlluminanceUnit.Megalux)] [InlineData("en-US", "mlx", IlluminanceUnit.Millilux)] - public void ParseUnitWithCulture(string culture, string abbreviation, IlluminanceUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, IlluminanceUnit expectedUnit) + { + using var _ = new CultureScope(culture); + IlluminanceUnit parsedUnit = Illuminance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "klx", IlluminanceUnit.Kilolux)] + [InlineData("en-US", "lx", IlluminanceUnit.Lux)] + [InlineData("en-US", "Mlx", IlluminanceUnit.Megalux)] + [InlineData("en-US", "mlx", IlluminanceUnit.Millilux)] + public void ParseUnit_WithCulture(string culture, string abbreviation, IlluminanceUnit expectedUnit) { IlluminanceUnit parsedUnit = Illuminance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -285,9 +312,35 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Illuminanc [InlineData("lx", IlluminanceUnit.Lux)] [InlineData("Mlx", IlluminanceUnit.Megalux)] [InlineData("mlx", IlluminanceUnit.Millilux)] - public void TryParseUnit(string abbreviation, IlluminanceUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, IlluminanceUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Illuminance.TryParseUnit(abbreviation, out IlluminanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("klx", IlluminanceUnit.Kilolux)] + [InlineData("lx", IlluminanceUnit.Lux)] + [InlineData("Mlx", IlluminanceUnit.Megalux)] + [InlineData("mlx", IlluminanceUnit.Millilux)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, IlluminanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Illuminance.TryParseUnit(abbreviation, out IlluminanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "klx", IlluminanceUnit.Kilolux)] + [InlineData("en-US", "lx", IlluminanceUnit.Lux)] + [InlineData("en-US", "Mlx", IlluminanceUnit.Megalux)] + [InlineData("en-US", "mlx", IlluminanceUnit.Millilux)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, IlluminanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Illuminance.TryParseUnit(abbreviation, out IlluminanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -297,7 +350,7 @@ public void TryParseUnit(string abbreviation, IlluminanceUnit expectedUnit) [InlineData("en-US", "lx", IlluminanceUnit.Lux)] [InlineData("en-US", "Mlx", IlluminanceUnit.Megalux)] [InlineData("en-US", "mlx", IlluminanceUnit.Millilux)] - public void TryParseUnitWithCulture(string culture, string abbreviation, IlluminanceUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, IlluminanceUnit expectedUnit) { Assert.True(Illuminance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out IlluminanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs index 3227ff5ba6..07ad5ae323 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ImpulseTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -478,10 +479,33 @@ public void TryParse() [InlineData("lb·ft/s", ImpulseUnit.PoundFootPerSecond)] [InlineData("lbf·s", ImpulseUnit.PoundForceSecond)] [InlineData("slug·ft/s", ImpulseUnit.SlugFootPerSecond)] - public void ParseUnit(string abbreviation, ImpulseUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ImpulseUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ImpulseUnit parsedUnit = Impulse.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ImpulseUnit parsedUnit = Impulse.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cN·s", ImpulseUnit.CentinewtonSecond)] + [InlineData("daN·s", ImpulseUnit.DecanewtonSecond)] + [InlineData("dN·s", ImpulseUnit.DecinewtonSecond)] + [InlineData("kg·m/s", ImpulseUnit.KilogramMeterPerSecond)] + [InlineData("kN·s", ImpulseUnit.KilonewtonSecond)] + [InlineData("MN·s", ImpulseUnit.MeganewtonSecond)] + [InlineData("µN·s", ImpulseUnit.MicronewtonSecond)] + [InlineData("mN·s", ImpulseUnit.MillinewtonSecond)] + [InlineData("nN·s", ImpulseUnit.NanonewtonSecond)] + [InlineData("N·s", ImpulseUnit.NewtonSecond)] + [InlineData("lb·ft/s", ImpulseUnit.PoundFootPerSecond)] + [InlineData("lbf·s", ImpulseUnit.PoundForceSecond)] + [InlineData("slug·ft/s", ImpulseUnit.SlugFootPerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ImpulseUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ImpulseUnit parsedUnit = Impulse.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -499,7 +523,28 @@ public void ParseUnit(string abbreviation, ImpulseUnit expectedUnit) [InlineData("en-US", "lb·ft/s", ImpulseUnit.PoundFootPerSecond)] [InlineData("en-US", "lbf·s", ImpulseUnit.PoundForceSecond)] [InlineData("en-US", "slug·ft/s", ImpulseUnit.SlugFootPerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, ImpulseUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ImpulseUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ImpulseUnit parsedUnit = Impulse.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cN·s", ImpulseUnit.CentinewtonSecond)] + [InlineData("en-US", "daN·s", ImpulseUnit.DecanewtonSecond)] + [InlineData("en-US", "dN·s", ImpulseUnit.DecinewtonSecond)] + [InlineData("en-US", "kg·m/s", ImpulseUnit.KilogramMeterPerSecond)] + [InlineData("en-US", "kN·s", ImpulseUnit.KilonewtonSecond)] + [InlineData("en-US", "MN·s", ImpulseUnit.MeganewtonSecond)] + [InlineData("en-US", "µN·s", ImpulseUnit.MicronewtonSecond)] + [InlineData("en-US", "mN·s", ImpulseUnit.MillinewtonSecond)] + [InlineData("en-US", "nN·s", ImpulseUnit.NanonewtonSecond)] + [InlineData("en-US", "N·s", ImpulseUnit.NewtonSecond)] + [InlineData("en-US", "lb·ft/s", ImpulseUnit.PoundFootPerSecond)] + [InlineData("en-US", "lbf·s", ImpulseUnit.PoundForceSecond)] + [InlineData("en-US", "slug·ft/s", ImpulseUnit.SlugFootPerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ImpulseUnit expectedUnit) { ImpulseUnit parsedUnit = Impulse.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -519,9 +564,53 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ImpulseUni [InlineData("lb·ft/s", ImpulseUnit.PoundFootPerSecond)] [InlineData("lbf·s", ImpulseUnit.PoundForceSecond)] [InlineData("slug·ft/s", ImpulseUnit.SlugFootPerSecond)] - public void TryParseUnit(string abbreviation, ImpulseUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ImpulseUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Impulse.TryParseUnit(abbreviation, out ImpulseUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cN·s", ImpulseUnit.CentinewtonSecond)] + [InlineData("daN·s", ImpulseUnit.DecanewtonSecond)] + [InlineData("dN·s", ImpulseUnit.DecinewtonSecond)] + [InlineData("kg·m/s", ImpulseUnit.KilogramMeterPerSecond)] + [InlineData("kN·s", ImpulseUnit.KilonewtonSecond)] + [InlineData("MN·s", ImpulseUnit.MeganewtonSecond)] + [InlineData("µN·s", ImpulseUnit.MicronewtonSecond)] + [InlineData("mN·s", ImpulseUnit.MillinewtonSecond)] + [InlineData("nN·s", ImpulseUnit.NanonewtonSecond)] + [InlineData("N·s", ImpulseUnit.NewtonSecond)] + [InlineData("lb·ft/s", ImpulseUnit.PoundFootPerSecond)] + [InlineData("lbf·s", ImpulseUnit.PoundForceSecond)] + [InlineData("slug·ft/s", ImpulseUnit.SlugFootPerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ImpulseUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Impulse.TryParseUnit(abbreviation, out ImpulseUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cN·s", ImpulseUnit.CentinewtonSecond)] + [InlineData("en-US", "daN·s", ImpulseUnit.DecanewtonSecond)] + [InlineData("en-US", "dN·s", ImpulseUnit.DecinewtonSecond)] + [InlineData("en-US", "kg·m/s", ImpulseUnit.KilogramMeterPerSecond)] + [InlineData("en-US", "kN·s", ImpulseUnit.KilonewtonSecond)] + [InlineData("en-US", "MN·s", ImpulseUnit.MeganewtonSecond)] + [InlineData("en-US", "µN·s", ImpulseUnit.MicronewtonSecond)] + [InlineData("en-US", "mN·s", ImpulseUnit.MillinewtonSecond)] + [InlineData("en-US", "nN·s", ImpulseUnit.NanonewtonSecond)] + [InlineData("en-US", "N·s", ImpulseUnit.NewtonSecond)] + [InlineData("en-US", "lb·ft/s", ImpulseUnit.PoundFootPerSecond)] + [InlineData("en-US", "lbf·s", ImpulseUnit.PoundForceSecond)] + [InlineData("en-US", "slug·ft/s", ImpulseUnit.SlugFootPerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ImpulseUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Impulse.TryParseUnit(abbreviation, out ImpulseUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -540,7 +629,7 @@ public void TryParseUnit(string abbreviation, ImpulseUnit expectedUnit) [InlineData("en-US", "lb·ft/s", ImpulseUnit.PoundFootPerSecond)] [InlineData("en-US", "lbf·s", ImpulseUnit.PoundForceSecond)] [InlineData("en-US", "slug·ft/s", ImpulseUnit.SlugFootPerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ImpulseUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ImpulseUnit expectedUnit) { Assert.True(Impulse.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ImpulseUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs index ce50c14d79..3ebc780ff2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/InformationTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -646,10 +647,46 @@ public void TryParse() [InlineData("TiB", InformationUnit.Tebibyte)] [InlineData("Tb", InformationUnit.Terabit)] [InlineData("TB", InformationUnit.Terabyte)] - public void ParseUnit(string abbreviation, InformationUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, InformationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - InformationUnit parsedUnit = Information.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + InformationUnit parsedUnit = Information.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("b", InformationUnit.Bit)] + [InlineData("B", InformationUnit.Byte)] + [InlineData("Eb", InformationUnit.Exabit)] + [InlineData("EB", InformationUnit.Exabyte)] + [InlineData("Eib", InformationUnit.Exbibit)] + [InlineData("EiB", InformationUnit.Exbibyte)] + [InlineData("Gib", InformationUnit.Gibibit)] + [InlineData("GiB", InformationUnit.Gibibyte)] + [InlineData("Gb", InformationUnit.Gigabit)] + [InlineData("GB", InformationUnit.Gigabyte)] + [InlineData("Kib", InformationUnit.Kibibit)] + [InlineData("KiB", InformationUnit.Kibibyte)] + [InlineData("kb", InformationUnit.Kilobit)] + [InlineData("kB", InformationUnit.Kilobyte)] + [InlineData("Mib", InformationUnit.Mebibit)] + [InlineData("MiB", InformationUnit.Mebibyte)] + [InlineData("Mb", InformationUnit.Megabit)] + [InlineData("MB", InformationUnit.Megabyte)] + [InlineData("Pib", InformationUnit.Pebibit)] + [InlineData("PiB", InformationUnit.Pebibyte)] + [InlineData("Pb", InformationUnit.Petabit)] + [InlineData("PB", InformationUnit.Petabyte)] + [InlineData("Tib", InformationUnit.Tebibit)] + [InlineData("TiB", InformationUnit.Tebibyte)] + [InlineData("Tb", InformationUnit.Terabit)] + [InlineData("TB", InformationUnit.Terabyte)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, InformationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + InformationUnit parsedUnit = Information.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -680,7 +717,41 @@ public void ParseUnit(string abbreviation, InformationUnit expectedUnit) [InlineData("en-US", "TiB", InformationUnit.Tebibyte)] [InlineData("en-US", "Tb", InformationUnit.Terabit)] [InlineData("en-US", "TB", InformationUnit.Terabyte)] - public void ParseUnitWithCulture(string culture, string abbreviation, InformationUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, InformationUnit expectedUnit) + { + using var _ = new CultureScope(culture); + InformationUnit parsedUnit = Information.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "b", InformationUnit.Bit)] + [InlineData("en-US", "B", InformationUnit.Byte)] + [InlineData("en-US", "Eb", InformationUnit.Exabit)] + [InlineData("en-US", "EB", InformationUnit.Exabyte)] + [InlineData("en-US", "Eib", InformationUnit.Exbibit)] + [InlineData("en-US", "EiB", InformationUnit.Exbibyte)] + [InlineData("en-US", "Gib", InformationUnit.Gibibit)] + [InlineData("en-US", "GiB", InformationUnit.Gibibyte)] + [InlineData("en-US", "Gb", InformationUnit.Gigabit)] + [InlineData("en-US", "GB", InformationUnit.Gigabyte)] + [InlineData("en-US", "Kib", InformationUnit.Kibibit)] + [InlineData("en-US", "KiB", InformationUnit.Kibibyte)] + [InlineData("en-US", "kb", InformationUnit.Kilobit)] + [InlineData("en-US", "kB", InformationUnit.Kilobyte)] + [InlineData("en-US", "Mib", InformationUnit.Mebibit)] + [InlineData("en-US", "MiB", InformationUnit.Mebibyte)] + [InlineData("en-US", "Mb", InformationUnit.Megabit)] + [InlineData("en-US", "MB", InformationUnit.Megabyte)] + [InlineData("en-US", "Pib", InformationUnit.Pebibit)] + [InlineData("en-US", "PiB", InformationUnit.Pebibyte)] + [InlineData("en-US", "Pb", InformationUnit.Petabit)] + [InlineData("en-US", "PB", InformationUnit.Petabyte)] + [InlineData("en-US", "Tib", InformationUnit.Tebibit)] + [InlineData("en-US", "TiB", InformationUnit.Tebibyte)] + [InlineData("en-US", "Tb", InformationUnit.Terabit)] + [InlineData("en-US", "TB", InformationUnit.Terabyte)] + public void ParseUnit_WithCulture(string culture, string abbreviation, InformationUnit expectedUnit) { InformationUnit parsedUnit = Information.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -713,9 +784,79 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Informatio [InlineData("TiB", InformationUnit.Tebibyte)] [InlineData("Tb", InformationUnit.Terabit)] [InlineData("TB", InformationUnit.Terabyte)] - public void TryParseUnit(string abbreviation, InformationUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, InformationUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Information.TryParseUnit(abbreviation, out InformationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("b", InformationUnit.Bit)] + [InlineData("B", InformationUnit.Byte)] + [InlineData("Eb", InformationUnit.Exabit)] + [InlineData("EB", InformationUnit.Exabyte)] + [InlineData("Eib", InformationUnit.Exbibit)] + [InlineData("EiB", InformationUnit.Exbibyte)] + [InlineData("Gib", InformationUnit.Gibibit)] + [InlineData("GiB", InformationUnit.Gibibyte)] + [InlineData("Gb", InformationUnit.Gigabit)] + [InlineData("GB", InformationUnit.Gigabyte)] + [InlineData("Kib", InformationUnit.Kibibit)] + [InlineData("KiB", InformationUnit.Kibibyte)] + [InlineData("kb", InformationUnit.Kilobit)] + [InlineData("kB", InformationUnit.Kilobyte)] + [InlineData("Mib", InformationUnit.Mebibit)] + [InlineData("MiB", InformationUnit.Mebibyte)] + [InlineData("Mb", InformationUnit.Megabit)] + [InlineData("MB", InformationUnit.Megabyte)] + [InlineData("Pib", InformationUnit.Pebibit)] + [InlineData("PiB", InformationUnit.Pebibyte)] + [InlineData("Pb", InformationUnit.Petabit)] + [InlineData("PB", InformationUnit.Petabyte)] + [InlineData("Tib", InformationUnit.Tebibit)] + [InlineData("TiB", InformationUnit.Tebibyte)] + [InlineData("Tb", InformationUnit.Terabit)] + [InlineData("TB", InformationUnit.Terabyte)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, InformationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Information.TryParseUnit(abbreviation, out InformationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "b", InformationUnit.Bit)] + [InlineData("en-US", "B", InformationUnit.Byte)] + [InlineData("en-US", "Eb", InformationUnit.Exabit)] + [InlineData("en-US", "EB", InformationUnit.Exabyte)] + [InlineData("en-US", "Eib", InformationUnit.Exbibit)] + [InlineData("en-US", "EiB", InformationUnit.Exbibyte)] + [InlineData("en-US", "Gib", InformationUnit.Gibibit)] + [InlineData("en-US", "GiB", InformationUnit.Gibibyte)] + [InlineData("en-US", "Gb", InformationUnit.Gigabit)] + [InlineData("en-US", "GB", InformationUnit.Gigabyte)] + [InlineData("en-US", "Kib", InformationUnit.Kibibit)] + [InlineData("en-US", "KiB", InformationUnit.Kibibyte)] + [InlineData("en-US", "kb", InformationUnit.Kilobit)] + [InlineData("en-US", "kB", InformationUnit.Kilobyte)] + [InlineData("en-US", "Mib", InformationUnit.Mebibit)] + [InlineData("en-US", "MiB", InformationUnit.Mebibyte)] + [InlineData("en-US", "Mb", InformationUnit.Megabit)] + [InlineData("en-US", "MB", InformationUnit.Megabyte)] + [InlineData("en-US", "Pib", InformationUnit.Pebibit)] + [InlineData("en-US", "PiB", InformationUnit.Pebibyte)] + [InlineData("en-US", "Pb", InformationUnit.Petabit)] + [InlineData("en-US", "PB", InformationUnit.Petabyte)] + [InlineData("en-US", "Tib", InformationUnit.Tebibit)] + [InlineData("en-US", "TiB", InformationUnit.Tebibyte)] + [InlineData("en-US", "Tb", InformationUnit.Terabit)] + [InlineData("en-US", "TB", InformationUnit.Terabyte)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, InformationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Information.TryParseUnit(abbreviation, out InformationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -747,7 +888,7 @@ public void TryParseUnit(string abbreviation, InformationUnit expectedUnit) [InlineData("en-US", "TiB", InformationUnit.Tebibyte)] [InlineData("en-US", "Tb", InformationUnit.Terabit)] [InlineData("en-US", "TB", InformationUnit.Terabyte)] - public void TryParseUnitWithCulture(string culture, string abbreviation, InformationUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, InformationUnit expectedUnit) { Assert.True(Information.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out InformationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs index 06fb0ec8be..392eb10c0d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradianceTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -490,10 +491,34 @@ public void TryParse() [InlineData("pW/m²", IrradianceUnit.PicowattPerSquareMeter)] [InlineData("W/cm²", IrradianceUnit.WattPerSquareCentimeter)] [InlineData("W/m²", IrradianceUnit.WattPerSquareMeter)] - public void ParseUnit(string abbreviation, IrradianceUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, IrradianceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - IrradianceUnit parsedUnit = Irradiance.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + IrradianceUnit parsedUnit = Irradiance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kW/cm²", IrradianceUnit.KilowattPerSquareCentimeter)] + [InlineData("kW/m²", IrradianceUnit.KilowattPerSquareMeter)] + [InlineData("MW/cm²", IrradianceUnit.MegawattPerSquareCentimeter)] + [InlineData("MW/m²", IrradianceUnit.MegawattPerSquareMeter)] + [InlineData("µW/cm²", IrradianceUnit.MicrowattPerSquareCentimeter)] + [InlineData("µW/m²", IrradianceUnit.MicrowattPerSquareMeter)] + [InlineData("mW/cm²", IrradianceUnit.MilliwattPerSquareCentimeter)] + [InlineData("mW/m²", IrradianceUnit.MilliwattPerSquareMeter)] + [InlineData("nW/cm²", IrradianceUnit.NanowattPerSquareCentimeter)] + [InlineData("nW/m²", IrradianceUnit.NanowattPerSquareMeter)] + [InlineData("pW/cm²", IrradianceUnit.PicowattPerSquareCentimeter)] + [InlineData("pW/m²", IrradianceUnit.PicowattPerSquareMeter)] + [InlineData("W/cm²", IrradianceUnit.WattPerSquareCentimeter)] + [InlineData("W/m²", IrradianceUnit.WattPerSquareMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, IrradianceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + IrradianceUnit parsedUnit = Irradiance.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -512,7 +537,29 @@ public void ParseUnit(string abbreviation, IrradianceUnit expectedUnit) [InlineData("en-US", "pW/m²", IrradianceUnit.PicowattPerSquareMeter)] [InlineData("en-US", "W/cm²", IrradianceUnit.WattPerSquareCentimeter)] [InlineData("en-US", "W/m²", IrradianceUnit.WattPerSquareMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, IrradianceUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, IrradianceUnit expectedUnit) + { + using var _ = new CultureScope(culture); + IrradianceUnit parsedUnit = Irradiance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kW/cm²", IrradianceUnit.KilowattPerSquareCentimeter)] + [InlineData("en-US", "kW/m²", IrradianceUnit.KilowattPerSquareMeter)] + [InlineData("en-US", "MW/cm²", IrradianceUnit.MegawattPerSquareCentimeter)] + [InlineData("en-US", "MW/m²", IrradianceUnit.MegawattPerSquareMeter)] + [InlineData("en-US", "µW/cm²", IrradianceUnit.MicrowattPerSquareCentimeter)] + [InlineData("en-US", "µW/m²", IrradianceUnit.MicrowattPerSquareMeter)] + [InlineData("en-US", "mW/cm²", IrradianceUnit.MilliwattPerSquareCentimeter)] + [InlineData("en-US", "mW/m²", IrradianceUnit.MilliwattPerSquareMeter)] + [InlineData("en-US", "nW/cm²", IrradianceUnit.NanowattPerSquareCentimeter)] + [InlineData("en-US", "nW/m²", IrradianceUnit.NanowattPerSquareMeter)] + [InlineData("en-US", "pW/cm²", IrradianceUnit.PicowattPerSquareCentimeter)] + [InlineData("en-US", "pW/m²", IrradianceUnit.PicowattPerSquareMeter)] + [InlineData("en-US", "W/cm²", IrradianceUnit.WattPerSquareCentimeter)] + [InlineData("en-US", "W/m²", IrradianceUnit.WattPerSquareMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, IrradianceUnit expectedUnit) { IrradianceUnit parsedUnit = Irradiance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -533,9 +580,55 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Irradiance [InlineData("pW/m²", IrradianceUnit.PicowattPerSquareMeter)] [InlineData("W/cm²", IrradianceUnit.WattPerSquareCentimeter)] [InlineData("W/m²", IrradianceUnit.WattPerSquareMeter)] - public void TryParseUnit(string abbreviation, IrradianceUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, IrradianceUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Irradiance.TryParseUnit(abbreviation, out IrradianceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kW/cm²", IrradianceUnit.KilowattPerSquareCentimeter)] + [InlineData("kW/m²", IrradianceUnit.KilowattPerSquareMeter)] + [InlineData("MW/cm²", IrradianceUnit.MegawattPerSquareCentimeter)] + [InlineData("MW/m²", IrradianceUnit.MegawattPerSquareMeter)] + [InlineData("µW/cm²", IrradianceUnit.MicrowattPerSquareCentimeter)] + [InlineData("µW/m²", IrradianceUnit.MicrowattPerSquareMeter)] + [InlineData("mW/cm²", IrradianceUnit.MilliwattPerSquareCentimeter)] + [InlineData("mW/m²", IrradianceUnit.MilliwattPerSquareMeter)] + [InlineData("nW/cm²", IrradianceUnit.NanowattPerSquareCentimeter)] + [InlineData("nW/m²", IrradianceUnit.NanowattPerSquareMeter)] + [InlineData("pW/cm²", IrradianceUnit.PicowattPerSquareCentimeter)] + [InlineData("pW/m²", IrradianceUnit.PicowattPerSquareMeter)] + [InlineData("W/cm²", IrradianceUnit.WattPerSquareCentimeter)] + [InlineData("W/m²", IrradianceUnit.WattPerSquareMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, IrradianceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Irradiance.TryParseUnit(abbreviation, out IrradianceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kW/cm²", IrradianceUnit.KilowattPerSquareCentimeter)] + [InlineData("en-US", "kW/m²", IrradianceUnit.KilowattPerSquareMeter)] + [InlineData("en-US", "MW/cm²", IrradianceUnit.MegawattPerSquareCentimeter)] + [InlineData("en-US", "MW/m²", IrradianceUnit.MegawattPerSquareMeter)] + [InlineData("en-US", "µW/cm²", IrradianceUnit.MicrowattPerSquareCentimeter)] + [InlineData("en-US", "µW/m²", IrradianceUnit.MicrowattPerSquareMeter)] + [InlineData("en-US", "mW/cm²", IrradianceUnit.MilliwattPerSquareCentimeter)] + [InlineData("en-US", "mW/m²", IrradianceUnit.MilliwattPerSquareMeter)] + [InlineData("en-US", "nW/cm²", IrradianceUnit.NanowattPerSquareCentimeter)] + [InlineData("en-US", "nW/m²", IrradianceUnit.NanowattPerSquareMeter)] + [InlineData("en-US", "pW/cm²", IrradianceUnit.PicowattPerSquareCentimeter)] + [InlineData("en-US", "pW/m²", IrradianceUnit.PicowattPerSquareMeter)] + [InlineData("en-US", "W/cm²", IrradianceUnit.WattPerSquareCentimeter)] + [InlineData("en-US", "W/m²", IrradianceUnit.WattPerSquareMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, IrradianceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Irradiance.TryParseUnit(abbreviation, out IrradianceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -555,7 +648,7 @@ public void TryParseUnit(string abbreviation, IrradianceUnit expectedUnit) [InlineData("en-US", "pW/m²", IrradianceUnit.PicowattPerSquareMeter)] [InlineData("en-US", "W/cm²", IrradianceUnit.WattPerSquareCentimeter)] [InlineData("en-US", "W/m²", IrradianceUnit.WattPerSquareMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, IrradianceUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, IrradianceUnit expectedUnit) { Assert.True(Irradiance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out IrradianceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs index 1f35081571..757ffe7513 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/IrradiationTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -394,10 +395,29 @@ public void TryParse() [InlineData("kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] [InlineData("mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] [InlineData("Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] - public void ParseUnit(string abbreviation, IrradiationUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, IrradiationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - IrradiationUnit parsedUnit = Irradiation.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + IrradiationUnit parsedUnit = Irradiation.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Btu/ft²", IrradiationUnit.BtuPerSquareFoot)] + [InlineData("J/cm²", IrradiationUnit.JoulePerSquareCentimeter)] + [InlineData("J/m²", IrradiationUnit.JoulePerSquareMeter)] + [InlineData("J/mm²", IrradiationUnit.JoulePerSquareMillimeter)] + [InlineData("kBtu/ft²", IrradiationUnit.KilobtuPerSquareFoot)] + [InlineData("kJ/m²", IrradiationUnit.KilojoulePerSquareMeter)] + [InlineData("kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] + [InlineData("mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] + [InlineData("Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, IrradiationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + IrradiationUnit parsedUnit = Irradiation.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -411,7 +431,24 @@ public void ParseUnit(string abbreviation, IrradiationUnit expectedUnit) [InlineData("en-US", "kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] [InlineData("en-US", "mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] [InlineData("en-US", "Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, IrradiationUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, IrradiationUnit expectedUnit) + { + using var _ = new CultureScope(culture); + IrradiationUnit parsedUnit = Irradiation.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Btu/ft²", IrradiationUnit.BtuPerSquareFoot)] + [InlineData("en-US", "J/cm²", IrradiationUnit.JoulePerSquareCentimeter)] + [InlineData("en-US", "J/m²", IrradiationUnit.JoulePerSquareMeter)] + [InlineData("en-US", "J/mm²", IrradiationUnit.JoulePerSquareMillimeter)] + [InlineData("en-US", "kBtu/ft²", IrradiationUnit.KilobtuPerSquareFoot)] + [InlineData("en-US", "kJ/m²", IrradiationUnit.KilojoulePerSquareMeter)] + [InlineData("en-US", "kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] + [InlineData("en-US", "mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] + [InlineData("en-US", "Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, IrradiationUnit expectedUnit) { IrradiationUnit parsedUnit = Irradiation.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -427,9 +464,45 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Irradiatio [InlineData("kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] [InlineData("mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] [InlineData("Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] - public void TryParseUnit(string abbreviation, IrradiationUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, IrradiationUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Irradiation.TryParseUnit(abbreviation, out IrradiationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Btu/ft²", IrradiationUnit.BtuPerSquareFoot)] + [InlineData("J/cm²", IrradiationUnit.JoulePerSquareCentimeter)] + [InlineData("J/m²", IrradiationUnit.JoulePerSquareMeter)] + [InlineData("J/mm²", IrradiationUnit.JoulePerSquareMillimeter)] + [InlineData("kBtu/ft²", IrradiationUnit.KilobtuPerSquareFoot)] + [InlineData("kJ/m²", IrradiationUnit.KilojoulePerSquareMeter)] + [InlineData("kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] + [InlineData("mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] + [InlineData("Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, IrradiationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Irradiation.TryParseUnit(abbreviation, out IrradiationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Btu/ft²", IrradiationUnit.BtuPerSquareFoot)] + [InlineData("en-US", "J/cm²", IrradiationUnit.JoulePerSquareCentimeter)] + [InlineData("en-US", "J/m²", IrradiationUnit.JoulePerSquareMeter)] + [InlineData("en-US", "J/mm²", IrradiationUnit.JoulePerSquareMillimeter)] + [InlineData("en-US", "kBtu/ft²", IrradiationUnit.KilobtuPerSquareFoot)] + [InlineData("en-US", "kJ/m²", IrradiationUnit.KilojoulePerSquareMeter)] + [InlineData("en-US", "kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] + [InlineData("en-US", "mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] + [InlineData("en-US", "Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, IrradiationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Irradiation.TryParseUnit(abbreviation, out IrradiationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -444,7 +517,7 @@ public void TryParseUnit(string abbreviation, IrradiationUnit expectedUnit) [InlineData("en-US", "kWh/m²", IrradiationUnit.KilowattHourPerSquareMeter)] [InlineData("en-US", "mJ/cm²", IrradiationUnit.MillijoulePerSquareCentimeter)] [InlineData("en-US", "Wh/m²", IrradiationUnit.WattHourPerSquareMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, IrradiationUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, IrradiationUnit expectedUnit) { Assert.True(Irradiation.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out IrradiationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs index 133edd0827..b1177c5605 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/JerkTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -585,10 +586,61 @@ public void TryParse() [InlineData("mg/s", JerkUnit.MillistandardGravitiesPerSecond)] [InlineData("nm/s³", JerkUnit.NanometerPerSecondCubed)] [InlineData("g/s", JerkUnit.StandardGravitiesPerSecond)] - public void ParseUnit(string abbreviation, JerkUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, JerkUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - JerkUnit parsedUnit = Jerk.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + JerkUnit parsedUnit = Jerk.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm/s³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("dm/s³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("ft/s³", JerkUnit.FootPerSecondCubed)] + [InlineData("in/s³", JerkUnit.InchPerSecondCubed)] + [InlineData("km/s³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("m/s³", JerkUnit.MeterPerSecondCubed)] + [InlineData("µm/s³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("mm/s³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("mg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("nm/s³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("g/s", JerkUnit.StandardGravitiesPerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, JerkUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + JerkUnit parsedUnit = Jerk.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm/s³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("en-US", "dm/s³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("en-US", "ft/s³", JerkUnit.FootPerSecondCubed)] + [InlineData("en-US", "in/s³", JerkUnit.InchPerSecondCubed)] + [InlineData("en-US", "km/s³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("en-US", "m/s³", JerkUnit.MeterPerSecondCubed)] + [InlineData("en-US", "µm/s³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("en-US", "mm/s³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("en-US", "mg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("en-US", "nm/s³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("en-US", "g/s", JerkUnit.StandardGravitiesPerSecond)] + [InlineData("ru-RU", "см/с³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("ru-RU", "дм/с³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("ru-RU", "фут/с³", JerkUnit.FootPerSecondCubed)] + [InlineData("ru-RU", "дюйм/с³", JerkUnit.InchPerSecondCubed)] + [InlineData("ru-RU", "км/с³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("ru-RU", "м/с³", JerkUnit.MeterPerSecondCubed)] + [InlineData("ru-RU", "мкм/с³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("ru-RU", "мм/с³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("ru-RU", "мg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("ru-RU", "нм/с³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("ru-RU", "g/s", JerkUnit.StandardGravitiesPerSecond)] + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, JerkUnit expectedUnit) + { + using var _ = new CultureScope(culture); + JerkUnit parsedUnit = Jerk.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -615,7 +667,7 @@ public void ParseUnit(string abbreviation, JerkUnit expectedUnit) [InlineData("ru-RU", "мg/s", JerkUnit.MillistandardGravitiesPerSecond)] [InlineData("ru-RU", "нм/с³", JerkUnit.NanometerPerSecondCubed)] [InlineData("ru-RU", "g/s", JerkUnit.StandardGravitiesPerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, JerkUnit expectedUnit) + public void ParseUnit_WithCulture(string culture, string abbreviation, JerkUnit expectedUnit) { JerkUnit parsedUnit = Jerk.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -633,9 +685,60 @@ public void ParseUnitWithCulture(string culture, string abbreviation, JerkUnit e [InlineData("mg/s", JerkUnit.MillistandardGravitiesPerSecond)] [InlineData("nm/s³", JerkUnit.NanometerPerSecondCubed)] [InlineData("g/s", JerkUnit.StandardGravitiesPerSecond)] - public void TryParseUnit(string abbreviation, JerkUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, JerkUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Jerk.TryParseUnit(abbreviation, out JerkUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm/s³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("dm/s³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("ft/s³", JerkUnit.FootPerSecondCubed)] + [InlineData("in/s³", JerkUnit.InchPerSecondCubed)] + [InlineData("km/s³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("m/s³", JerkUnit.MeterPerSecondCubed)] + [InlineData("µm/s³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("mm/s³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("mg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("nm/s³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("g/s", JerkUnit.StandardGravitiesPerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, JerkUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Jerk.TryParseUnit(abbreviation, out JerkUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm/s³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("en-US", "dm/s³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("en-US", "ft/s³", JerkUnit.FootPerSecondCubed)] + [InlineData("en-US", "in/s³", JerkUnit.InchPerSecondCubed)] + [InlineData("en-US", "km/s³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("en-US", "m/s³", JerkUnit.MeterPerSecondCubed)] + [InlineData("en-US", "µm/s³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("en-US", "mm/s³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("en-US", "mg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("en-US", "nm/s³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("en-US", "g/s", JerkUnit.StandardGravitiesPerSecond)] + [InlineData("ru-RU", "см/с³", JerkUnit.CentimeterPerSecondCubed)] + [InlineData("ru-RU", "дм/с³", JerkUnit.DecimeterPerSecondCubed)] + [InlineData("ru-RU", "фут/с³", JerkUnit.FootPerSecondCubed)] + [InlineData("ru-RU", "дюйм/с³", JerkUnit.InchPerSecondCubed)] + [InlineData("ru-RU", "км/с³", JerkUnit.KilometerPerSecondCubed)] + [InlineData("ru-RU", "м/с³", JerkUnit.MeterPerSecondCubed)] + [InlineData("ru-RU", "мкм/с³", JerkUnit.MicrometerPerSecondCubed)] + [InlineData("ru-RU", "мм/с³", JerkUnit.MillimeterPerSecondCubed)] + [InlineData("ru-RU", "мg/s", JerkUnit.MillistandardGravitiesPerSecond)] + [InlineData("ru-RU", "нм/с³", JerkUnit.NanometerPerSecondCubed)] + [InlineData("ru-RU", "g/s", JerkUnit.StandardGravitiesPerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, JerkUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Jerk.TryParseUnit(abbreviation, out JerkUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -663,7 +766,7 @@ public void TryParseUnit(string abbreviation, JerkUnit expectedUnit) [InlineData("ru-RU", "мg/s", JerkUnit.MillistandardGravitiesPerSecond)] [InlineData("ru-RU", "нм/с³", JerkUnit.NanometerPerSecondCubed)] [InlineData("ru-RU", "g/s", JerkUnit.StandardGravitiesPerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, JerkUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, JerkUnit expectedUnit) { Assert.True(Jerk.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out JerkUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs index 17ce47c442..ea2bfa72dd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/KinematicViscosityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -498,10 +499,29 @@ public void TryParse() [InlineData("ft²/s", KinematicViscosityUnit.SquareFootPerSecond)] [InlineData("m²/s", KinematicViscosityUnit.SquareMeterPerSecond)] [InlineData("St", KinematicViscosityUnit.Stokes)] - public void ParseUnit(string abbreviation, KinematicViscosityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, KinematicViscosityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - KinematicViscosityUnit parsedUnit = KinematicViscosity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + KinematicViscosityUnit parsedUnit = KinematicViscosity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cSt", KinematicViscosityUnit.Centistokes)] + [InlineData("dSt", KinematicViscosityUnit.Decistokes)] + [InlineData("kSt", KinematicViscosityUnit.Kilostokes)] + [InlineData("µSt", KinematicViscosityUnit.Microstokes)] + [InlineData("mSt", KinematicViscosityUnit.Millistokes)] + [InlineData("nSt", KinematicViscosityUnit.Nanostokes)] + [InlineData("ft²/s", KinematicViscosityUnit.SquareFootPerSecond)] + [InlineData("m²/s", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("St", KinematicViscosityUnit.Stokes)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, KinematicViscosityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + KinematicViscosityUnit parsedUnit = KinematicViscosity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -523,7 +543,32 @@ public void ParseUnit(string abbreviation, KinematicViscosityUnit expectedUnit) [InlineData("ru-RU", "нСт", KinematicViscosityUnit.Nanostokes)] [InlineData("ru-RU", "м²/с", KinematicViscosityUnit.SquareMeterPerSecond)] [InlineData("ru-RU", "Ст", KinematicViscosityUnit.Stokes)] - public void ParseUnitWithCulture(string culture, string abbreviation, KinematicViscosityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, KinematicViscosityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + KinematicViscosityUnit parsedUnit = KinematicViscosity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cSt", KinematicViscosityUnit.Centistokes)] + [InlineData("en-US", "dSt", KinematicViscosityUnit.Decistokes)] + [InlineData("en-US", "kSt", KinematicViscosityUnit.Kilostokes)] + [InlineData("en-US", "µSt", KinematicViscosityUnit.Microstokes)] + [InlineData("en-US", "mSt", KinematicViscosityUnit.Millistokes)] + [InlineData("en-US", "nSt", KinematicViscosityUnit.Nanostokes)] + [InlineData("en-US", "ft²/s", KinematicViscosityUnit.SquareFootPerSecond)] + [InlineData("en-US", "m²/s", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("en-US", "St", KinematicViscosityUnit.Stokes)] + [InlineData("ru-RU", "сСт", KinematicViscosityUnit.Centistokes)] + [InlineData("ru-RU", "дСт", KinematicViscosityUnit.Decistokes)] + [InlineData("ru-RU", "кСт", KinematicViscosityUnit.Kilostokes)] + [InlineData("ru-RU", "мкСт", KinematicViscosityUnit.Microstokes)] + [InlineData("ru-RU", "мСт", KinematicViscosityUnit.Millistokes)] + [InlineData("ru-RU", "нСт", KinematicViscosityUnit.Nanostokes)] + [InlineData("ru-RU", "м²/с", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("ru-RU", "Ст", KinematicViscosityUnit.Stokes)] + public void ParseUnit_WithCulture(string culture, string abbreviation, KinematicViscosityUnit expectedUnit) { KinematicViscosityUnit parsedUnit = KinematicViscosity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -539,9 +584,53 @@ public void ParseUnitWithCulture(string culture, string abbreviation, KinematicV [InlineData("ft²/s", KinematicViscosityUnit.SquareFootPerSecond)] [InlineData("m²/s", KinematicViscosityUnit.SquareMeterPerSecond)] [InlineData("St", KinematicViscosityUnit.Stokes)] - public void TryParseUnit(string abbreviation, KinematicViscosityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, KinematicViscosityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(KinematicViscosity.TryParseUnit(abbreviation, out KinematicViscosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cSt", KinematicViscosityUnit.Centistokes)] + [InlineData("dSt", KinematicViscosityUnit.Decistokes)] + [InlineData("kSt", KinematicViscosityUnit.Kilostokes)] + [InlineData("µSt", KinematicViscosityUnit.Microstokes)] + [InlineData("mSt", KinematicViscosityUnit.Millistokes)] + [InlineData("nSt", KinematicViscosityUnit.Nanostokes)] + [InlineData("ft²/s", KinematicViscosityUnit.SquareFootPerSecond)] + [InlineData("m²/s", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("St", KinematicViscosityUnit.Stokes)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, KinematicViscosityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(KinematicViscosity.TryParseUnit(abbreviation, out KinematicViscosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cSt", KinematicViscosityUnit.Centistokes)] + [InlineData("en-US", "dSt", KinematicViscosityUnit.Decistokes)] + [InlineData("en-US", "kSt", KinematicViscosityUnit.Kilostokes)] + [InlineData("en-US", "µSt", KinematicViscosityUnit.Microstokes)] + [InlineData("en-US", "mSt", KinematicViscosityUnit.Millistokes)] + [InlineData("en-US", "nSt", KinematicViscosityUnit.Nanostokes)] + [InlineData("en-US", "ft²/s", KinematicViscosityUnit.SquareFootPerSecond)] + [InlineData("en-US", "m²/s", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("en-US", "St", KinematicViscosityUnit.Stokes)] + [InlineData("ru-RU", "сСт", KinematicViscosityUnit.Centistokes)] + [InlineData("ru-RU", "дСт", KinematicViscosityUnit.Decistokes)] + [InlineData("ru-RU", "кСт", KinematicViscosityUnit.Kilostokes)] + [InlineData("ru-RU", "мкСт", KinematicViscosityUnit.Microstokes)] + [InlineData("ru-RU", "мСт", KinematicViscosityUnit.Millistokes)] + [InlineData("ru-RU", "нСт", KinematicViscosityUnit.Nanostokes)] + [InlineData("ru-RU", "м²/с", KinematicViscosityUnit.SquareMeterPerSecond)] + [InlineData("ru-RU", "Ст", KinematicViscosityUnit.Stokes)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, KinematicViscosityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(KinematicViscosity.TryParseUnit(abbreviation, out KinematicViscosityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -564,7 +653,7 @@ public void TryParseUnit(string abbreviation, KinematicViscosityUnit expectedUni [InlineData("ru-RU", "нСт", KinematicViscosityUnit.Nanostokes)] [InlineData("ru-RU", "м²/с", KinematicViscosityUnit.SquareMeterPerSecond)] [InlineData("ru-RU", "Ст", KinematicViscosityUnit.Stokes)] - public void TryParseUnitWithCulture(string culture, string abbreviation, KinematicViscosityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, KinematicViscosityUnit expectedUnit) { Assert.True(KinematicViscosity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out KinematicViscosityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs index 7846d8d747..99aa4178cb 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LeakRateTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -250,10 +251,23 @@ public void TryParse() [InlineData("mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] [InlineData("Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] [InlineData("Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] - public void ParseUnit(string abbreviation, LeakRateUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LeakRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - LeakRateUnit parsedUnit = LeakRate.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + LeakRateUnit parsedUnit = LeakRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] + [InlineData("Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] + [InlineData("Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LeakRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + LeakRateUnit parsedUnit = LeakRate.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -261,7 +275,18 @@ public void ParseUnit(string abbreviation, LeakRateUnit expectedUnit) [InlineData("en-US", "mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] [InlineData("en-US", "Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] [InlineData("en-US", "Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, LeakRateUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, LeakRateUnit expectedUnit) + { + using var _ = new CultureScope(culture); + LeakRateUnit parsedUnit = LeakRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] + [InlineData("en-US", "Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] + [InlineData("en-US", "Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, LeakRateUnit expectedUnit) { LeakRateUnit parsedUnit = LeakRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -271,9 +296,33 @@ public void ParseUnitWithCulture(string culture, string abbreviation, LeakRateUn [InlineData("mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] [InlineData("Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] [InlineData("Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] - public void TryParseUnit(string abbreviation, LeakRateUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LeakRateUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(LeakRate.TryParseUnit(abbreviation, out LeakRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] + [InlineData("Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] + [InlineData("Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LeakRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(LeakRate.TryParseUnit(abbreviation, out LeakRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] + [InlineData("en-US", "Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] + [InlineData("en-US", "Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, LeakRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(LeakRate.TryParseUnit(abbreviation, out LeakRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -282,7 +331,7 @@ public void TryParseUnit(string abbreviation, LeakRateUnit expectedUnit) [InlineData("en-US", "mbar·l/s", LeakRateUnit.MillibarLiterPerSecond)] [InlineData("en-US", "Pa·m³/s", LeakRateUnit.PascalCubicMeterPerSecond)] [InlineData("en-US", "Torr·l/s", LeakRateUnit.TorrLiterPerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, LeakRateUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, LeakRateUnit expectedUnit) { Assert.True(LeakRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LeakRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs index 9a6e92a0df..eb18b06235 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LengthTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1786,10 +1787,68 @@ public void TryParse() [InlineData("twip", LengthUnit.Twip)] [InlineData("ftUS", LengthUnit.UsSurveyFoot)] [InlineData("yd", LengthUnit.Yard)] - public void ParseUnit(string abbreviation, LengthUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LengthUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - LengthUnit parsedUnit = Length.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + LengthUnit parsedUnit = Length.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Å", LengthUnit.Angstrom)] + [InlineData("A", LengthUnit.Angstrom)] + [InlineData("au", LengthUnit.AstronomicalUnit)] + [InlineData("ua", LengthUnit.AstronomicalUnit)] + [InlineData("cm", LengthUnit.Centimeter)] + [InlineData("ch", LengthUnit.Chain)] + [InlineData("DM", LengthUnit.DataMile)] + [InlineData("dam", LengthUnit.Decameter)] + [InlineData("dm", LengthUnit.Decimeter)] + [InlineData("fathom", LengthUnit.Fathom)] + [InlineData("fm", LengthUnit.Femtometer)] + [InlineData("ft", LengthUnit.Foot)] + [InlineData("'", LengthUnit.Foot)] + [InlineData("′", LengthUnit.Foot)] + [InlineData("Gm", LengthUnit.Gigameter)] + [InlineData("h", LengthUnit.Hand)] + [InlineData("hh", LengthUnit.Hand)] + [InlineData("hm", LengthUnit.Hectometer)] + [InlineData("in", LengthUnit.Inch)] + [InlineData("\"", LengthUnit.Inch)] + [InlineData("″", LengthUnit.Inch)] + [InlineData("kft", LengthUnit.Kilofoot)] + [InlineData("k'", LengthUnit.Kilofoot)] + [InlineData("k′", LengthUnit.Kilofoot)] + [InlineData("kly", LengthUnit.KilolightYear)] + [InlineData("km", LengthUnit.Kilometer)] + [InlineData("kpc", LengthUnit.Kiloparsec)] + [InlineData("kyd", LengthUnit.Kiloyard)] + [InlineData("ly", LengthUnit.LightYear)] + [InlineData("Mly", LengthUnit.MegalightYear)] + [InlineData("Mm", LengthUnit.Megameter)] + [InlineData("Mpc", LengthUnit.Megaparsec)] + [InlineData("m", LengthUnit.Meter)] + [InlineData("µin", LengthUnit.Microinch)] + [InlineData("µm", LengthUnit.Micrometer)] + [InlineData("mil", LengthUnit.Mil)] + [InlineData("mi", LengthUnit.Mile)] + [InlineData("mm", LengthUnit.Millimeter)] + [InlineData("nm", LengthUnit.Nanometer)] + [InlineData("NM", LengthUnit.NauticalMile)] + [InlineData("nmi", LengthUnit.NauticalMile)] + [InlineData("pc", LengthUnit.Parsec)] + [InlineData("pm", LengthUnit.Picometer)] + [InlineData("shackle", LengthUnit.Shackle)] + [InlineData("R⊙", LengthUnit.SolarRadius)] + [InlineData("twip", LengthUnit.Twip)] + [InlineData("ftUS", LengthUnit.UsSurveyFoot)] + [InlineData("yd", LengthUnit.Yard)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LengthUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + LengthUnit parsedUnit = Length.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1882,7 +1941,103 @@ public void ParseUnit(string abbreviation, LengthUnit expectedUnit) [InlineData("zh-CN", "毫米", LengthUnit.Millimeter)] [InlineData("zh-CN", "皮米", LengthUnit.Picometer)] [InlineData("zh-CN", "码", LengthUnit.Yard)] - public void ParseUnitWithCulture(string culture, string abbreviation, LengthUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, LengthUnit expectedUnit) + { + using var _ = new CultureScope(culture); + LengthUnit parsedUnit = Length.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Å", LengthUnit.Angstrom)] + [InlineData("en-US", "A", LengthUnit.Angstrom)] + [InlineData("en-US", "au", LengthUnit.AstronomicalUnit)] + [InlineData("en-US", "ua", LengthUnit.AstronomicalUnit)] + [InlineData("en-US", "cm", LengthUnit.Centimeter)] + [InlineData("en-US", "ch", LengthUnit.Chain)] + [InlineData("en-US", "DM", LengthUnit.DataMile)] + [InlineData("en-US", "dam", LengthUnit.Decameter)] + [InlineData("en-US", "dm", LengthUnit.Decimeter)] + [InlineData("en-US", "fathom", LengthUnit.Fathom)] + [InlineData("en-US", "fm", LengthUnit.Femtometer)] + [InlineData("en-US", "ft", LengthUnit.Foot)] + [InlineData("en-US", "'", LengthUnit.Foot)] + [InlineData("en-US", "′", LengthUnit.Foot)] + [InlineData("en-US", "Gm", LengthUnit.Gigameter)] + [InlineData("en-US", "h", LengthUnit.Hand)] + [InlineData("en-US", "hh", LengthUnit.Hand)] + [InlineData("en-US", "hm", LengthUnit.Hectometer)] + [InlineData("en-US", "in", LengthUnit.Inch)] + [InlineData("en-US", "\"", LengthUnit.Inch)] + [InlineData("en-US", "″", LengthUnit.Inch)] + [InlineData("en-US", "kft", LengthUnit.Kilofoot)] + [InlineData("en-US", "k'", LengthUnit.Kilofoot)] + [InlineData("en-US", "k′", LengthUnit.Kilofoot)] + [InlineData("en-US", "kly", LengthUnit.KilolightYear)] + [InlineData("en-US", "km", LengthUnit.Kilometer)] + [InlineData("en-US", "kpc", LengthUnit.Kiloparsec)] + [InlineData("en-US", "kyd", LengthUnit.Kiloyard)] + [InlineData("en-US", "ly", LengthUnit.LightYear)] + [InlineData("en-US", "Mly", LengthUnit.MegalightYear)] + [InlineData("en-US", "Mm", LengthUnit.Megameter)] + [InlineData("en-US", "Mpc", LengthUnit.Megaparsec)] + [InlineData("en-US", "m", LengthUnit.Meter)] + [InlineData("en-US", "µin", LengthUnit.Microinch)] + [InlineData("en-US", "µm", LengthUnit.Micrometer)] + [InlineData("en-US", "mil", LengthUnit.Mil)] + [InlineData("en-US", "mi", LengthUnit.Mile)] + [InlineData("en-US", "mm", LengthUnit.Millimeter)] + [InlineData("en-US", "nm", LengthUnit.Nanometer)] + [InlineData("en-US", "NM", LengthUnit.NauticalMile)] + [InlineData("en-US", "nmi", LengthUnit.NauticalMile)] + [InlineData("en-US", "pc", LengthUnit.Parsec)] + [InlineData("en-US", "pm", LengthUnit.Picometer)] + [InlineData("en-US", "shackle", LengthUnit.Shackle)] + [InlineData("en-US", "R⊙", LengthUnit.SolarRadius)] + [InlineData("en-US", "twip", LengthUnit.Twip)] + [InlineData("en-US", "ftUS", LengthUnit.UsSurveyFoot)] + [InlineData("en-US", "yd", LengthUnit.Yard)] + [InlineData("ru-RU", "см", LengthUnit.Centimeter)] + [InlineData("ru-RU", "дам", LengthUnit.Decameter)] + [InlineData("ru-RU", "дм", LengthUnit.Decimeter)] + [InlineData("ru-RU", "фм", LengthUnit.Femtometer)] + [InlineData("ru-RU", "фут", LengthUnit.Foot)] + [InlineData("ru-RU", "Гм", LengthUnit.Gigameter)] + [InlineData("ru-RU", "гм", LengthUnit.Hectometer)] + [InlineData("ru-RU", "дюйм", LengthUnit.Inch)] + [InlineData("ru-RU", "кфут", LengthUnit.Kilofoot)] + [InlineData("ru-RU", "км", LengthUnit.Kilometer)] + [InlineData("ru-RU", "кярд", LengthUnit.Kiloyard)] + [InlineData("ru-RU", "Мм", LengthUnit.Megameter)] + [InlineData("ru-RU", "м", LengthUnit.Meter)] + [InlineData("ru-RU", "микродюйм", LengthUnit.Microinch)] + [InlineData("ru-RU", "мкм", LengthUnit.Micrometer)] + [InlineData("ru-RU", "миля", LengthUnit.Mile)] + [InlineData("ru-RU", "мм", LengthUnit.Millimeter)] + [InlineData("ru-RU", "нм", LengthUnit.Nanometer)] + [InlineData("ru-RU", "пм", LengthUnit.Picometer)] + [InlineData("ru-RU", "ярд", LengthUnit.Yard)] + [InlineData("zh-CN", "厘米", LengthUnit.Centimeter)] + [InlineData("zh-CN", "十米", LengthUnit.Decameter)] + [InlineData("zh-CN", "分米", LengthUnit.Decimeter)] + [InlineData("zh-CN", "飞米", LengthUnit.Femtometer)] + [InlineData("zh-CN", "英尺", LengthUnit.Foot)] + [InlineData("zh-CN", "吉米", LengthUnit.Gigameter)] + [InlineData("zh-CN", "百米", LengthUnit.Hectometer)] + [InlineData("zh-CN", "英寸", LengthUnit.Inch)] + [InlineData("zh-CN", "千英尺", LengthUnit.Kilofoot)] + [InlineData("zh-CN", "千米", LengthUnit.Kilometer)] + [InlineData("zh-CN", "千码", LengthUnit.Kiloyard)] + [InlineData("zh-CN", "兆米", LengthUnit.Megameter)] + [InlineData("zh-CN", "米", LengthUnit.Meter)] + [InlineData("zh-CN", "微英寸", LengthUnit.Microinch)] + [InlineData("zh-CN", "微米", LengthUnit.Micrometer)] + [InlineData("zh-CN", "密耳", LengthUnit.Mil)] + [InlineData("zh-CN", "英里", LengthUnit.Mile)] + [InlineData("zh-CN", "毫米", LengthUnit.Millimeter)] + [InlineData("zh-CN", "皮米", LengthUnit.Picometer)] + [InlineData("zh-CN", "码", LengthUnit.Yard)] + public void ParseUnit_WithCulture(string culture, string abbreviation, LengthUnit expectedUnit) { LengthUnit parsedUnit = Length.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1947,9 +2102,163 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati [InlineData("twip", LengthUnit.Twip)] [InlineData("ftUS", LengthUnit.UsSurveyFoot)] [InlineData("yd", LengthUnit.Yard)] - public void TryParseUnit(string abbreviation, LengthUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LengthUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Length.TryParseUnit(abbreviation, out LengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Å", LengthUnit.Angstrom)] + [InlineData("A", LengthUnit.Angstrom)] + [InlineData("au", LengthUnit.AstronomicalUnit)] + [InlineData("ua", LengthUnit.AstronomicalUnit)] + [InlineData("cm", LengthUnit.Centimeter)] + [InlineData("ch", LengthUnit.Chain)] + [InlineData("DM", LengthUnit.DataMile)] + [InlineData("dam", LengthUnit.Decameter)] + [InlineData("dm", LengthUnit.Decimeter)] + [InlineData("fathom", LengthUnit.Fathom)] + [InlineData("fm", LengthUnit.Femtometer)] + [InlineData("ft", LengthUnit.Foot)] + [InlineData("'", LengthUnit.Foot)] + [InlineData("′", LengthUnit.Foot)] + [InlineData("Gm", LengthUnit.Gigameter)] + [InlineData("h", LengthUnit.Hand)] + [InlineData("hh", LengthUnit.Hand)] + [InlineData("hm", LengthUnit.Hectometer)] + [InlineData("in", LengthUnit.Inch)] + [InlineData("\"", LengthUnit.Inch)] + [InlineData("″", LengthUnit.Inch)] + [InlineData("kft", LengthUnit.Kilofoot)] + [InlineData("k'", LengthUnit.Kilofoot)] + [InlineData("k′", LengthUnit.Kilofoot)] + [InlineData("kly", LengthUnit.KilolightYear)] + [InlineData("km", LengthUnit.Kilometer)] + [InlineData("kpc", LengthUnit.Kiloparsec)] + [InlineData("kyd", LengthUnit.Kiloyard)] + [InlineData("ly", LengthUnit.LightYear)] + [InlineData("Mly", LengthUnit.MegalightYear)] + [InlineData("Mm", LengthUnit.Megameter)] + [InlineData("Mpc", LengthUnit.Megaparsec)] + [InlineData("m", LengthUnit.Meter)] + [InlineData("µin", LengthUnit.Microinch)] + [InlineData("µm", LengthUnit.Micrometer)] + [InlineData("mil", LengthUnit.Mil)] + [InlineData("mi", LengthUnit.Mile)] + [InlineData("mm", LengthUnit.Millimeter)] + [InlineData("nm", LengthUnit.Nanometer)] + [InlineData("NM", LengthUnit.NauticalMile)] + [InlineData("nmi", LengthUnit.NauticalMile)] + [InlineData("pc", LengthUnit.Parsec)] + [InlineData("pm", LengthUnit.Picometer)] + [InlineData("shackle", LengthUnit.Shackle)] + [InlineData("R⊙", LengthUnit.SolarRadius)] + [InlineData("twip", LengthUnit.Twip)] + [InlineData("ftUS", LengthUnit.UsSurveyFoot)] + [InlineData("yd", LengthUnit.Yard)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LengthUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Length.TryParseUnit(abbreviation, out LengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Å", LengthUnit.Angstrom)] + [InlineData("en-US", "A", LengthUnit.Angstrom)] + [InlineData("en-US", "au", LengthUnit.AstronomicalUnit)] + [InlineData("en-US", "ua", LengthUnit.AstronomicalUnit)] + [InlineData("en-US", "cm", LengthUnit.Centimeter)] + [InlineData("en-US", "ch", LengthUnit.Chain)] + [InlineData("en-US", "DM", LengthUnit.DataMile)] + [InlineData("en-US", "dam", LengthUnit.Decameter)] + [InlineData("en-US", "dm", LengthUnit.Decimeter)] + [InlineData("en-US", "fathom", LengthUnit.Fathom)] + [InlineData("en-US", "fm", LengthUnit.Femtometer)] + [InlineData("en-US", "ft", LengthUnit.Foot)] + [InlineData("en-US", "'", LengthUnit.Foot)] + [InlineData("en-US", "′", LengthUnit.Foot)] + [InlineData("en-US", "Gm", LengthUnit.Gigameter)] + [InlineData("en-US", "h", LengthUnit.Hand)] + [InlineData("en-US", "hh", LengthUnit.Hand)] + [InlineData("en-US", "hm", LengthUnit.Hectometer)] + [InlineData("en-US", "in", LengthUnit.Inch)] + [InlineData("en-US", "\"", LengthUnit.Inch)] + [InlineData("en-US", "″", LengthUnit.Inch)] + [InlineData("en-US", "kft", LengthUnit.Kilofoot)] + [InlineData("en-US", "k'", LengthUnit.Kilofoot)] + [InlineData("en-US", "k′", LengthUnit.Kilofoot)] + [InlineData("en-US", "kly", LengthUnit.KilolightYear)] + [InlineData("en-US", "km", LengthUnit.Kilometer)] + [InlineData("en-US", "kpc", LengthUnit.Kiloparsec)] + [InlineData("en-US", "kyd", LengthUnit.Kiloyard)] + [InlineData("en-US", "ly", LengthUnit.LightYear)] + [InlineData("en-US", "Mly", LengthUnit.MegalightYear)] + [InlineData("en-US", "Mm", LengthUnit.Megameter)] + [InlineData("en-US", "Mpc", LengthUnit.Megaparsec)] + [InlineData("en-US", "m", LengthUnit.Meter)] + [InlineData("en-US", "µin", LengthUnit.Microinch)] + [InlineData("en-US", "µm", LengthUnit.Micrometer)] + [InlineData("en-US", "mil", LengthUnit.Mil)] + [InlineData("en-US", "mi", LengthUnit.Mile)] + [InlineData("en-US", "mm", LengthUnit.Millimeter)] + [InlineData("en-US", "nm", LengthUnit.Nanometer)] + [InlineData("en-US", "NM", LengthUnit.NauticalMile)] + [InlineData("en-US", "nmi", LengthUnit.NauticalMile)] + [InlineData("en-US", "pc", LengthUnit.Parsec)] + [InlineData("en-US", "pm", LengthUnit.Picometer)] + [InlineData("en-US", "shackle", LengthUnit.Shackle)] + [InlineData("en-US", "R⊙", LengthUnit.SolarRadius)] + [InlineData("en-US", "twip", LengthUnit.Twip)] + [InlineData("en-US", "ftUS", LengthUnit.UsSurveyFoot)] + [InlineData("en-US", "yd", LengthUnit.Yard)] + [InlineData("ru-RU", "см", LengthUnit.Centimeter)] + [InlineData("ru-RU", "дам", LengthUnit.Decameter)] + [InlineData("ru-RU", "дм", LengthUnit.Decimeter)] + [InlineData("ru-RU", "фм", LengthUnit.Femtometer)] + [InlineData("ru-RU", "фут", LengthUnit.Foot)] + [InlineData("ru-RU", "Гм", LengthUnit.Gigameter)] + [InlineData("ru-RU", "гм", LengthUnit.Hectometer)] + [InlineData("ru-RU", "дюйм", LengthUnit.Inch)] + [InlineData("ru-RU", "кфут", LengthUnit.Kilofoot)] + [InlineData("ru-RU", "км", LengthUnit.Kilometer)] + [InlineData("ru-RU", "кярд", LengthUnit.Kiloyard)] + [InlineData("ru-RU", "Мм", LengthUnit.Megameter)] + [InlineData("ru-RU", "м", LengthUnit.Meter)] + [InlineData("ru-RU", "микродюйм", LengthUnit.Microinch)] + [InlineData("ru-RU", "мкм", LengthUnit.Micrometer)] + [InlineData("ru-RU", "миля", LengthUnit.Mile)] + [InlineData("ru-RU", "мм", LengthUnit.Millimeter)] + [InlineData("ru-RU", "нм", LengthUnit.Nanometer)] + [InlineData("ru-RU", "пм", LengthUnit.Picometer)] + [InlineData("ru-RU", "ярд", LengthUnit.Yard)] + [InlineData("zh-CN", "厘米", LengthUnit.Centimeter)] + [InlineData("zh-CN", "十米", LengthUnit.Decameter)] + [InlineData("zh-CN", "分米", LengthUnit.Decimeter)] + [InlineData("zh-CN", "飞米", LengthUnit.Femtometer)] + [InlineData("zh-CN", "英尺", LengthUnit.Foot)] + [InlineData("zh-CN", "吉米", LengthUnit.Gigameter)] + [InlineData("zh-CN", "百米", LengthUnit.Hectometer)] + [InlineData("zh-CN", "英寸", LengthUnit.Inch)] + [InlineData("zh-CN", "千英尺", LengthUnit.Kilofoot)] + [InlineData("zh-CN", "千米", LengthUnit.Kilometer)] + [InlineData("zh-CN", "千码", LengthUnit.Kiloyard)] + [InlineData("zh-CN", "兆米", LengthUnit.Megameter)] + [InlineData("zh-CN", "米", LengthUnit.Meter)] + [InlineData("zh-CN", "微英寸", LengthUnit.Microinch)] + [InlineData("zh-CN", "微米", LengthUnit.Micrometer)] + [InlineData("zh-CN", "密耳", LengthUnit.Mil)] + [InlineData("zh-CN", "英里", LengthUnit.Mile)] + [InlineData("zh-CN", "毫米", LengthUnit.Millimeter)] + [InlineData("zh-CN", "皮米", LengthUnit.Picometer)] + [InlineData("zh-CN", "码", LengthUnit.Yard)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, LengthUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Length.TryParseUnit(abbreviation, out LengthUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -2043,7 +2352,7 @@ public void TryParseUnit(string abbreviation, LengthUnit expectedUnit) [InlineData("zh-CN", "毫米", LengthUnit.Millimeter)] [InlineData("zh-CN", "皮米", LengthUnit.Picometer)] [InlineData("zh-CN", "码", LengthUnit.Yard)] - public void TryParseUnitWithCulture(string culture, string abbreviation, LengthUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, LengthUnit expectedUnit) { Assert.True(Length.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LengthUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs index 19aa857c9f..a836bb2a77 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LevelTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -226,17 +227,39 @@ public void TryParse() [Theory] [InlineData("dB", LevelUnit.Decibel)] [InlineData("Np", LevelUnit.Neper)] - public void ParseUnit(string abbreviation, LevelUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LevelUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - LevelUnit parsedUnit = Level.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + LevelUnit parsedUnit = Level.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("dB", LevelUnit.Decibel)] + [InlineData("Np", LevelUnit.Neper)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LevelUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + LevelUnit parsedUnit = Level.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "dB", LevelUnit.Decibel)] [InlineData("en-US", "Np", LevelUnit.Neper)] - public void ParseUnitWithCulture(string culture, string abbreviation, LevelUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, LevelUnit expectedUnit) + { + using var _ = new CultureScope(culture); + LevelUnit parsedUnit = Level.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "dB", LevelUnit.Decibel)] + [InlineData("en-US", "Np", LevelUnit.Neper)] + public void ParseUnit_WithCulture(string culture, string abbreviation, LevelUnit expectedUnit) { LevelUnit parsedUnit = Level.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -245,9 +268,31 @@ public void ParseUnitWithCulture(string culture, string abbreviation, LevelUnit [Theory] [InlineData("dB", LevelUnit.Decibel)] [InlineData("Np", LevelUnit.Neper)] - public void TryParseUnit(string abbreviation, LevelUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LevelUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Level.TryParseUnit(abbreviation, out LevelUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("dB", LevelUnit.Decibel)] + [InlineData("Np", LevelUnit.Neper)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LevelUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Level.TryParseUnit(abbreviation, out LevelUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "dB", LevelUnit.Decibel)] + [InlineData("en-US", "Np", LevelUnit.Neper)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, LevelUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Level.TryParseUnit(abbreviation, out LevelUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -255,7 +300,7 @@ public void TryParseUnit(string abbreviation, LevelUnit expectedUnit) [Theory] [InlineData("en-US", "dB", LevelUnit.Decibel)] [InlineData("en-US", "Np", LevelUnit.Neper)] - public void TryParseUnitWithCulture(string culture, string abbreviation, LevelUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, LevelUnit expectedUnit) { Assert.True(Level.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LevelUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs index 339679b470..dae7d03ef5 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearDensityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -610,10 +611,38 @@ public void TryParse() [InlineData("mg/mm", LinearDensityUnit.MilligramPerMillimeter)] [InlineData("lb/ft", LinearDensityUnit.PoundPerFoot)] [InlineData("lb/in", LinearDensityUnit.PoundPerInch)] - public void ParseUnit(string abbreviation, LinearDensityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LinearDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - LinearDensityUnit parsedUnit = LinearDensity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + LinearDensityUnit parsedUnit = LinearDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g/cm", LinearDensityUnit.GramPerCentimeter)] + [InlineData("g/ft", LinearDensityUnit.GramPerFoot)] + [InlineData("g/m", LinearDensityUnit.GramPerMeter)] + [InlineData("g/mm", LinearDensityUnit.GramPerMillimeter)] + [InlineData("kg/cm", LinearDensityUnit.KilogramPerCentimeter)] + [InlineData("kg/ft", LinearDensityUnit.KilogramPerFoot)] + [InlineData("kg/m", LinearDensityUnit.KilogramPerMeter)] + [InlineData("kg/mm", LinearDensityUnit.KilogramPerMillimeter)] + [InlineData("µg/cm", LinearDensityUnit.MicrogramPerCentimeter)] + [InlineData("µg/ft", LinearDensityUnit.MicrogramPerFoot)] + [InlineData("µg/m", LinearDensityUnit.MicrogramPerMeter)] + [InlineData("µg/mm", LinearDensityUnit.MicrogramPerMillimeter)] + [InlineData("mg/cm", LinearDensityUnit.MilligramPerCentimeter)] + [InlineData("mg/ft", LinearDensityUnit.MilligramPerFoot)] + [InlineData("mg/m", LinearDensityUnit.MilligramPerMeter)] + [InlineData("mg/mm", LinearDensityUnit.MilligramPerMillimeter)] + [InlineData("lb/ft", LinearDensityUnit.PoundPerFoot)] + [InlineData("lb/in", LinearDensityUnit.PoundPerInch)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LinearDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + LinearDensityUnit parsedUnit = LinearDensity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -636,7 +665,33 @@ public void ParseUnit(string abbreviation, LinearDensityUnit expectedUnit) [InlineData("en-US", "mg/mm", LinearDensityUnit.MilligramPerMillimeter)] [InlineData("en-US", "lb/ft", LinearDensityUnit.PoundPerFoot)] [InlineData("en-US", "lb/in", LinearDensityUnit.PoundPerInch)] - public void ParseUnitWithCulture(string culture, string abbreviation, LinearDensityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, LinearDensityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + LinearDensityUnit parsedUnit = LinearDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g/cm", LinearDensityUnit.GramPerCentimeter)] + [InlineData("en-US", "g/ft", LinearDensityUnit.GramPerFoot)] + [InlineData("en-US", "g/m", LinearDensityUnit.GramPerMeter)] + [InlineData("en-US", "g/mm", LinearDensityUnit.GramPerMillimeter)] + [InlineData("en-US", "kg/cm", LinearDensityUnit.KilogramPerCentimeter)] + [InlineData("en-US", "kg/ft", LinearDensityUnit.KilogramPerFoot)] + [InlineData("en-US", "kg/m", LinearDensityUnit.KilogramPerMeter)] + [InlineData("en-US", "kg/mm", LinearDensityUnit.KilogramPerMillimeter)] + [InlineData("en-US", "µg/cm", LinearDensityUnit.MicrogramPerCentimeter)] + [InlineData("en-US", "µg/ft", LinearDensityUnit.MicrogramPerFoot)] + [InlineData("en-US", "µg/m", LinearDensityUnit.MicrogramPerMeter)] + [InlineData("en-US", "µg/mm", LinearDensityUnit.MicrogramPerMillimeter)] + [InlineData("en-US", "mg/cm", LinearDensityUnit.MilligramPerCentimeter)] + [InlineData("en-US", "mg/ft", LinearDensityUnit.MilligramPerFoot)] + [InlineData("en-US", "mg/m", LinearDensityUnit.MilligramPerMeter)] + [InlineData("en-US", "mg/mm", LinearDensityUnit.MilligramPerMillimeter)] + [InlineData("en-US", "lb/ft", LinearDensityUnit.PoundPerFoot)] + [InlineData("en-US", "lb/in", LinearDensityUnit.PoundPerInch)] + public void ParseUnit_WithCulture(string culture, string abbreviation, LinearDensityUnit expectedUnit) { LinearDensityUnit parsedUnit = LinearDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -661,9 +716,63 @@ public void ParseUnitWithCulture(string culture, string abbreviation, LinearDens [InlineData("mg/mm", LinearDensityUnit.MilligramPerMillimeter)] [InlineData("lb/ft", LinearDensityUnit.PoundPerFoot)] [InlineData("lb/in", LinearDensityUnit.PoundPerInch)] - public void TryParseUnit(string abbreviation, LinearDensityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LinearDensityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(LinearDensity.TryParseUnit(abbreviation, out LinearDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g/cm", LinearDensityUnit.GramPerCentimeter)] + [InlineData("g/ft", LinearDensityUnit.GramPerFoot)] + [InlineData("g/m", LinearDensityUnit.GramPerMeter)] + [InlineData("g/mm", LinearDensityUnit.GramPerMillimeter)] + [InlineData("kg/cm", LinearDensityUnit.KilogramPerCentimeter)] + [InlineData("kg/ft", LinearDensityUnit.KilogramPerFoot)] + [InlineData("kg/m", LinearDensityUnit.KilogramPerMeter)] + [InlineData("kg/mm", LinearDensityUnit.KilogramPerMillimeter)] + [InlineData("µg/cm", LinearDensityUnit.MicrogramPerCentimeter)] + [InlineData("µg/ft", LinearDensityUnit.MicrogramPerFoot)] + [InlineData("µg/m", LinearDensityUnit.MicrogramPerMeter)] + [InlineData("µg/mm", LinearDensityUnit.MicrogramPerMillimeter)] + [InlineData("mg/cm", LinearDensityUnit.MilligramPerCentimeter)] + [InlineData("mg/ft", LinearDensityUnit.MilligramPerFoot)] + [InlineData("mg/m", LinearDensityUnit.MilligramPerMeter)] + [InlineData("mg/mm", LinearDensityUnit.MilligramPerMillimeter)] + [InlineData("lb/ft", LinearDensityUnit.PoundPerFoot)] + [InlineData("lb/in", LinearDensityUnit.PoundPerInch)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LinearDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(LinearDensity.TryParseUnit(abbreviation, out LinearDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g/cm", LinearDensityUnit.GramPerCentimeter)] + [InlineData("en-US", "g/ft", LinearDensityUnit.GramPerFoot)] + [InlineData("en-US", "g/m", LinearDensityUnit.GramPerMeter)] + [InlineData("en-US", "g/mm", LinearDensityUnit.GramPerMillimeter)] + [InlineData("en-US", "kg/cm", LinearDensityUnit.KilogramPerCentimeter)] + [InlineData("en-US", "kg/ft", LinearDensityUnit.KilogramPerFoot)] + [InlineData("en-US", "kg/m", LinearDensityUnit.KilogramPerMeter)] + [InlineData("en-US", "kg/mm", LinearDensityUnit.KilogramPerMillimeter)] + [InlineData("en-US", "µg/cm", LinearDensityUnit.MicrogramPerCentimeter)] + [InlineData("en-US", "µg/ft", LinearDensityUnit.MicrogramPerFoot)] + [InlineData("en-US", "µg/m", LinearDensityUnit.MicrogramPerMeter)] + [InlineData("en-US", "µg/mm", LinearDensityUnit.MicrogramPerMillimeter)] + [InlineData("en-US", "mg/cm", LinearDensityUnit.MilligramPerCentimeter)] + [InlineData("en-US", "mg/ft", LinearDensityUnit.MilligramPerFoot)] + [InlineData("en-US", "mg/m", LinearDensityUnit.MilligramPerMeter)] + [InlineData("en-US", "mg/mm", LinearDensityUnit.MilligramPerMillimeter)] + [InlineData("en-US", "lb/ft", LinearDensityUnit.PoundPerFoot)] + [InlineData("en-US", "lb/in", LinearDensityUnit.PoundPerInch)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, LinearDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(LinearDensity.TryParseUnit(abbreviation, out LinearDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -687,7 +796,7 @@ public void TryParseUnit(string abbreviation, LinearDensityUnit expectedUnit) [InlineData("en-US", "mg/mm", LinearDensityUnit.MilligramPerMillimeter)] [InlineData("en-US", "lb/ft", LinearDensityUnit.PoundPerFoot)] [InlineData("en-US", "lb/in", LinearDensityUnit.PoundPerInch)] - public void TryParseUnitWithCulture(string culture, string abbreviation, LinearDensityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, LinearDensityUnit expectedUnit) { Assert.True(LinearDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LinearDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs index 3fb096c5e2..14a4f1dfc3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LinearPowerDensityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -718,10 +719,45 @@ public void TryParse() [InlineData("W/in", LinearPowerDensityUnit.WattPerInch)] [InlineData("W/m", LinearPowerDensityUnit.WattPerMeter)] [InlineData("W/mm", LinearPowerDensityUnit.WattPerMillimeter)] - public void ParseUnit(string abbreviation, LinearPowerDensityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LinearPowerDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - LinearPowerDensityUnit parsedUnit = LinearPowerDensity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + LinearPowerDensityUnit parsedUnit = LinearPowerDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("GW/cm", LinearPowerDensityUnit.GigawattPerCentimeter)] + [InlineData("GW/ft", LinearPowerDensityUnit.GigawattPerFoot)] + [InlineData("GW/in", LinearPowerDensityUnit.GigawattPerInch)] + [InlineData("GW/m", LinearPowerDensityUnit.GigawattPerMeter)] + [InlineData("GW/mm", LinearPowerDensityUnit.GigawattPerMillimeter)] + [InlineData("kW/cm", LinearPowerDensityUnit.KilowattPerCentimeter)] + [InlineData("kW/ft", LinearPowerDensityUnit.KilowattPerFoot)] + [InlineData("kW/in", LinearPowerDensityUnit.KilowattPerInch)] + [InlineData("kW/m", LinearPowerDensityUnit.KilowattPerMeter)] + [InlineData("kW/mm", LinearPowerDensityUnit.KilowattPerMillimeter)] + [InlineData("MW/cm", LinearPowerDensityUnit.MegawattPerCentimeter)] + [InlineData("MW/ft", LinearPowerDensityUnit.MegawattPerFoot)] + [InlineData("MW/in", LinearPowerDensityUnit.MegawattPerInch)] + [InlineData("MW/m", LinearPowerDensityUnit.MegawattPerMeter)] + [InlineData("MW/mm", LinearPowerDensityUnit.MegawattPerMillimeter)] + [InlineData("mW/cm", LinearPowerDensityUnit.MilliwattPerCentimeter)] + [InlineData("mW/ft", LinearPowerDensityUnit.MilliwattPerFoot)] + [InlineData("mW/in", LinearPowerDensityUnit.MilliwattPerInch)] + [InlineData("mW/m", LinearPowerDensityUnit.MilliwattPerMeter)] + [InlineData("mW/mm", LinearPowerDensityUnit.MilliwattPerMillimeter)] + [InlineData("W/cm", LinearPowerDensityUnit.WattPerCentimeter)] + [InlineData("W/ft", LinearPowerDensityUnit.WattPerFoot)] + [InlineData("W/in", LinearPowerDensityUnit.WattPerInch)] + [InlineData("W/m", LinearPowerDensityUnit.WattPerMeter)] + [InlineData("W/mm", LinearPowerDensityUnit.WattPerMillimeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LinearPowerDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + LinearPowerDensityUnit parsedUnit = LinearPowerDensity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -751,7 +787,40 @@ public void ParseUnit(string abbreviation, LinearPowerDensityUnit expectedUnit) [InlineData("en-US", "W/in", LinearPowerDensityUnit.WattPerInch)] [InlineData("en-US", "W/m", LinearPowerDensityUnit.WattPerMeter)] [InlineData("en-US", "W/mm", LinearPowerDensityUnit.WattPerMillimeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, LinearPowerDensityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, LinearPowerDensityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + LinearPowerDensityUnit parsedUnit = LinearPowerDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "GW/cm", LinearPowerDensityUnit.GigawattPerCentimeter)] + [InlineData("en-US", "GW/ft", LinearPowerDensityUnit.GigawattPerFoot)] + [InlineData("en-US", "GW/in", LinearPowerDensityUnit.GigawattPerInch)] + [InlineData("en-US", "GW/m", LinearPowerDensityUnit.GigawattPerMeter)] + [InlineData("en-US", "GW/mm", LinearPowerDensityUnit.GigawattPerMillimeter)] + [InlineData("en-US", "kW/cm", LinearPowerDensityUnit.KilowattPerCentimeter)] + [InlineData("en-US", "kW/ft", LinearPowerDensityUnit.KilowattPerFoot)] + [InlineData("en-US", "kW/in", LinearPowerDensityUnit.KilowattPerInch)] + [InlineData("en-US", "kW/m", LinearPowerDensityUnit.KilowattPerMeter)] + [InlineData("en-US", "kW/mm", LinearPowerDensityUnit.KilowattPerMillimeter)] + [InlineData("en-US", "MW/cm", LinearPowerDensityUnit.MegawattPerCentimeter)] + [InlineData("en-US", "MW/ft", LinearPowerDensityUnit.MegawattPerFoot)] + [InlineData("en-US", "MW/in", LinearPowerDensityUnit.MegawattPerInch)] + [InlineData("en-US", "MW/m", LinearPowerDensityUnit.MegawattPerMeter)] + [InlineData("en-US", "MW/mm", LinearPowerDensityUnit.MegawattPerMillimeter)] + [InlineData("en-US", "mW/cm", LinearPowerDensityUnit.MilliwattPerCentimeter)] + [InlineData("en-US", "mW/ft", LinearPowerDensityUnit.MilliwattPerFoot)] + [InlineData("en-US", "mW/in", LinearPowerDensityUnit.MilliwattPerInch)] + [InlineData("en-US", "mW/m", LinearPowerDensityUnit.MilliwattPerMeter)] + [InlineData("en-US", "mW/mm", LinearPowerDensityUnit.MilliwattPerMillimeter)] + [InlineData("en-US", "W/cm", LinearPowerDensityUnit.WattPerCentimeter)] + [InlineData("en-US", "W/ft", LinearPowerDensityUnit.WattPerFoot)] + [InlineData("en-US", "W/in", LinearPowerDensityUnit.WattPerInch)] + [InlineData("en-US", "W/m", LinearPowerDensityUnit.WattPerMeter)] + [InlineData("en-US", "W/mm", LinearPowerDensityUnit.WattPerMillimeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, LinearPowerDensityUnit expectedUnit) { LinearPowerDensityUnit parsedUnit = LinearPowerDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -783,9 +852,77 @@ public void ParseUnitWithCulture(string culture, string abbreviation, LinearPowe [InlineData("W/in", LinearPowerDensityUnit.WattPerInch)] [InlineData("W/m", LinearPowerDensityUnit.WattPerMeter)] [InlineData("W/mm", LinearPowerDensityUnit.WattPerMillimeter)] - public void TryParseUnit(string abbreviation, LinearPowerDensityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LinearPowerDensityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(LinearPowerDensity.TryParseUnit(abbreviation, out LinearPowerDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("GW/cm", LinearPowerDensityUnit.GigawattPerCentimeter)] + [InlineData("GW/ft", LinearPowerDensityUnit.GigawattPerFoot)] + [InlineData("GW/in", LinearPowerDensityUnit.GigawattPerInch)] + [InlineData("GW/m", LinearPowerDensityUnit.GigawattPerMeter)] + [InlineData("GW/mm", LinearPowerDensityUnit.GigawattPerMillimeter)] + [InlineData("kW/cm", LinearPowerDensityUnit.KilowattPerCentimeter)] + [InlineData("kW/ft", LinearPowerDensityUnit.KilowattPerFoot)] + [InlineData("kW/in", LinearPowerDensityUnit.KilowattPerInch)] + [InlineData("kW/m", LinearPowerDensityUnit.KilowattPerMeter)] + [InlineData("kW/mm", LinearPowerDensityUnit.KilowattPerMillimeter)] + [InlineData("MW/cm", LinearPowerDensityUnit.MegawattPerCentimeter)] + [InlineData("MW/ft", LinearPowerDensityUnit.MegawattPerFoot)] + [InlineData("MW/in", LinearPowerDensityUnit.MegawattPerInch)] + [InlineData("MW/m", LinearPowerDensityUnit.MegawattPerMeter)] + [InlineData("MW/mm", LinearPowerDensityUnit.MegawattPerMillimeter)] + [InlineData("mW/cm", LinearPowerDensityUnit.MilliwattPerCentimeter)] + [InlineData("mW/ft", LinearPowerDensityUnit.MilliwattPerFoot)] + [InlineData("mW/in", LinearPowerDensityUnit.MilliwattPerInch)] + [InlineData("mW/m", LinearPowerDensityUnit.MilliwattPerMeter)] + [InlineData("mW/mm", LinearPowerDensityUnit.MilliwattPerMillimeter)] + [InlineData("W/cm", LinearPowerDensityUnit.WattPerCentimeter)] + [InlineData("W/ft", LinearPowerDensityUnit.WattPerFoot)] + [InlineData("W/in", LinearPowerDensityUnit.WattPerInch)] + [InlineData("W/m", LinearPowerDensityUnit.WattPerMeter)] + [InlineData("W/mm", LinearPowerDensityUnit.WattPerMillimeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LinearPowerDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(LinearPowerDensity.TryParseUnit(abbreviation, out LinearPowerDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "GW/cm", LinearPowerDensityUnit.GigawattPerCentimeter)] + [InlineData("en-US", "GW/ft", LinearPowerDensityUnit.GigawattPerFoot)] + [InlineData("en-US", "GW/in", LinearPowerDensityUnit.GigawattPerInch)] + [InlineData("en-US", "GW/m", LinearPowerDensityUnit.GigawattPerMeter)] + [InlineData("en-US", "GW/mm", LinearPowerDensityUnit.GigawattPerMillimeter)] + [InlineData("en-US", "kW/cm", LinearPowerDensityUnit.KilowattPerCentimeter)] + [InlineData("en-US", "kW/ft", LinearPowerDensityUnit.KilowattPerFoot)] + [InlineData("en-US", "kW/in", LinearPowerDensityUnit.KilowattPerInch)] + [InlineData("en-US", "kW/m", LinearPowerDensityUnit.KilowattPerMeter)] + [InlineData("en-US", "kW/mm", LinearPowerDensityUnit.KilowattPerMillimeter)] + [InlineData("en-US", "MW/cm", LinearPowerDensityUnit.MegawattPerCentimeter)] + [InlineData("en-US", "MW/ft", LinearPowerDensityUnit.MegawattPerFoot)] + [InlineData("en-US", "MW/in", LinearPowerDensityUnit.MegawattPerInch)] + [InlineData("en-US", "MW/m", LinearPowerDensityUnit.MegawattPerMeter)] + [InlineData("en-US", "MW/mm", LinearPowerDensityUnit.MegawattPerMillimeter)] + [InlineData("en-US", "mW/cm", LinearPowerDensityUnit.MilliwattPerCentimeter)] + [InlineData("en-US", "mW/ft", LinearPowerDensityUnit.MilliwattPerFoot)] + [InlineData("en-US", "mW/in", LinearPowerDensityUnit.MilliwattPerInch)] + [InlineData("en-US", "mW/m", LinearPowerDensityUnit.MilliwattPerMeter)] + [InlineData("en-US", "mW/mm", LinearPowerDensityUnit.MilliwattPerMillimeter)] + [InlineData("en-US", "W/cm", LinearPowerDensityUnit.WattPerCentimeter)] + [InlineData("en-US", "W/ft", LinearPowerDensityUnit.WattPerFoot)] + [InlineData("en-US", "W/in", LinearPowerDensityUnit.WattPerInch)] + [InlineData("en-US", "W/m", LinearPowerDensityUnit.WattPerMeter)] + [InlineData("en-US", "W/mm", LinearPowerDensityUnit.WattPerMillimeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, LinearPowerDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(LinearPowerDensity.TryParseUnit(abbreviation, out LinearPowerDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -816,7 +953,7 @@ public void TryParseUnit(string abbreviation, LinearPowerDensityUnit expectedUni [InlineData("en-US", "W/in", LinearPowerDensityUnit.WattPerInch)] [InlineData("en-US", "W/m", LinearPowerDensityUnit.WattPerMeter)] [InlineData("en-US", "W/mm", LinearPowerDensityUnit.WattPerMillimeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, LinearPowerDensityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, LinearPowerDensityUnit expectedUnit) { Assert.True(LinearPowerDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LinearPowerDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs index 51a3590034..5095f755a3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminanceTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -418,10 +419,30 @@ public void TryParse() [InlineData("mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] [InlineData("nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] [InlineData("nt", LuminanceUnit.Nit)] - public void ParseUnit(string abbreviation, LuminanceUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LuminanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - LuminanceUnit parsedUnit = Luminance.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + LuminanceUnit parsedUnit = Luminance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Cd/ft²", LuminanceUnit.CandelaPerSquareFoot)] + [InlineData("Cd/in²", LuminanceUnit.CandelaPerSquareInch)] + [InlineData("Cd/m²", LuminanceUnit.CandelaPerSquareMeter)] + [InlineData("cCd/m²", LuminanceUnit.CenticandelaPerSquareMeter)] + [InlineData("dCd/m²", LuminanceUnit.DecicandelaPerSquareMeter)] + [InlineData("kCd/m²", LuminanceUnit.KilocandelaPerSquareMeter)] + [InlineData("µCd/m²", LuminanceUnit.MicrocandelaPerSquareMeter)] + [InlineData("mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] + [InlineData("nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] + [InlineData("nt", LuminanceUnit.Nit)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LuminanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + LuminanceUnit parsedUnit = Luminance.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -436,7 +457,25 @@ public void ParseUnit(string abbreviation, LuminanceUnit expectedUnit) [InlineData("en-US", "mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] [InlineData("en-US", "nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] [InlineData("en-US", "nt", LuminanceUnit.Nit)] - public void ParseUnitWithCulture(string culture, string abbreviation, LuminanceUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, LuminanceUnit expectedUnit) + { + using var _ = new CultureScope(culture); + LuminanceUnit parsedUnit = Luminance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Cd/ft²", LuminanceUnit.CandelaPerSquareFoot)] + [InlineData("en-US", "Cd/in²", LuminanceUnit.CandelaPerSquareInch)] + [InlineData("en-US", "Cd/m²", LuminanceUnit.CandelaPerSquareMeter)] + [InlineData("en-US", "cCd/m²", LuminanceUnit.CenticandelaPerSquareMeter)] + [InlineData("en-US", "dCd/m²", LuminanceUnit.DecicandelaPerSquareMeter)] + [InlineData("en-US", "kCd/m²", LuminanceUnit.KilocandelaPerSquareMeter)] + [InlineData("en-US", "µCd/m²", LuminanceUnit.MicrocandelaPerSquareMeter)] + [InlineData("en-US", "mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] + [InlineData("en-US", "nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] + [InlineData("en-US", "nt", LuminanceUnit.Nit)] + public void ParseUnit_WithCulture(string culture, string abbreviation, LuminanceUnit expectedUnit) { LuminanceUnit parsedUnit = Luminance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -453,9 +492,47 @@ public void ParseUnitWithCulture(string culture, string abbreviation, LuminanceU [InlineData("mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] [InlineData("nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] [InlineData("nt", LuminanceUnit.Nit)] - public void TryParseUnit(string abbreviation, LuminanceUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LuminanceUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Luminance.TryParseUnit(abbreviation, out LuminanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Cd/ft²", LuminanceUnit.CandelaPerSquareFoot)] + [InlineData("Cd/in²", LuminanceUnit.CandelaPerSquareInch)] + [InlineData("Cd/m²", LuminanceUnit.CandelaPerSquareMeter)] + [InlineData("cCd/m²", LuminanceUnit.CenticandelaPerSquareMeter)] + [InlineData("dCd/m²", LuminanceUnit.DecicandelaPerSquareMeter)] + [InlineData("kCd/m²", LuminanceUnit.KilocandelaPerSquareMeter)] + [InlineData("µCd/m²", LuminanceUnit.MicrocandelaPerSquareMeter)] + [InlineData("mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] + [InlineData("nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] + [InlineData("nt", LuminanceUnit.Nit)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LuminanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Luminance.TryParseUnit(abbreviation, out LuminanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Cd/ft²", LuminanceUnit.CandelaPerSquareFoot)] + [InlineData("en-US", "Cd/in²", LuminanceUnit.CandelaPerSquareInch)] + [InlineData("en-US", "Cd/m²", LuminanceUnit.CandelaPerSquareMeter)] + [InlineData("en-US", "cCd/m²", LuminanceUnit.CenticandelaPerSquareMeter)] + [InlineData("en-US", "dCd/m²", LuminanceUnit.DecicandelaPerSquareMeter)] + [InlineData("en-US", "kCd/m²", LuminanceUnit.KilocandelaPerSquareMeter)] + [InlineData("en-US", "µCd/m²", LuminanceUnit.MicrocandelaPerSquareMeter)] + [InlineData("en-US", "mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] + [InlineData("en-US", "nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] + [InlineData("en-US", "nt", LuminanceUnit.Nit)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, LuminanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Luminance.TryParseUnit(abbreviation, out LuminanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -471,7 +548,7 @@ public void TryParseUnit(string abbreviation, LuminanceUnit expectedUnit) [InlineData("en-US", "mCd/m²", LuminanceUnit.MillicandelaPerSquareMeter)] [InlineData("en-US", "nCd/m²", LuminanceUnit.NanocandelaPerSquareMeter)] [InlineData("en-US", "nt", LuminanceUnit.Nit)] - public void TryParseUnitWithCulture(string culture, string abbreviation, LuminanceUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, LuminanceUnit expectedUnit) { Assert.True(Luminance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LuminanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs index 50aebd008a..393342cc45 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminosityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -490,10 +491,34 @@ public void TryParse() [InlineData("L⊙", LuminosityUnit.SolarLuminosity)] [InlineData("TW", LuminosityUnit.Terawatt)] [InlineData("W", LuminosityUnit.Watt)] - public void ParseUnit(string abbreviation, LuminosityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LuminosityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - LuminosityUnit parsedUnit = Luminosity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + LuminosityUnit parsedUnit = Luminosity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("daW", LuminosityUnit.Decawatt)] + [InlineData("dW", LuminosityUnit.Deciwatt)] + [InlineData("fW", LuminosityUnit.Femtowatt)] + [InlineData("GW", LuminosityUnit.Gigawatt)] + [InlineData("kW", LuminosityUnit.Kilowatt)] + [InlineData("MW", LuminosityUnit.Megawatt)] + [InlineData("µW", LuminosityUnit.Microwatt)] + [InlineData("mW", LuminosityUnit.Milliwatt)] + [InlineData("nW", LuminosityUnit.Nanowatt)] + [InlineData("PW", LuminosityUnit.Petawatt)] + [InlineData("pW", LuminosityUnit.Picowatt)] + [InlineData("L⊙", LuminosityUnit.SolarLuminosity)] + [InlineData("TW", LuminosityUnit.Terawatt)] + [InlineData("W", LuminosityUnit.Watt)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LuminosityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + LuminosityUnit parsedUnit = Luminosity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -512,7 +537,29 @@ public void ParseUnit(string abbreviation, LuminosityUnit expectedUnit) [InlineData("en-US", "L⊙", LuminosityUnit.SolarLuminosity)] [InlineData("en-US", "TW", LuminosityUnit.Terawatt)] [InlineData("en-US", "W", LuminosityUnit.Watt)] - public void ParseUnitWithCulture(string culture, string abbreviation, LuminosityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, LuminosityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + LuminosityUnit parsedUnit = Luminosity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "daW", LuminosityUnit.Decawatt)] + [InlineData("en-US", "dW", LuminosityUnit.Deciwatt)] + [InlineData("en-US", "fW", LuminosityUnit.Femtowatt)] + [InlineData("en-US", "GW", LuminosityUnit.Gigawatt)] + [InlineData("en-US", "kW", LuminosityUnit.Kilowatt)] + [InlineData("en-US", "MW", LuminosityUnit.Megawatt)] + [InlineData("en-US", "µW", LuminosityUnit.Microwatt)] + [InlineData("en-US", "mW", LuminosityUnit.Milliwatt)] + [InlineData("en-US", "nW", LuminosityUnit.Nanowatt)] + [InlineData("en-US", "PW", LuminosityUnit.Petawatt)] + [InlineData("en-US", "pW", LuminosityUnit.Picowatt)] + [InlineData("en-US", "L⊙", LuminosityUnit.SolarLuminosity)] + [InlineData("en-US", "TW", LuminosityUnit.Terawatt)] + [InlineData("en-US", "W", LuminosityUnit.Watt)] + public void ParseUnit_WithCulture(string culture, string abbreviation, LuminosityUnit expectedUnit) { LuminosityUnit parsedUnit = Luminosity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -533,9 +580,55 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Luminosity [InlineData("L⊙", LuminosityUnit.SolarLuminosity)] [InlineData("TW", LuminosityUnit.Terawatt)] [InlineData("W", LuminosityUnit.Watt)] - public void TryParseUnit(string abbreviation, LuminosityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LuminosityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Luminosity.TryParseUnit(abbreviation, out LuminosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("daW", LuminosityUnit.Decawatt)] + [InlineData("dW", LuminosityUnit.Deciwatt)] + [InlineData("fW", LuminosityUnit.Femtowatt)] + [InlineData("GW", LuminosityUnit.Gigawatt)] + [InlineData("kW", LuminosityUnit.Kilowatt)] + [InlineData("MW", LuminosityUnit.Megawatt)] + [InlineData("µW", LuminosityUnit.Microwatt)] + [InlineData("mW", LuminosityUnit.Milliwatt)] + [InlineData("nW", LuminosityUnit.Nanowatt)] + [InlineData("PW", LuminosityUnit.Petawatt)] + [InlineData("pW", LuminosityUnit.Picowatt)] + [InlineData("L⊙", LuminosityUnit.SolarLuminosity)] + [InlineData("TW", LuminosityUnit.Terawatt)] + [InlineData("W", LuminosityUnit.Watt)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LuminosityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Luminosity.TryParseUnit(abbreviation, out LuminosityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "daW", LuminosityUnit.Decawatt)] + [InlineData("en-US", "dW", LuminosityUnit.Deciwatt)] + [InlineData("en-US", "fW", LuminosityUnit.Femtowatt)] + [InlineData("en-US", "GW", LuminosityUnit.Gigawatt)] + [InlineData("en-US", "kW", LuminosityUnit.Kilowatt)] + [InlineData("en-US", "MW", LuminosityUnit.Megawatt)] + [InlineData("en-US", "µW", LuminosityUnit.Microwatt)] + [InlineData("en-US", "mW", LuminosityUnit.Milliwatt)] + [InlineData("en-US", "nW", LuminosityUnit.Nanowatt)] + [InlineData("en-US", "PW", LuminosityUnit.Petawatt)] + [InlineData("en-US", "pW", LuminosityUnit.Picowatt)] + [InlineData("en-US", "L⊙", LuminosityUnit.SolarLuminosity)] + [InlineData("en-US", "TW", LuminosityUnit.Terawatt)] + [InlineData("en-US", "W", LuminosityUnit.Watt)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, LuminosityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Luminosity.TryParseUnit(abbreviation, out LuminosityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -555,7 +648,7 @@ public void TryParseUnit(string abbreviation, LuminosityUnit expectedUnit) [InlineData("en-US", "L⊙", LuminosityUnit.SolarLuminosity)] [InlineData("en-US", "TW", LuminosityUnit.Terawatt)] [InlineData("en-US", "W", LuminosityUnit.Watt)] - public void TryParseUnitWithCulture(string culture, string abbreviation, LuminosityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, LuminosityUnit expectedUnit) { Assert.True(Luminosity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LuminosityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs index 9a451c665b..f214ff76c9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousFluxTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("lm", LuminousFluxUnit.Lumen)] - public void ParseUnit(string abbreviation, LuminousFluxUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LuminousFluxUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - LuminousFluxUnit parsedUnit = LuminousFlux.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + LuminousFluxUnit parsedUnit = LuminousFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("lm", LuminousFluxUnit.Lumen)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LuminousFluxUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + LuminousFluxUnit parsedUnit = LuminousFlux.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "lm", LuminousFluxUnit.Lumen)] - public void ParseUnitWithCulture(string culture, string abbreviation, LuminousFluxUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, LuminousFluxUnit expectedUnit) + { + using var _ = new CultureScope(culture); + LuminousFluxUnit parsedUnit = LuminousFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "lm", LuminousFluxUnit.Lumen)] + public void ParseUnit_WithCulture(string culture, string abbreviation, LuminousFluxUnit expectedUnit) { LuminousFluxUnit parsedUnit = LuminousFlux.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, LuminousFl [Theory] [InlineData("lm", LuminousFluxUnit.Lumen)] - public void TryParseUnit(string abbreviation, LuminousFluxUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LuminousFluxUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(LuminousFlux.TryParseUnit(abbreviation, out LuminousFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("lm", LuminousFluxUnit.Lumen)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LuminousFluxUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(LuminousFlux.TryParseUnit(abbreviation, out LuminousFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "lm", LuminousFluxUnit.Lumen)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, LuminousFluxUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(LuminousFlux.TryParseUnit(abbreviation, out LuminousFluxUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "lm", LuminousFluxUnit.Lumen)] - public void TryParseUnitWithCulture(string culture, string abbreviation, LuminousFluxUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, LuminousFluxUnit expectedUnit) { Assert.True(LuminousFlux.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LuminousFluxUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs index 5c6f38d55d..4824c340d3 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/LuminousIntensityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("cd", LuminousIntensityUnit.Candela)] - public void ParseUnit(string abbreviation, LuminousIntensityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LuminousIntensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - LuminousIntensityUnit parsedUnit = LuminousIntensity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + LuminousIntensityUnit parsedUnit = LuminousIntensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cd", LuminousIntensityUnit.Candela)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LuminousIntensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + LuminousIntensityUnit parsedUnit = LuminousIntensity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "cd", LuminousIntensityUnit.Candela)] - public void ParseUnitWithCulture(string culture, string abbreviation, LuminousIntensityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, LuminousIntensityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + LuminousIntensityUnit parsedUnit = LuminousIntensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cd", LuminousIntensityUnit.Candela)] + public void ParseUnit_WithCulture(string culture, string abbreviation, LuminousIntensityUnit expectedUnit) { LuminousIntensityUnit parsedUnit = LuminousIntensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, LuminousIn [Theory] [InlineData("cd", LuminousIntensityUnit.Candela)] - public void TryParseUnit(string abbreviation, LuminousIntensityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, LuminousIntensityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(LuminousIntensity.TryParseUnit(abbreviation, out LuminousIntensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cd", LuminousIntensityUnit.Candela)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, LuminousIntensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(LuminousIntensity.TryParseUnit(abbreviation, out LuminousIntensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cd", LuminousIntensityUnit.Candela)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, LuminousIntensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(LuminousIntensity.TryParseUnit(abbreviation, out LuminousIntensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "cd", LuminousIntensityUnit.Candela)] - public void TryParseUnitWithCulture(string culture, string abbreviation, LuminousIntensityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, LuminousIntensityUnit expectedUnit) { Assert.True(LuminousIntensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out LuminousIntensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs index 887c96a3da..7fa8e250ee 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFieldTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -322,10 +323,26 @@ public void TryParse() [InlineData("mT", MagneticFieldUnit.Millitesla)] [InlineData("nT", MagneticFieldUnit.Nanotesla)] [InlineData("T", MagneticFieldUnit.Tesla)] - public void ParseUnit(string abbreviation, MagneticFieldUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MagneticFieldUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MagneticFieldUnit parsedUnit = MagneticField.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MagneticFieldUnit parsedUnit = MagneticField.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("G", MagneticFieldUnit.Gauss)] + [InlineData("µT", MagneticFieldUnit.Microtesla)] + [InlineData("mG", MagneticFieldUnit.Milligauss)] + [InlineData("mT", MagneticFieldUnit.Millitesla)] + [InlineData("nT", MagneticFieldUnit.Nanotesla)] + [InlineData("T", MagneticFieldUnit.Tesla)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MagneticFieldUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MagneticFieldUnit parsedUnit = MagneticField.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -336,7 +353,21 @@ public void ParseUnit(string abbreviation, MagneticFieldUnit expectedUnit) [InlineData("en-US", "mT", MagneticFieldUnit.Millitesla)] [InlineData("en-US", "nT", MagneticFieldUnit.Nanotesla)] [InlineData("en-US", "T", MagneticFieldUnit.Tesla)] - public void ParseUnitWithCulture(string culture, string abbreviation, MagneticFieldUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MagneticFieldUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MagneticFieldUnit parsedUnit = MagneticField.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "G", MagneticFieldUnit.Gauss)] + [InlineData("en-US", "µT", MagneticFieldUnit.Microtesla)] + [InlineData("en-US", "mG", MagneticFieldUnit.Milligauss)] + [InlineData("en-US", "mT", MagneticFieldUnit.Millitesla)] + [InlineData("en-US", "nT", MagneticFieldUnit.Nanotesla)] + [InlineData("en-US", "T", MagneticFieldUnit.Tesla)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MagneticFieldUnit expectedUnit) { MagneticFieldUnit parsedUnit = MagneticField.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -349,9 +380,39 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MagneticFi [InlineData("mT", MagneticFieldUnit.Millitesla)] [InlineData("nT", MagneticFieldUnit.Nanotesla)] [InlineData("T", MagneticFieldUnit.Tesla)] - public void TryParseUnit(string abbreviation, MagneticFieldUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MagneticFieldUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(MagneticField.TryParseUnit(abbreviation, out MagneticFieldUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("G", MagneticFieldUnit.Gauss)] + [InlineData("µT", MagneticFieldUnit.Microtesla)] + [InlineData("mG", MagneticFieldUnit.Milligauss)] + [InlineData("mT", MagneticFieldUnit.Millitesla)] + [InlineData("nT", MagneticFieldUnit.Nanotesla)] + [InlineData("T", MagneticFieldUnit.Tesla)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MagneticFieldUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(MagneticField.TryParseUnit(abbreviation, out MagneticFieldUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "G", MagneticFieldUnit.Gauss)] + [InlineData("en-US", "µT", MagneticFieldUnit.Microtesla)] + [InlineData("en-US", "mG", MagneticFieldUnit.Milligauss)] + [InlineData("en-US", "mT", MagneticFieldUnit.Millitesla)] + [InlineData("en-US", "nT", MagneticFieldUnit.Nanotesla)] + [InlineData("en-US", "T", MagneticFieldUnit.Tesla)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MagneticFieldUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(MagneticField.TryParseUnit(abbreviation, out MagneticFieldUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -363,7 +424,7 @@ public void TryParseUnit(string abbreviation, MagneticFieldUnit expectedUnit) [InlineData("en-US", "mT", MagneticFieldUnit.Millitesla)] [InlineData("en-US", "nT", MagneticFieldUnit.Nanotesla)] [InlineData("en-US", "T", MagneticFieldUnit.Tesla)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MagneticFieldUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MagneticFieldUnit expectedUnit) { Assert.True(MagneticField.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MagneticFieldUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs index de42287ffb..889e33de9f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagneticFluxTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("Wb", MagneticFluxUnit.Weber)] - public void ParseUnit(string abbreviation, MagneticFluxUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MagneticFluxUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MagneticFluxUnit parsedUnit = MagneticFlux.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MagneticFluxUnit parsedUnit = MagneticFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Wb", MagneticFluxUnit.Weber)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MagneticFluxUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MagneticFluxUnit parsedUnit = MagneticFlux.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "Wb", MagneticFluxUnit.Weber)] - public void ParseUnitWithCulture(string culture, string abbreviation, MagneticFluxUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MagneticFluxUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MagneticFluxUnit parsedUnit = MagneticFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Wb", MagneticFluxUnit.Weber)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MagneticFluxUnit expectedUnit) { MagneticFluxUnit parsedUnit = MagneticFlux.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MagneticFl [Theory] [InlineData("Wb", MagneticFluxUnit.Weber)] - public void TryParseUnit(string abbreviation, MagneticFluxUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MagneticFluxUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(MagneticFlux.TryParseUnit(abbreviation, out MagneticFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Wb", MagneticFluxUnit.Weber)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MagneticFluxUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(MagneticFlux.TryParseUnit(abbreviation, out MagneticFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Wb", MagneticFluxUnit.Weber)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MagneticFluxUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(MagneticFlux.TryParseUnit(abbreviation, out MagneticFluxUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "Wb", MagneticFluxUnit.Weber)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MagneticFluxUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MagneticFluxUnit expectedUnit) { Assert.True(MagneticFlux.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MagneticFluxUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs index 44ec060e21..d0571a6bf2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MagnetizationTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("A/m", MagnetizationUnit.AmperePerMeter)] - public void ParseUnit(string abbreviation, MagnetizationUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MagnetizationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MagnetizationUnit parsedUnit = Magnetization.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MagnetizationUnit parsedUnit = Magnetization.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("A/m", MagnetizationUnit.AmperePerMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MagnetizationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MagnetizationUnit parsedUnit = Magnetization.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "A/m", MagnetizationUnit.AmperePerMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, MagnetizationUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MagnetizationUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MagnetizationUnit parsedUnit = Magnetization.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "A/m", MagnetizationUnit.AmperePerMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MagnetizationUnit expectedUnit) { MagnetizationUnit parsedUnit = Magnetization.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Magnetizat [Theory] [InlineData("A/m", MagnetizationUnit.AmperePerMeter)] - public void TryParseUnit(string abbreviation, MagnetizationUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MagnetizationUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Magnetization.TryParseUnit(abbreviation, out MagnetizationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("A/m", MagnetizationUnit.AmperePerMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MagnetizationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Magnetization.TryParseUnit(abbreviation, out MagnetizationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "A/m", MagnetizationUnit.AmperePerMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MagnetizationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Magnetization.TryParseUnit(abbreviation, out MagnetizationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "A/m", MagnetizationUnit.AmperePerMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MagnetizationUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MagnetizationUnit expectedUnit) { Assert.True(Magnetization.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MagnetizationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs index 4cd37bf5cd..e970258812 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassConcentrationTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1406,10 +1407,69 @@ public void TryParse() [InlineData("t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter)] [InlineData("t/m³", MassConcentrationUnit.TonnePerCubicMeter)] [InlineData("t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter)] - public void ParseUnit(string abbreviation, MassConcentrationUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassConcentrationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MassConcentrationUnit parsedUnit = MassConcentration.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MassConcentrationUnit parsedUnit = MassConcentration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg/dl", MassConcentrationUnit.CentigramPerDeciliter)] + [InlineData("cg/l", MassConcentrationUnit.CentigramPerLiter)] + [InlineData("cg/μl", MassConcentrationUnit.CentigramPerMicroliter)] + [InlineData("cg/ml", MassConcentrationUnit.CentigramPerMilliliter)] + [InlineData("dg/dl", MassConcentrationUnit.DecigramPerDeciliter)] + [InlineData("dg/l", MassConcentrationUnit.DecigramPerLiter)] + [InlineData("dg/μl", MassConcentrationUnit.DecigramPerMicroliter)] + [InlineData("dg/ml", MassConcentrationUnit.DecigramPerMilliliter)] + [InlineData("g/cm³", MassConcentrationUnit.GramPerCubicCentimeter)] + [InlineData("g/m³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("g/mm³", MassConcentrationUnit.GramPerCubicMillimeter)] + [InlineData("g/dl", MassConcentrationUnit.GramPerDeciliter)] + [InlineData("g/l", MassConcentrationUnit.GramPerLiter)] + [InlineData("g/μl", MassConcentrationUnit.GramPerMicroliter)] + [InlineData("g/ml", MassConcentrationUnit.GramPerMilliliter)] + [InlineData("kg/cm³", MassConcentrationUnit.KilogramPerCubicCentimeter)] + [InlineData("kg/m³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("kg/mm³", MassConcentrationUnit.KilogramPerCubicMillimeter)] + [InlineData("kg/l", MassConcentrationUnit.KilogramPerLiter)] + [InlineData("kip/ft³", MassConcentrationUnit.KilopoundPerCubicFoot)] + [InlineData("kip/in³", MassConcentrationUnit.KilopoundPerCubicInch)] + [InlineData("µg/m³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("µg/dl", MassConcentrationUnit.MicrogramPerDeciliter)] + [InlineData("µg/l", MassConcentrationUnit.MicrogramPerLiter)] + [InlineData("µg/μl", MassConcentrationUnit.MicrogramPerMicroliter)] + [InlineData("µg/ml", MassConcentrationUnit.MicrogramPerMilliliter)] + [InlineData("mg/m³", MassConcentrationUnit.MilligramPerCubicMeter)] + [InlineData("mg/dl", MassConcentrationUnit.MilligramPerDeciliter)] + [InlineData("mg/l", MassConcentrationUnit.MilligramPerLiter)] + [InlineData("mg/μl", MassConcentrationUnit.MilligramPerMicroliter)] + [InlineData("mg/ml", MassConcentrationUnit.MilligramPerMilliliter)] + [InlineData("ng/dl", MassConcentrationUnit.NanogramPerDeciliter)] + [InlineData("ng/l", MassConcentrationUnit.NanogramPerLiter)] + [InlineData("ng/μl", MassConcentrationUnit.NanogramPerMicroliter)] + [InlineData("ng/ml", MassConcentrationUnit.NanogramPerMilliliter)] + [InlineData("oz/gal (imp.)", MassConcentrationUnit.OuncePerImperialGallon)] + [InlineData("oz/gal (U.S.)", MassConcentrationUnit.OuncePerUSGallon)] + [InlineData("pg/dl", MassConcentrationUnit.PicogramPerDeciliter)] + [InlineData("pg/l", MassConcentrationUnit.PicogramPerLiter)] + [InlineData("pg/μl", MassConcentrationUnit.PicogramPerMicroliter)] + [InlineData("pg/ml", MassConcentrationUnit.PicogramPerMilliliter)] + [InlineData("lb/ft³", MassConcentrationUnit.PoundPerCubicFoot)] + [InlineData("lb/in³", MassConcentrationUnit.PoundPerCubicInch)] + [InlineData("ppg (imp.)", MassConcentrationUnit.PoundPerImperialGallon)] + [InlineData("ppg (U.S.)", MassConcentrationUnit.PoundPerUSGallon)] + [InlineData("slug/ft³", MassConcentrationUnit.SlugPerCubicFoot)] + [InlineData("t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter)] + [InlineData("t/m³", MassConcentrationUnit.TonnePerCubicMeter)] + [InlineData("t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassConcentrationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MassConcentrationUnit parsedUnit = MassConcentration.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1467,7 +1527,68 @@ public void ParseUnit(string abbreviation, MassConcentrationUnit expectedUnit) [InlineData("ru-RU", "кг/м³", MassConcentrationUnit.KilogramPerCubicMeter)] [InlineData("ru-RU", "мкг/м³", MassConcentrationUnit.MicrogramPerCubicMeter)] [InlineData("ru-RU", "мг/м³", MassConcentrationUnit.MilligramPerCubicMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, MassConcentrationUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MassConcentrationUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MassConcentrationUnit parsedUnit = MassConcentration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg/dl", MassConcentrationUnit.CentigramPerDeciliter)] + [InlineData("en-US", "cg/l", MassConcentrationUnit.CentigramPerLiter)] + [InlineData("en-US", "cg/μl", MassConcentrationUnit.CentigramPerMicroliter)] + [InlineData("en-US", "cg/ml", MassConcentrationUnit.CentigramPerMilliliter)] + [InlineData("en-US", "dg/dl", MassConcentrationUnit.DecigramPerDeciliter)] + [InlineData("en-US", "dg/l", MassConcentrationUnit.DecigramPerLiter)] + [InlineData("en-US", "dg/μl", MassConcentrationUnit.DecigramPerMicroliter)] + [InlineData("en-US", "dg/ml", MassConcentrationUnit.DecigramPerMilliliter)] + [InlineData("en-US", "g/cm³", MassConcentrationUnit.GramPerCubicCentimeter)] + [InlineData("en-US", "g/m³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("en-US", "g/mm³", MassConcentrationUnit.GramPerCubicMillimeter)] + [InlineData("en-US", "g/dl", MassConcentrationUnit.GramPerDeciliter)] + [InlineData("en-US", "g/l", MassConcentrationUnit.GramPerLiter)] + [InlineData("en-US", "g/μl", MassConcentrationUnit.GramPerMicroliter)] + [InlineData("en-US", "g/ml", MassConcentrationUnit.GramPerMilliliter)] + [InlineData("en-US", "kg/cm³", MassConcentrationUnit.KilogramPerCubicCentimeter)] + [InlineData("en-US", "kg/m³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("en-US", "kg/mm³", MassConcentrationUnit.KilogramPerCubicMillimeter)] + [InlineData("en-US", "kg/l", MassConcentrationUnit.KilogramPerLiter)] + [InlineData("en-US", "kip/ft³", MassConcentrationUnit.KilopoundPerCubicFoot)] + [InlineData("en-US", "kip/in³", MassConcentrationUnit.KilopoundPerCubicInch)] + [InlineData("en-US", "µg/m³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("en-US", "µg/dl", MassConcentrationUnit.MicrogramPerDeciliter)] + [InlineData("en-US", "µg/l", MassConcentrationUnit.MicrogramPerLiter)] + [InlineData("en-US", "µg/μl", MassConcentrationUnit.MicrogramPerMicroliter)] + [InlineData("en-US", "µg/ml", MassConcentrationUnit.MicrogramPerMilliliter)] + [InlineData("en-US", "mg/m³", MassConcentrationUnit.MilligramPerCubicMeter)] + [InlineData("en-US", "mg/dl", MassConcentrationUnit.MilligramPerDeciliter)] + [InlineData("en-US", "mg/l", MassConcentrationUnit.MilligramPerLiter)] + [InlineData("en-US", "mg/μl", MassConcentrationUnit.MilligramPerMicroliter)] + [InlineData("en-US", "mg/ml", MassConcentrationUnit.MilligramPerMilliliter)] + [InlineData("en-US", "ng/dl", MassConcentrationUnit.NanogramPerDeciliter)] + [InlineData("en-US", "ng/l", MassConcentrationUnit.NanogramPerLiter)] + [InlineData("en-US", "ng/μl", MassConcentrationUnit.NanogramPerMicroliter)] + [InlineData("en-US", "ng/ml", MassConcentrationUnit.NanogramPerMilliliter)] + [InlineData("en-US", "oz/gal (imp.)", MassConcentrationUnit.OuncePerImperialGallon)] + [InlineData("en-US", "oz/gal (U.S.)", MassConcentrationUnit.OuncePerUSGallon)] + [InlineData("en-US", "pg/dl", MassConcentrationUnit.PicogramPerDeciliter)] + [InlineData("en-US", "pg/l", MassConcentrationUnit.PicogramPerLiter)] + [InlineData("en-US", "pg/μl", MassConcentrationUnit.PicogramPerMicroliter)] + [InlineData("en-US", "pg/ml", MassConcentrationUnit.PicogramPerMilliliter)] + [InlineData("en-US", "lb/ft³", MassConcentrationUnit.PoundPerCubicFoot)] + [InlineData("en-US", "lb/in³", MassConcentrationUnit.PoundPerCubicInch)] + [InlineData("en-US", "ppg (imp.)", MassConcentrationUnit.PoundPerImperialGallon)] + [InlineData("en-US", "ppg (U.S.)", MassConcentrationUnit.PoundPerUSGallon)] + [InlineData("en-US", "slug/ft³", MassConcentrationUnit.SlugPerCubicFoot)] + [InlineData("en-US", "t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter)] + [InlineData("en-US", "t/m³", MassConcentrationUnit.TonnePerCubicMeter)] + [InlineData("en-US", "t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter)] + [InlineData("ru-RU", "г/м³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("ru-RU", "кг/м³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("ru-RU", "мкг/м³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("ru-RU", "мг/м³", MassConcentrationUnit.MilligramPerCubicMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MassConcentrationUnit expectedUnit) { MassConcentrationUnit parsedUnit = MassConcentration.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1523,9 +1644,129 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MassConcen [InlineData("t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter)] [InlineData("t/m³", MassConcentrationUnit.TonnePerCubicMeter)] [InlineData("t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter)] - public void TryParseUnit(string abbreviation, MassConcentrationUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassConcentrationUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(MassConcentration.TryParseUnit(abbreviation, out MassConcentrationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg/dl", MassConcentrationUnit.CentigramPerDeciliter)] + [InlineData("cg/l", MassConcentrationUnit.CentigramPerLiter)] + [InlineData("cg/μl", MassConcentrationUnit.CentigramPerMicroliter)] + [InlineData("cg/ml", MassConcentrationUnit.CentigramPerMilliliter)] + [InlineData("dg/dl", MassConcentrationUnit.DecigramPerDeciliter)] + [InlineData("dg/l", MassConcentrationUnit.DecigramPerLiter)] + [InlineData("dg/μl", MassConcentrationUnit.DecigramPerMicroliter)] + [InlineData("dg/ml", MassConcentrationUnit.DecigramPerMilliliter)] + [InlineData("g/cm³", MassConcentrationUnit.GramPerCubicCentimeter)] + [InlineData("g/m³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("g/mm³", MassConcentrationUnit.GramPerCubicMillimeter)] + [InlineData("g/dl", MassConcentrationUnit.GramPerDeciliter)] + [InlineData("g/l", MassConcentrationUnit.GramPerLiter)] + [InlineData("g/μl", MassConcentrationUnit.GramPerMicroliter)] + [InlineData("g/ml", MassConcentrationUnit.GramPerMilliliter)] + [InlineData("kg/cm³", MassConcentrationUnit.KilogramPerCubicCentimeter)] + [InlineData("kg/m³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("kg/mm³", MassConcentrationUnit.KilogramPerCubicMillimeter)] + [InlineData("kg/l", MassConcentrationUnit.KilogramPerLiter)] + [InlineData("kip/ft³", MassConcentrationUnit.KilopoundPerCubicFoot)] + [InlineData("kip/in³", MassConcentrationUnit.KilopoundPerCubicInch)] + [InlineData("µg/m³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("µg/dl", MassConcentrationUnit.MicrogramPerDeciliter)] + [InlineData("µg/l", MassConcentrationUnit.MicrogramPerLiter)] + [InlineData("µg/μl", MassConcentrationUnit.MicrogramPerMicroliter)] + [InlineData("µg/ml", MassConcentrationUnit.MicrogramPerMilliliter)] + [InlineData("mg/m³", MassConcentrationUnit.MilligramPerCubicMeter)] + [InlineData("mg/dl", MassConcentrationUnit.MilligramPerDeciliter)] + [InlineData("mg/l", MassConcentrationUnit.MilligramPerLiter)] + [InlineData("mg/μl", MassConcentrationUnit.MilligramPerMicroliter)] + [InlineData("mg/ml", MassConcentrationUnit.MilligramPerMilliliter)] + [InlineData("ng/dl", MassConcentrationUnit.NanogramPerDeciliter)] + [InlineData("ng/l", MassConcentrationUnit.NanogramPerLiter)] + [InlineData("ng/μl", MassConcentrationUnit.NanogramPerMicroliter)] + [InlineData("ng/ml", MassConcentrationUnit.NanogramPerMilliliter)] + [InlineData("oz/gal (imp.)", MassConcentrationUnit.OuncePerImperialGallon)] + [InlineData("oz/gal (U.S.)", MassConcentrationUnit.OuncePerUSGallon)] + [InlineData("pg/dl", MassConcentrationUnit.PicogramPerDeciliter)] + [InlineData("pg/l", MassConcentrationUnit.PicogramPerLiter)] + [InlineData("pg/μl", MassConcentrationUnit.PicogramPerMicroliter)] + [InlineData("pg/ml", MassConcentrationUnit.PicogramPerMilliliter)] + [InlineData("lb/ft³", MassConcentrationUnit.PoundPerCubicFoot)] + [InlineData("lb/in³", MassConcentrationUnit.PoundPerCubicInch)] + [InlineData("ppg (imp.)", MassConcentrationUnit.PoundPerImperialGallon)] + [InlineData("ppg (U.S.)", MassConcentrationUnit.PoundPerUSGallon)] + [InlineData("slug/ft³", MassConcentrationUnit.SlugPerCubicFoot)] + [InlineData("t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter)] + [InlineData("t/m³", MassConcentrationUnit.TonnePerCubicMeter)] + [InlineData("t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassConcentrationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(MassConcentration.TryParseUnit(abbreviation, out MassConcentrationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg/dl", MassConcentrationUnit.CentigramPerDeciliter)] + [InlineData("en-US", "cg/l", MassConcentrationUnit.CentigramPerLiter)] + [InlineData("en-US", "cg/μl", MassConcentrationUnit.CentigramPerMicroliter)] + [InlineData("en-US", "cg/ml", MassConcentrationUnit.CentigramPerMilliliter)] + [InlineData("en-US", "dg/dl", MassConcentrationUnit.DecigramPerDeciliter)] + [InlineData("en-US", "dg/l", MassConcentrationUnit.DecigramPerLiter)] + [InlineData("en-US", "dg/μl", MassConcentrationUnit.DecigramPerMicroliter)] + [InlineData("en-US", "dg/ml", MassConcentrationUnit.DecigramPerMilliliter)] + [InlineData("en-US", "g/cm³", MassConcentrationUnit.GramPerCubicCentimeter)] + [InlineData("en-US", "g/m³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("en-US", "g/mm³", MassConcentrationUnit.GramPerCubicMillimeter)] + [InlineData("en-US", "g/dl", MassConcentrationUnit.GramPerDeciliter)] + [InlineData("en-US", "g/l", MassConcentrationUnit.GramPerLiter)] + [InlineData("en-US", "g/μl", MassConcentrationUnit.GramPerMicroliter)] + [InlineData("en-US", "g/ml", MassConcentrationUnit.GramPerMilliliter)] + [InlineData("en-US", "kg/cm³", MassConcentrationUnit.KilogramPerCubicCentimeter)] + [InlineData("en-US", "kg/m³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("en-US", "kg/mm³", MassConcentrationUnit.KilogramPerCubicMillimeter)] + [InlineData("en-US", "kg/l", MassConcentrationUnit.KilogramPerLiter)] + [InlineData("en-US", "kip/ft³", MassConcentrationUnit.KilopoundPerCubicFoot)] + [InlineData("en-US", "kip/in³", MassConcentrationUnit.KilopoundPerCubicInch)] + [InlineData("en-US", "µg/m³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("en-US", "µg/dl", MassConcentrationUnit.MicrogramPerDeciliter)] + [InlineData("en-US", "µg/l", MassConcentrationUnit.MicrogramPerLiter)] + [InlineData("en-US", "µg/μl", MassConcentrationUnit.MicrogramPerMicroliter)] + [InlineData("en-US", "µg/ml", MassConcentrationUnit.MicrogramPerMilliliter)] + [InlineData("en-US", "mg/m³", MassConcentrationUnit.MilligramPerCubicMeter)] + [InlineData("en-US", "mg/dl", MassConcentrationUnit.MilligramPerDeciliter)] + [InlineData("en-US", "mg/l", MassConcentrationUnit.MilligramPerLiter)] + [InlineData("en-US", "mg/μl", MassConcentrationUnit.MilligramPerMicroliter)] + [InlineData("en-US", "mg/ml", MassConcentrationUnit.MilligramPerMilliliter)] + [InlineData("en-US", "ng/dl", MassConcentrationUnit.NanogramPerDeciliter)] + [InlineData("en-US", "ng/l", MassConcentrationUnit.NanogramPerLiter)] + [InlineData("en-US", "ng/μl", MassConcentrationUnit.NanogramPerMicroliter)] + [InlineData("en-US", "ng/ml", MassConcentrationUnit.NanogramPerMilliliter)] + [InlineData("en-US", "oz/gal (imp.)", MassConcentrationUnit.OuncePerImperialGallon)] + [InlineData("en-US", "oz/gal (U.S.)", MassConcentrationUnit.OuncePerUSGallon)] + [InlineData("en-US", "pg/dl", MassConcentrationUnit.PicogramPerDeciliter)] + [InlineData("en-US", "pg/l", MassConcentrationUnit.PicogramPerLiter)] + [InlineData("en-US", "pg/μl", MassConcentrationUnit.PicogramPerMicroliter)] + [InlineData("en-US", "pg/ml", MassConcentrationUnit.PicogramPerMilliliter)] + [InlineData("en-US", "lb/ft³", MassConcentrationUnit.PoundPerCubicFoot)] + [InlineData("en-US", "lb/in³", MassConcentrationUnit.PoundPerCubicInch)] + [InlineData("en-US", "ppg (imp.)", MassConcentrationUnit.PoundPerImperialGallon)] + [InlineData("en-US", "ppg (U.S.)", MassConcentrationUnit.PoundPerUSGallon)] + [InlineData("en-US", "slug/ft³", MassConcentrationUnit.SlugPerCubicFoot)] + [InlineData("en-US", "t/cm³", MassConcentrationUnit.TonnePerCubicCentimeter)] + [InlineData("en-US", "t/m³", MassConcentrationUnit.TonnePerCubicMeter)] + [InlineData("en-US", "t/mm³", MassConcentrationUnit.TonnePerCubicMillimeter)] + [InlineData("ru-RU", "г/м³", MassConcentrationUnit.GramPerCubicMeter)] + [InlineData("ru-RU", "кг/м³", MassConcentrationUnit.KilogramPerCubicMeter)] + [InlineData("ru-RU", "мкг/м³", MassConcentrationUnit.MicrogramPerCubicMeter)] + [InlineData("ru-RU", "мг/м³", MassConcentrationUnit.MilligramPerCubicMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MassConcentrationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(MassConcentration.TryParseUnit(abbreviation, out MassConcentrationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1584,7 +1825,7 @@ public void TryParseUnit(string abbreviation, MassConcentrationUnit expectedUnit [InlineData("ru-RU", "кг/м³", MassConcentrationUnit.KilogramPerCubicMeter)] [InlineData("ru-RU", "мкг/м³", MassConcentrationUnit.MicrogramPerCubicMeter)] [InlineData("ru-RU", "мг/м³", MassConcentrationUnit.MilligramPerCubicMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MassConcentrationUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MassConcentrationUnit expectedUnit) { Assert.True(MassConcentration.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassConcentrationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs index 621fe98a93..d38bfd6675 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFlowTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1110,10 +1111,62 @@ public void TryParse() [InlineData("short tn/h", MassFlowUnit.ShortTonPerHour)] [InlineData("t/d", MassFlowUnit.TonnePerDay)] [InlineData("t/h", MassFlowUnit.TonnePerHour)] - public void ParseUnit(string abbreviation, MassFlowUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassFlowUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MassFlowUnit parsedUnit = MassFlow.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MassFlowUnit parsedUnit = MassFlow.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg/d", MassFlowUnit.CentigramPerDay)] + [InlineData("cg/s", MassFlowUnit.CentigramPerSecond)] + [InlineData("cg/S", MassFlowUnit.CentigramPerSecond)] + [InlineData("dag/d", MassFlowUnit.DecagramPerDay)] + [InlineData("dag/s", MassFlowUnit.DecagramPerSecond)] + [InlineData("dag/S", MassFlowUnit.DecagramPerSecond)] + [InlineData("dg/d", MassFlowUnit.DecigramPerDay)] + [InlineData("dg/s", MassFlowUnit.DecigramPerSecond)] + [InlineData("dg/S", MassFlowUnit.DecigramPerSecond)] + [InlineData("g/d", MassFlowUnit.GramPerDay)] + [InlineData("g/h", MassFlowUnit.GramPerHour)] + [InlineData("g/s", MassFlowUnit.GramPerSecond)] + [InlineData("g/S", MassFlowUnit.GramPerSecond)] + [InlineData("hg/d", MassFlowUnit.HectogramPerDay)] + [InlineData("hg/s", MassFlowUnit.HectogramPerSecond)] + [InlineData("hg/S", MassFlowUnit.HectogramPerSecond)] + [InlineData("kg/d", MassFlowUnit.KilogramPerDay)] + [InlineData("kg/h", MassFlowUnit.KilogramPerHour)] + [InlineData("kg/min", MassFlowUnit.KilogramPerMinute)] + [InlineData("kg/s", MassFlowUnit.KilogramPerSecond)] + [InlineData("kg/S", MassFlowUnit.KilogramPerSecond)] + [InlineData("Mg/d", MassFlowUnit.MegagramPerDay)] + [InlineData("Mlb/d", MassFlowUnit.MegapoundPerDay)] + [InlineData("Mlb/h", MassFlowUnit.MegapoundPerHour)] + [InlineData("Mlb/min", MassFlowUnit.MegapoundPerMinute)] + [InlineData("Mlb/s", MassFlowUnit.MegapoundPerSecond)] + [InlineData("µg/d", MassFlowUnit.MicrogramPerDay)] + [InlineData("µg/s", MassFlowUnit.MicrogramPerSecond)] + [InlineData("µg/S", MassFlowUnit.MicrogramPerSecond)] + [InlineData("mg/d", MassFlowUnit.MilligramPerDay)] + [InlineData("mg/s", MassFlowUnit.MilligramPerSecond)] + [InlineData("mg/S", MassFlowUnit.MilligramPerSecond)] + [InlineData("ng/d", MassFlowUnit.NanogramPerDay)] + [InlineData("ng/s", MassFlowUnit.NanogramPerSecond)] + [InlineData("ng/S", MassFlowUnit.NanogramPerSecond)] + [InlineData("lb/d", MassFlowUnit.PoundPerDay)] + [InlineData("lb/h", MassFlowUnit.PoundPerHour)] + [InlineData("lb/min", MassFlowUnit.PoundPerMinute)] + [InlineData("lb/s", MassFlowUnit.PoundPerSecond)] + [InlineData("short tn/h", MassFlowUnit.ShortTonPerHour)] + [InlineData("t/d", MassFlowUnit.TonnePerDay)] + [InlineData("t/h", MassFlowUnit.TonnePerHour)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassFlowUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MassFlowUnit parsedUnit = MassFlow.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1162,7 +1215,59 @@ public void ParseUnit(string abbreviation, MassFlowUnit expectedUnit) [InlineData("en-US", "t/h", MassFlowUnit.TonnePerHour)] [InlineData("ru-RU", "кг/ч", MassFlowUnit.KilogramPerHour)] [InlineData("ru-RU", "кг/мин", MassFlowUnit.KilogramPerMinute)] - public void ParseUnitWithCulture(string culture, string abbreviation, MassFlowUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MassFlowUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MassFlowUnit parsedUnit = MassFlow.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg/d", MassFlowUnit.CentigramPerDay)] + [InlineData("en-US", "cg/s", MassFlowUnit.CentigramPerSecond)] + [InlineData("en-US", "cg/S", MassFlowUnit.CentigramPerSecond)] + [InlineData("en-US", "dag/d", MassFlowUnit.DecagramPerDay)] + [InlineData("en-US", "dag/s", MassFlowUnit.DecagramPerSecond)] + [InlineData("en-US", "dag/S", MassFlowUnit.DecagramPerSecond)] + [InlineData("en-US", "dg/d", MassFlowUnit.DecigramPerDay)] + [InlineData("en-US", "dg/s", MassFlowUnit.DecigramPerSecond)] + [InlineData("en-US", "dg/S", MassFlowUnit.DecigramPerSecond)] + [InlineData("en-US", "g/d", MassFlowUnit.GramPerDay)] + [InlineData("en-US", "g/h", MassFlowUnit.GramPerHour)] + [InlineData("en-US", "g/s", MassFlowUnit.GramPerSecond)] + [InlineData("en-US", "g/S", MassFlowUnit.GramPerSecond)] + [InlineData("en-US", "hg/d", MassFlowUnit.HectogramPerDay)] + [InlineData("en-US", "hg/s", MassFlowUnit.HectogramPerSecond)] + [InlineData("en-US", "hg/S", MassFlowUnit.HectogramPerSecond)] + [InlineData("en-US", "kg/d", MassFlowUnit.KilogramPerDay)] + [InlineData("en-US", "kg/h", MassFlowUnit.KilogramPerHour)] + [InlineData("en-US", "kg/min", MassFlowUnit.KilogramPerMinute)] + [InlineData("en-US", "kg/s", MassFlowUnit.KilogramPerSecond)] + [InlineData("en-US", "kg/S", MassFlowUnit.KilogramPerSecond)] + [InlineData("en-US", "Mg/d", MassFlowUnit.MegagramPerDay)] + [InlineData("en-US", "Mlb/d", MassFlowUnit.MegapoundPerDay)] + [InlineData("en-US", "Mlb/h", MassFlowUnit.MegapoundPerHour)] + [InlineData("en-US", "Mlb/min", MassFlowUnit.MegapoundPerMinute)] + [InlineData("en-US", "Mlb/s", MassFlowUnit.MegapoundPerSecond)] + [InlineData("en-US", "µg/d", MassFlowUnit.MicrogramPerDay)] + [InlineData("en-US", "µg/s", MassFlowUnit.MicrogramPerSecond)] + [InlineData("en-US", "µg/S", MassFlowUnit.MicrogramPerSecond)] + [InlineData("en-US", "mg/d", MassFlowUnit.MilligramPerDay)] + [InlineData("en-US", "mg/s", MassFlowUnit.MilligramPerSecond)] + [InlineData("en-US", "mg/S", MassFlowUnit.MilligramPerSecond)] + [InlineData("en-US", "ng/d", MassFlowUnit.NanogramPerDay)] + [InlineData("en-US", "ng/s", MassFlowUnit.NanogramPerSecond)] + [InlineData("en-US", "ng/S", MassFlowUnit.NanogramPerSecond)] + [InlineData("en-US", "lb/d", MassFlowUnit.PoundPerDay)] + [InlineData("en-US", "lb/h", MassFlowUnit.PoundPerHour)] + [InlineData("en-US", "lb/min", MassFlowUnit.PoundPerMinute)] + [InlineData("en-US", "lb/s", MassFlowUnit.PoundPerSecond)] + [InlineData("en-US", "short tn/h", MassFlowUnit.ShortTonPerHour)] + [InlineData("en-US", "t/d", MassFlowUnit.TonnePerDay)] + [InlineData("en-US", "t/h", MassFlowUnit.TonnePerHour)] + [InlineData("ru-RU", "кг/ч", MassFlowUnit.KilogramPerHour)] + [InlineData("ru-RU", "кг/мин", MassFlowUnit.KilogramPerMinute)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MassFlowUnit expectedUnit) { MassFlowUnit parsedUnit = MassFlow.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1211,9 +1316,113 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MassFlowUn [InlineData("short tn/h", MassFlowUnit.ShortTonPerHour)] [InlineData("t/d", MassFlowUnit.TonnePerDay)] [InlineData("t/h", MassFlowUnit.TonnePerHour)] - public void TryParseUnit(string abbreviation, MassFlowUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassFlowUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(MassFlow.TryParseUnit(abbreviation, out MassFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg/d", MassFlowUnit.CentigramPerDay)] + [InlineData("cg/s", MassFlowUnit.CentigramPerSecond)] + [InlineData("cg/S", MassFlowUnit.CentigramPerSecond)] + [InlineData("dag/d", MassFlowUnit.DecagramPerDay)] + [InlineData("dag/s", MassFlowUnit.DecagramPerSecond)] + [InlineData("dag/S", MassFlowUnit.DecagramPerSecond)] + [InlineData("dg/d", MassFlowUnit.DecigramPerDay)] + [InlineData("dg/s", MassFlowUnit.DecigramPerSecond)] + [InlineData("dg/S", MassFlowUnit.DecigramPerSecond)] + [InlineData("g/d", MassFlowUnit.GramPerDay)] + [InlineData("g/h", MassFlowUnit.GramPerHour)] + [InlineData("g/s", MassFlowUnit.GramPerSecond)] + [InlineData("g/S", MassFlowUnit.GramPerSecond)] + [InlineData("hg/d", MassFlowUnit.HectogramPerDay)] + [InlineData("hg/s", MassFlowUnit.HectogramPerSecond)] + [InlineData("hg/S", MassFlowUnit.HectogramPerSecond)] + [InlineData("kg/d", MassFlowUnit.KilogramPerDay)] + [InlineData("kg/h", MassFlowUnit.KilogramPerHour)] + [InlineData("kg/min", MassFlowUnit.KilogramPerMinute)] + [InlineData("kg/s", MassFlowUnit.KilogramPerSecond)] + [InlineData("kg/S", MassFlowUnit.KilogramPerSecond)] + [InlineData("Mg/d", MassFlowUnit.MegagramPerDay)] + [InlineData("Mlb/d", MassFlowUnit.MegapoundPerDay)] + [InlineData("Mlb/h", MassFlowUnit.MegapoundPerHour)] + [InlineData("Mlb/min", MassFlowUnit.MegapoundPerMinute)] + [InlineData("Mlb/s", MassFlowUnit.MegapoundPerSecond)] + [InlineData("µg/d", MassFlowUnit.MicrogramPerDay)] + [InlineData("µg/s", MassFlowUnit.MicrogramPerSecond)] + [InlineData("µg/S", MassFlowUnit.MicrogramPerSecond)] + [InlineData("mg/d", MassFlowUnit.MilligramPerDay)] + [InlineData("mg/s", MassFlowUnit.MilligramPerSecond)] + [InlineData("mg/S", MassFlowUnit.MilligramPerSecond)] + [InlineData("ng/d", MassFlowUnit.NanogramPerDay)] + [InlineData("ng/s", MassFlowUnit.NanogramPerSecond)] + [InlineData("ng/S", MassFlowUnit.NanogramPerSecond)] + [InlineData("lb/d", MassFlowUnit.PoundPerDay)] + [InlineData("lb/h", MassFlowUnit.PoundPerHour)] + [InlineData("lb/min", MassFlowUnit.PoundPerMinute)] + [InlineData("lb/s", MassFlowUnit.PoundPerSecond)] + [InlineData("short tn/h", MassFlowUnit.ShortTonPerHour)] + [InlineData("t/d", MassFlowUnit.TonnePerDay)] + [InlineData("t/h", MassFlowUnit.TonnePerHour)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassFlowUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(MassFlow.TryParseUnit(abbreviation, out MassFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg/d", MassFlowUnit.CentigramPerDay)] + [InlineData("en-US", "cg/s", MassFlowUnit.CentigramPerSecond)] + [InlineData("en-US", "cg/S", MassFlowUnit.CentigramPerSecond)] + [InlineData("en-US", "dag/d", MassFlowUnit.DecagramPerDay)] + [InlineData("en-US", "dag/s", MassFlowUnit.DecagramPerSecond)] + [InlineData("en-US", "dag/S", MassFlowUnit.DecagramPerSecond)] + [InlineData("en-US", "dg/d", MassFlowUnit.DecigramPerDay)] + [InlineData("en-US", "dg/s", MassFlowUnit.DecigramPerSecond)] + [InlineData("en-US", "dg/S", MassFlowUnit.DecigramPerSecond)] + [InlineData("en-US", "g/d", MassFlowUnit.GramPerDay)] + [InlineData("en-US", "g/h", MassFlowUnit.GramPerHour)] + [InlineData("en-US", "g/s", MassFlowUnit.GramPerSecond)] + [InlineData("en-US", "g/S", MassFlowUnit.GramPerSecond)] + [InlineData("en-US", "hg/d", MassFlowUnit.HectogramPerDay)] + [InlineData("en-US", "hg/s", MassFlowUnit.HectogramPerSecond)] + [InlineData("en-US", "hg/S", MassFlowUnit.HectogramPerSecond)] + [InlineData("en-US", "kg/d", MassFlowUnit.KilogramPerDay)] + [InlineData("en-US", "kg/h", MassFlowUnit.KilogramPerHour)] + [InlineData("en-US", "kg/min", MassFlowUnit.KilogramPerMinute)] + [InlineData("en-US", "kg/s", MassFlowUnit.KilogramPerSecond)] + [InlineData("en-US", "kg/S", MassFlowUnit.KilogramPerSecond)] + [InlineData("en-US", "Mg/d", MassFlowUnit.MegagramPerDay)] + [InlineData("en-US", "Mlb/d", MassFlowUnit.MegapoundPerDay)] + [InlineData("en-US", "Mlb/h", MassFlowUnit.MegapoundPerHour)] + [InlineData("en-US", "Mlb/min", MassFlowUnit.MegapoundPerMinute)] + [InlineData("en-US", "Mlb/s", MassFlowUnit.MegapoundPerSecond)] + [InlineData("en-US", "µg/d", MassFlowUnit.MicrogramPerDay)] + [InlineData("en-US", "µg/s", MassFlowUnit.MicrogramPerSecond)] + [InlineData("en-US", "µg/S", MassFlowUnit.MicrogramPerSecond)] + [InlineData("en-US", "mg/d", MassFlowUnit.MilligramPerDay)] + [InlineData("en-US", "mg/s", MassFlowUnit.MilligramPerSecond)] + [InlineData("en-US", "mg/S", MassFlowUnit.MilligramPerSecond)] + [InlineData("en-US", "ng/d", MassFlowUnit.NanogramPerDay)] + [InlineData("en-US", "ng/s", MassFlowUnit.NanogramPerSecond)] + [InlineData("en-US", "ng/S", MassFlowUnit.NanogramPerSecond)] + [InlineData("en-US", "lb/d", MassFlowUnit.PoundPerDay)] + [InlineData("en-US", "lb/h", MassFlowUnit.PoundPerHour)] + [InlineData("en-US", "lb/min", MassFlowUnit.PoundPerMinute)] + [InlineData("en-US", "lb/s", MassFlowUnit.PoundPerSecond)] + [InlineData("en-US", "short tn/h", MassFlowUnit.ShortTonPerHour)] + [InlineData("en-US", "t/d", MassFlowUnit.TonnePerDay)] + [InlineData("en-US", "t/h", MassFlowUnit.TonnePerHour)] + [InlineData("ru-RU", "кг/ч", MassFlowUnit.KilogramPerHour)] + [InlineData("ru-RU", "кг/мин", MassFlowUnit.KilogramPerMinute)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MassFlowUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(MassFlow.TryParseUnit(abbreviation, out MassFlowUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1263,7 +1472,7 @@ public void TryParseUnit(string abbreviation, MassFlowUnit expectedUnit) [InlineData("en-US", "t/h", MassFlowUnit.TonnePerHour)] [InlineData("ru-RU", "кг/ч", MassFlowUnit.KilogramPerHour)] [InlineData("ru-RU", "кг/мин", MassFlowUnit.KilogramPerMinute)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MassFlowUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MassFlowUnit expectedUnit) { Assert.True(MassFlow.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassFlowUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs index 043feb6510..997524a792 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFluxTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -466,10 +467,32 @@ public void TryParse() [InlineData("kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] [InlineData("kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] [InlineData("kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] - public void ParseUnit(string abbreviation, MassFluxUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassFluxUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MassFluxUnit parsedUnit = MassFlux.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MassFluxUnit parsedUnit = MassFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g·h⁻¹·cm⁻²", MassFluxUnit.GramPerHourPerSquareCentimeter)] + [InlineData("g·h⁻¹·m⁻²", MassFluxUnit.GramPerHourPerSquareMeter)] + [InlineData("g·h⁻¹·mm⁻²", MassFluxUnit.GramPerHourPerSquareMillimeter)] + [InlineData("g·s⁻¹·cm⁻²", MassFluxUnit.GramPerSecondPerSquareCentimeter)] + [InlineData("g·s⁻¹·m⁻²", MassFluxUnit.GramPerSecondPerSquareMeter)] + [InlineData("g·s⁻¹·mm⁻²", MassFluxUnit.GramPerSecondPerSquareMillimeter)] + [InlineData("kg·h⁻¹·cm⁻²", MassFluxUnit.KilogramPerHourPerSquareCentimeter)] + [InlineData("kg·h⁻¹·m⁻²", MassFluxUnit.KilogramPerHourPerSquareMeter)] + [InlineData("kg·h⁻¹·mm⁻²", MassFluxUnit.KilogramPerHourPerSquareMillimeter)] + [InlineData("kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] + [InlineData("kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] + [InlineData("kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassFluxUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MassFluxUnit parsedUnit = MassFlux.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -486,7 +509,27 @@ public void ParseUnit(string abbreviation, MassFluxUnit expectedUnit) [InlineData("en-US", "kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] [InlineData("en-US", "kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] [InlineData("en-US", "kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, MassFluxUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MassFluxUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MassFluxUnit parsedUnit = MassFlux.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g·h⁻¹·cm⁻²", MassFluxUnit.GramPerHourPerSquareCentimeter)] + [InlineData("en-US", "g·h⁻¹·m⁻²", MassFluxUnit.GramPerHourPerSquareMeter)] + [InlineData("en-US", "g·h⁻¹·mm⁻²", MassFluxUnit.GramPerHourPerSquareMillimeter)] + [InlineData("en-US", "g·s⁻¹·cm⁻²", MassFluxUnit.GramPerSecondPerSquareCentimeter)] + [InlineData("en-US", "g·s⁻¹·m⁻²", MassFluxUnit.GramPerSecondPerSquareMeter)] + [InlineData("en-US", "g·s⁻¹·mm⁻²", MassFluxUnit.GramPerSecondPerSquareMillimeter)] + [InlineData("en-US", "kg·h⁻¹·cm⁻²", MassFluxUnit.KilogramPerHourPerSquareCentimeter)] + [InlineData("en-US", "kg·h⁻¹·m⁻²", MassFluxUnit.KilogramPerHourPerSquareMeter)] + [InlineData("en-US", "kg·h⁻¹·mm⁻²", MassFluxUnit.KilogramPerHourPerSquareMillimeter)] + [InlineData("en-US", "kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] + [InlineData("en-US", "kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] + [InlineData("en-US", "kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MassFluxUnit expectedUnit) { MassFluxUnit parsedUnit = MassFlux.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -505,9 +548,51 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MassFluxUn [InlineData("kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] [InlineData("kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] [InlineData("kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] - public void TryParseUnit(string abbreviation, MassFluxUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassFluxUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(MassFlux.TryParseUnit(abbreviation, out MassFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g·h⁻¹·cm⁻²", MassFluxUnit.GramPerHourPerSquareCentimeter)] + [InlineData("g·h⁻¹·m⁻²", MassFluxUnit.GramPerHourPerSquareMeter)] + [InlineData("g·h⁻¹·mm⁻²", MassFluxUnit.GramPerHourPerSquareMillimeter)] + [InlineData("g·s⁻¹·cm⁻²", MassFluxUnit.GramPerSecondPerSquareCentimeter)] + [InlineData("g·s⁻¹·m⁻²", MassFluxUnit.GramPerSecondPerSquareMeter)] + [InlineData("g·s⁻¹·mm⁻²", MassFluxUnit.GramPerSecondPerSquareMillimeter)] + [InlineData("kg·h⁻¹·cm⁻²", MassFluxUnit.KilogramPerHourPerSquareCentimeter)] + [InlineData("kg·h⁻¹·m⁻²", MassFluxUnit.KilogramPerHourPerSquareMeter)] + [InlineData("kg·h⁻¹·mm⁻²", MassFluxUnit.KilogramPerHourPerSquareMillimeter)] + [InlineData("kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] + [InlineData("kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] + [InlineData("kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassFluxUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(MassFlux.TryParseUnit(abbreviation, out MassFluxUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g·h⁻¹·cm⁻²", MassFluxUnit.GramPerHourPerSquareCentimeter)] + [InlineData("en-US", "g·h⁻¹·m⁻²", MassFluxUnit.GramPerHourPerSquareMeter)] + [InlineData("en-US", "g·h⁻¹·mm⁻²", MassFluxUnit.GramPerHourPerSquareMillimeter)] + [InlineData("en-US", "g·s⁻¹·cm⁻²", MassFluxUnit.GramPerSecondPerSquareCentimeter)] + [InlineData("en-US", "g·s⁻¹·m⁻²", MassFluxUnit.GramPerSecondPerSquareMeter)] + [InlineData("en-US", "g·s⁻¹·mm⁻²", MassFluxUnit.GramPerSecondPerSquareMillimeter)] + [InlineData("en-US", "kg·h⁻¹·cm⁻²", MassFluxUnit.KilogramPerHourPerSquareCentimeter)] + [InlineData("en-US", "kg·h⁻¹·m⁻²", MassFluxUnit.KilogramPerHourPerSquareMeter)] + [InlineData("en-US", "kg·h⁻¹·mm⁻²", MassFluxUnit.KilogramPerHourPerSquareMillimeter)] + [InlineData("en-US", "kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] + [InlineData("en-US", "kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] + [InlineData("en-US", "kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MassFluxUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(MassFlux.TryParseUnit(abbreviation, out MassFluxUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -525,7 +610,7 @@ public void TryParseUnit(string abbreviation, MassFluxUnit expectedUnit) [InlineData("en-US", "kg·s⁻¹·cm⁻²", MassFluxUnit.KilogramPerSecondPerSquareCentimeter)] [InlineData("en-US", "kg·s⁻¹·m⁻²", MassFluxUnit.KilogramPerSecondPerSquareMeter)] [InlineData("en-US", "kg·s⁻¹·mm⁻²", MassFluxUnit.KilogramPerSecondPerSquareMillimeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MassFluxUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MassFluxUnit expectedUnit) { Assert.True(MassFlux.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassFluxUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs index 4305c0a56b..865f588c3d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassFractionTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -768,10 +769,45 @@ public void TryParse() [InlineData("ppt", MassFractionUnit.PartPerTrillion)] [InlineData("%", MassFractionUnit.Percent)] [InlineData("% (w/w)", MassFractionUnit.Percent)] - public void ParseUnit(string abbreviation, MassFractionUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassFractionUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MassFractionUnit parsedUnit = MassFraction.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MassFractionUnit parsedUnit = MassFraction.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg/g", MassFractionUnit.CentigramPerGram)] + [InlineData("cg/kg", MassFractionUnit.CentigramPerKilogram)] + [InlineData("dag/g", MassFractionUnit.DecagramPerGram)] + [InlineData("dag/kg", MassFractionUnit.DecagramPerKilogram)] + [InlineData("dg/g", MassFractionUnit.DecigramPerGram)] + [InlineData("dg/kg", MassFractionUnit.DecigramPerKilogram)] + [InlineData("", MassFractionUnit.DecimalFraction)] + [InlineData("g/g", MassFractionUnit.GramPerGram)] + [InlineData("g/kg", MassFractionUnit.GramPerKilogram)] + [InlineData("hg/g", MassFractionUnit.HectogramPerGram)] + [InlineData("hg/kg", MassFractionUnit.HectogramPerKilogram)] + [InlineData("kg/g", MassFractionUnit.KilogramPerGram)] + [InlineData("kg/kg", MassFractionUnit.KilogramPerKilogram)] + [InlineData("µg/g", MassFractionUnit.MicrogramPerGram)] + [InlineData("µg/kg", MassFractionUnit.MicrogramPerKilogram)] + [InlineData("mg/g", MassFractionUnit.MilligramPerGram)] + [InlineData("mg/kg", MassFractionUnit.MilligramPerKilogram)] + [InlineData("ng/g", MassFractionUnit.NanogramPerGram)] + [InlineData("ng/kg", MassFractionUnit.NanogramPerKilogram)] + [InlineData("ppb", MassFractionUnit.PartPerBillion)] + [InlineData("ppm", MassFractionUnit.PartPerMillion)] + [InlineData("‰", MassFractionUnit.PartPerThousand)] + [InlineData("ppt", MassFractionUnit.PartPerTrillion)] + [InlineData("%", MassFractionUnit.Percent)] + [InlineData("% (w/w)", MassFractionUnit.Percent)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassFractionUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MassFractionUnit parsedUnit = MassFraction.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -801,7 +837,40 @@ public void ParseUnit(string abbreviation, MassFractionUnit expectedUnit) [InlineData("en-US", "ppt", MassFractionUnit.PartPerTrillion)] [InlineData("en-US", "%", MassFractionUnit.Percent)] [InlineData("en-US", "% (w/w)", MassFractionUnit.Percent)] - public void ParseUnitWithCulture(string culture, string abbreviation, MassFractionUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MassFractionUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MassFractionUnit parsedUnit = MassFraction.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg/g", MassFractionUnit.CentigramPerGram)] + [InlineData("en-US", "cg/kg", MassFractionUnit.CentigramPerKilogram)] + [InlineData("en-US", "dag/g", MassFractionUnit.DecagramPerGram)] + [InlineData("en-US", "dag/kg", MassFractionUnit.DecagramPerKilogram)] + [InlineData("en-US", "dg/g", MassFractionUnit.DecigramPerGram)] + [InlineData("en-US", "dg/kg", MassFractionUnit.DecigramPerKilogram)] + [InlineData("en-US", "", MassFractionUnit.DecimalFraction)] + [InlineData("en-US", "g/g", MassFractionUnit.GramPerGram)] + [InlineData("en-US", "g/kg", MassFractionUnit.GramPerKilogram)] + [InlineData("en-US", "hg/g", MassFractionUnit.HectogramPerGram)] + [InlineData("en-US", "hg/kg", MassFractionUnit.HectogramPerKilogram)] + [InlineData("en-US", "kg/g", MassFractionUnit.KilogramPerGram)] + [InlineData("en-US", "kg/kg", MassFractionUnit.KilogramPerKilogram)] + [InlineData("en-US", "µg/g", MassFractionUnit.MicrogramPerGram)] + [InlineData("en-US", "µg/kg", MassFractionUnit.MicrogramPerKilogram)] + [InlineData("en-US", "mg/g", MassFractionUnit.MilligramPerGram)] + [InlineData("en-US", "mg/kg", MassFractionUnit.MilligramPerKilogram)] + [InlineData("en-US", "ng/g", MassFractionUnit.NanogramPerGram)] + [InlineData("en-US", "ng/kg", MassFractionUnit.NanogramPerKilogram)] + [InlineData("en-US", "ppb", MassFractionUnit.PartPerBillion)] + [InlineData("en-US", "ppm", MassFractionUnit.PartPerMillion)] + [InlineData("en-US", "‰", MassFractionUnit.PartPerThousand)] + [InlineData("en-US", "ppt", MassFractionUnit.PartPerTrillion)] + [InlineData("en-US", "%", MassFractionUnit.Percent)] + [InlineData("en-US", "% (w/w)", MassFractionUnit.Percent)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MassFractionUnit expectedUnit) { MassFractionUnit parsedUnit = MassFraction.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -833,9 +902,77 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MassFracti [InlineData("ppt", MassFractionUnit.PartPerTrillion)] [InlineData("%", MassFractionUnit.Percent)] [InlineData("% (w/w)", MassFractionUnit.Percent)] - public void TryParseUnit(string abbreviation, MassFractionUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassFractionUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(MassFraction.TryParseUnit(abbreviation, out MassFractionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg/g", MassFractionUnit.CentigramPerGram)] + [InlineData("cg/kg", MassFractionUnit.CentigramPerKilogram)] + [InlineData("dag/g", MassFractionUnit.DecagramPerGram)] + [InlineData("dag/kg", MassFractionUnit.DecagramPerKilogram)] + [InlineData("dg/g", MassFractionUnit.DecigramPerGram)] + [InlineData("dg/kg", MassFractionUnit.DecigramPerKilogram)] + [InlineData("", MassFractionUnit.DecimalFraction)] + [InlineData("g/g", MassFractionUnit.GramPerGram)] + [InlineData("g/kg", MassFractionUnit.GramPerKilogram)] + [InlineData("hg/g", MassFractionUnit.HectogramPerGram)] + [InlineData("hg/kg", MassFractionUnit.HectogramPerKilogram)] + [InlineData("kg/g", MassFractionUnit.KilogramPerGram)] + [InlineData("kg/kg", MassFractionUnit.KilogramPerKilogram)] + [InlineData("µg/g", MassFractionUnit.MicrogramPerGram)] + [InlineData("µg/kg", MassFractionUnit.MicrogramPerKilogram)] + [InlineData("mg/g", MassFractionUnit.MilligramPerGram)] + [InlineData("mg/kg", MassFractionUnit.MilligramPerKilogram)] + [InlineData("ng/g", MassFractionUnit.NanogramPerGram)] + [InlineData("ng/kg", MassFractionUnit.NanogramPerKilogram)] + [InlineData("ppb", MassFractionUnit.PartPerBillion)] + [InlineData("ppm", MassFractionUnit.PartPerMillion)] + [InlineData("‰", MassFractionUnit.PartPerThousand)] + [InlineData("ppt", MassFractionUnit.PartPerTrillion)] + [InlineData("%", MassFractionUnit.Percent)] + [InlineData("% (w/w)", MassFractionUnit.Percent)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassFractionUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(MassFraction.TryParseUnit(abbreviation, out MassFractionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg/g", MassFractionUnit.CentigramPerGram)] + [InlineData("en-US", "cg/kg", MassFractionUnit.CentigramPerKilogram)] + [InlineData("en-US", "dag/g", MassFractionUnit.DecagramPerGram)] + [InlineData("en-US", "dag/kg", MassFractionUnit.DecagramPerKilogram)] + [InlineData("en-US", "dg/g", MassFractionUnit.DecigramPerGram)] + [InlineData("en-US", "dg/kg", MassFractionUnit.DecigramPerKilogram)] + [InlineData("en-US", "", MassFractionUnit.DecimalFraction)] + [InlineData("en-US", "g/g", MassFractionUnit.GramPerGram)] + [InlineData("en-US", "g/kg", MassFractionUnit.GramPerKilogram)] + [InlineData("en-US", "hg/g", MassFractionUnit.HectogramPerGram)] + [InlineData("en-US", "hg/kg", MassFractionUnit.HectogramPerKilogram)] + [InlineData("en-US", "kg/g", MassFractionUnit.KilogramPerGram)] + [InlineData("en-US", "kg/kg", MassFractionUnit.KilogramPerKilogram)] + [InlineData("en-US", "µg/g", MassFractionUnit.MicrogramPerGram)] + [InlineData("en-US", "µg/kg", MassFractionUnit.MicrogramPerKilogram)] + [InlineData("en-US", "mg/g", MassFractionUnit.MilligramPerGram)] + [InlineData("en-US", "mg/kg", MassFractionUnit.MilligramPerKilogram)] + [InlineData("en-US", "ng/g", MassFractionUnit.NanogramPerGram)] + [InlineData("en-US", "ng/kg", MassFractionUnit.NanogramPerKilogram)] + [InlineData("en-US", "ppb", MassFractionUnit.PartPerBillion)] + [InlineData("en-US", "ppm", MassFractionUnit.PartPerMillion)] + [InlineData("en-US", "‰", MassFractionUnit.PartPerThousand)] + [InlineData("en-US", "ppt", MassFractionUnit.PartPerTrillion)] + [InlineData("en-US", "%", MassFractionUnit.Percent)] + [InlineData("en-US", "% (w/w)", MassFractionUnit.Percent)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MassFractionUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(MassFraction.TryParseUnit(abbreviation, out MassFractionUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -866,7 +1003,7 @@ public void TryParseUnit(string abbreviation, MassFractionUnit expectedUnit) [InlineData("en-US", "ppt", MassFractionUnit.PartPerTrillion)] [InlineData("en-US", "%", MassFractionUnit.Percent)] [InlineData("en-US", "% (w/w)", MassFractionUnit.Percent)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MassFractionUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MassFractionUnit expectedUnit) { Assert.True(MassFraction.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassFractionUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs index e017d09326..27cbc86cbd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassMomentOfInertiaTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -850,10 +851,48 @@ public void TryParse() [InlineData("t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] [InlineData("t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] [InlineData("t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] - public void ParseUnit(string abbreviation, MassMomentOfInertiaUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassMomentOfInertiaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MassMomentOfInertiaUnit parsedUnit = MassMomentOfInertia.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MassMomentOfInertiaUnit parsedUnit = MassMomentOfInertia.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g·cm²", MassMomentOfInertiaUnit.GramSquareCentimeter)] + [InlineData("g·dm²", MassMomentOfInertiaUnit.GramSquareDecimeter)] + [InlineData("g·m²", MassMomentOfInertiaUnit.GramSquareMeter)] + [InlineData("g·mm²", MassMomentOfInertiaUnit.GramSquareMillimeter)] + [InlineData("kg·cm²", MassMomentOfInertiaUnit.KilogramSquareCentimeter)] + [InlineData("kg·dm²", MassMomentOfInertiaUnit.KilogramSquareDecimeter)] + [InlineData("kg·m²", MassMomentOfInertiaUnit.KilogramSquareMeter)] + [InlineData("kg·mm²", MassMomentOfInertiaUnit.KilogramSquareMillimeter)] + [InlineData("kt·cm²", MassMomentOfInertiaUnit.KilotonneSquareCentimeter)] + [InlineData("kt·dm²", MassMomentOfInertiaUnit.KilotonneSquareDecimeter)] + [InlineData("kt·m²", MassMomentOfInertiaUnit.KilotonneSquareMeter)] + [InlineData("kt·mm²", MassMomentOfInertiaUnit.KilotonneSquareMilimeter)] + [InlineData("Mt·cm²", MassMomentOfInertiaUnit.MegatonneSquareCentimeter)] + [InlineData("Mt·dm²", MassMomentOfInertiaUnit.MegatonneSquareDecimeter)] + [InlineData("Mt·m²", MassMomentOfInertiaUnit.MegatonneSquareMeter)] + [InlineData("Mt·mm²", MassMomentOfInertiaUnit.MegatonneSquareMilimeter)] + [InlineData("mg·cm²", MassMomentOfInertiaUnit.MilligramSquareCentimeter)] + [InlineData("mg·dm²", MassMomentOfInertiaUnit.MilligramSquareDecimeter)] + [InlineData("mg·m²", MassMomentOfInertiaUnit.MilligramSquareMeter)] + [InlineData("mg·mm²", MassMomentOfInertiaUnit.MilligramSquareMillimeter)] + [InlineData("lb·ft²", MassMomentOfInertiaUnit.PoundSquareFoot)] + [InlineData("lb·in²", MassMomentOfInertiaUnit.PoundSquareInch)] + [InlineData("slug·ft²", MassMomentOfInertiaUnit.SlugSquareFoot)] + [InlineData("slug·in²", MassMomentOfInertiaUnit.SlugSquareInch)] + [InlineData("t·cm²", MassMomentOfInertiaUnit.TonneSquareCentimeter)] + [InlineData("t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] + [InlineData("t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] + [InlineData("t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassMomentOfInertiaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MassMomentOfInertiaUnit parsedUnit = MassMomentOfInertia.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -886,7 +925,43 @@ public void ParseUnit(string abbreviation, MassMomentOfInertiaUnit expectedUnit) [InlineData("en-US", "t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] [InlineData("en-US", "t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] [InlineData("en-US", "t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, MassMomentOfInertiaUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MassMomentOfInertiaUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MassMomentOfInertiaUnit parsedUnit = MassMomentOfInertia.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g·cm²", MassMomentOfInertiaUnit.GramSquareCentimeter)] + [InlineData("en-US", "g·dm²", MassMomentOfInertiaUnit.GramSquareDecimeter)] + [InlineData("en-US", "g·m²", MassMomentOfInertiaUnit.GramSquareMeter)] + [InlineData("en-US", "g·mm²", MassMomentOfInertiaUnit.GramSquareMillimeter)] + [InlineData("en-US", "kg·cm²", MassMomentOfInertiaUnit.KilogramSquareCentimeter)] + [InlineData("en-US", "kg·dm²", MassMomentOfInertiaUnit.KilogramSquareDecimeter)] + [InlineData("en-US", "kg·m²", MassMomentOfInertiaUnit.KilogramSquareMeter)] + [InlineData("en-US", "kg·mm²", MassMomentOfInertiaUnit.KilogramSquareMillimeter)] + [InlineData("en-US", "kt·cm²", MassMomentOfInertiaUnit.KilotonneSquareCentimeter)] + [InlineData("en-US", "kt·dm²", MassMomentOfInertiaUnit.KilotonneSquareDecimeter)] + [InlineData("en-US", "kt·m²", MassMomentOfInertiaUnit.KilotonneSquareMeter)] + [InlineData("en-US", "kt·mm²", MassMomentOfInertiaUnit.KilotonneSquareMilimeter)] + [InlineData("en-US", "Mt·cm²", MassMomentOfInertiaUnit.MegatonneSquareCentimeter)] + [InlineData("en-US", "Mt·dm²", MassMomentOfInertiaUnit.MegatonneSquareDecimeter)] + [InlineData("en-US", "Mt·m²", MassMomentOfInertiaUnit.MegatonneSquareMeter)] + [InlineData("en-US", "Mt·mm²", MassMomentOfInertiaUnit.MegatonneSquareMilimeter)] + [InlineData("en-US", "mg·cm²", MassMomentOfInertiaUnit.MilligramSquareCentimeter)] + [InlineData("en-US", "mg·dm²", MassMomentOfInertiaUnit.MilligramSquareDecimeter)] + [InlineData("en-US", "mg·m²", MassMomentOfInertiaUnit.MilligramSquareMeter)] + [InlineData("en-US", "mg·mm²", MassMomentOfInertiaUnit.MilligramSquareMillimeter)] + [InlineData("en-US", "lb·ft²", MassMomentOfInertiaUnit.PoundSquareFoot)] + [InlineData("en-US", "lb·in²", MassMomentOfInertiaUnit.PoundSquareInch)] + [InlineData("en-US", "slug·ft²", MassMomentOfInertiaUnit.SlugSquareFoot)] + [InlineData("en-US", "slug·in²", MassMomentOfInertiaUnit.SlugSquareInch)] + [InlineData("en-US", "t·cm²", MassMomentOfInertiaUnit.TonneSquareCentimeter)] + [InlineData("en-US", "t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] + [InlineData("en-US", "t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] + [InlineData("en-US", "t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MassMomentOfInertiaUnit expectedUnit) { MassMomentOfInertiaUnit parsedUnit = MassMomentOfInertia.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -921,9 +996,83 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MassMoment [InlineData("t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] [InlineData("t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] [InlineData("t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] - public void TryParseUnit(string abbreviation, MassMomentOfInertiaUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassMomentOfInertiaUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(MassMomentOfInertia.TryParseUnit(abbreviation, out MassMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g·cm²", MassMomentOfInertiaUnit.GramSquareCentimeter)] + [InlineData("g·dm²", MassMomentOfInertiaUnit.GramSquareDecimeter)] + [InlineData("g·m²", MassMomentOfInertiaUnit.GramSquareMeter)] + [InlineData("g·mm²", MassMomentOfInertiaUnit.GramSquareMillimeter)] + [InlineData("kg·cm²", MassMomentOfInertiaUnit.KilogramSquareCentimeter)] + [InlineData("kg·dm²", MassMomentOfInertiaUnit.KilogramSquareDecimeter)] + [InlineData("kg·m²", MassMomentOfInertiaUnit.KilogramSquareMeter)] + [InlineData("kg·mm²", MassMomentOfInertiaUnit.KilogramSquareMillimeter)] + [InlineData("kt·cm²", MassMomentOfInertiaUnit.KilotonneSquareCentimeter)] + [InlineData("kt·dm²", MassMomentOfInertiaUnit.KilotonneSquareDecimeter)] + [InlineData("kt·m²", MassMomentOfInertiaUnit.KilotonneSquareMeter)] + [InlineData("kt·mm²", MassMomentOfInertiaUnit.KilotonneSquareMilimeter)] + [InlineData("Mt·cm²", MassMomentOfInertiaUnit.MegatonneSquareCentimeter)] + [InlineData("Mt·dm²", MassMomentOfInertiaUnit.MegatonneSquareDecimeter)] + [InlineData("Mt·m²", MassMomentOfInertiaUnit.MegatonneSquareMeter)] + [InlineData("Mt·mm²", MassMomentOfInertiaUnit.MegatonneSquareMilimeter)] + [InlineData("mg·cm²", MassMomentOfInertiaUnit.MilligramSquareCentimeter)] + [InlineData("mg·dm²", MassMomentOfInertiaUnit.MilligramSquareDecimeter)] + [InlineData("mg·m²", MassMomentOfInertiaUnit.MilligramSquareMeter)] + [InlineData("mg·mm²", MassMomentOfInertiaUnit.MilligramSquareMillimeter)] + [InlineData("lb·ft²", MassMomentOfInertiaUnit.PoundSquareFoot)] + [InlineData("lb·in²", MassMomentOfInertiaUnit.PoundSquareInch)] + [InlineData("slug·ft²", MassMomentOfInertiaUnit.SlugSquareFoot)] + [InlineData("slug·in²", MassMomentOfInertiaUnit.SlugSquareInch)] + [InlineData("t·cm²", MassMomentOfInertiaUnit.TonneSquareCentimeter)] + [InlineData("t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] + [InlineData("t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] + [InlineData("t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassMomentOfInertiaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(MassMomentOfInertia.TryParseUnit(abbreviation, out MassMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g·cm²", MassMomentOfInertiaUnit.GramSquareCentimeter)] + [InlineData("en-US", "g·dm²", MassMomentOfInertiaUnit.GramSquareDecimeter)] + [InlineData("en-US", "g·m²", MassMomentOfInertiaUnit.GramSquareMeter)] + [InlineData("en-US", "g·mm²", MassMomentOfInertiaUnit.GramSquareMillimeter)] + [InlineData("en-US", "kg·cm²", MassMomentOfInertiaUnit.KilogramSquareCentimeter)] + [InlineData("en-US", "kg·dm²", MassMomentOfInertiaUnit.KilogramSquareDecimeter)] + [InlineData("en-US", "kg·m²", MassMomentOfInertiaUnit.KilogramSquareMeter)] + [InlineData("en-US", "kg·mm²", MassMomentOfInertiaUnit.KilogramSquareMillimeter)] + [InlineData("en-US", "kt·cm²", MassMomentOfInertiaUnit.KilotonneSquareCentimeter)] + [InlineData("en-US", "kt·dm²", MassMomentOfInertiaUnit.KilotonneSquareDecimeter)] + [InlineData("en-US", "kt·m²", MassMomentOfInertiaUnit.KilotonneSquareMeter)] + [InlineData("en-US", "kt·mm²", MassMomentOfInertiaUnit.KilotonneSquareMilimeter)] + [InlineData("en-US", "Mt·cm²", MassMomentOfInertiaUnit.MegatonneSquareCentimeter)] + [InlineData("en-US", "Mt·dm²", MassMomentOfInertiaUnit.MegatonneSquareDecimeter)] + [InlineData("en-US", "Mt·m²", MassMomentOfInertiaUnit.MegatonneSquareMeter)] + [InlineData("en-US", "Mt·mm²", MassMomentOfInertiaUnit.MegatonneSquareMilimeter)] + [InlineData("en-US", "mg·cm²", MassMomentOfInertiaUnit.MilligramSquareCentimeter)] + [InlineData("en-US", "mg·dm²", MassMomentOfInertiaUnit.MilligramSquareDecimeter)] + [InlineData("en-US", "mg·m²", MassMomentOfInertiaUnit.MilligramSquareMeter)] + [InlineData("en-US", "mg·mm²", MassMomentOfInertiaUnit.MilligramSquareMillimeter)] + [InlineData("en-US", "lb·ft²", MassMomentOfInertiaUnit.PoundSquareFoot)] + [InlineData("en-US", "lb·in²", MassMomentOfInertiaUnit.PoundSquareInch)] + [InlineData("en-US", "slug·ft²", MassMomentOfInertiaUnit.SlugSquareFoot)] + [InlineData("en-US", "slug·in²", MassMomentOfInertiaUnit.SlugSquareInch)] + [InlineData("en-US", "t·cm²", MassMomentOfInertiaUnit.TonneSquareCentimeter)] + [InlineData("en-US", "t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] + [InlineData("en-US", "t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] + [InlineData("en-US", "t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MassMomentOfInertiaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(MassMomentOfInertia.TryParseUnit(abbreviation, out MassMomentOfInertiaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -957,7 +1106,7 @@ public void TryParseUnit(string abbreviation, MassMomentOfInertiaUnit expectedUn [InlineData("en-US", "t·dm²", MassMomentOfInertiaUnit.TonneSquareDecimeter)] [InlineData("en-US", "t·m²", MassMomentOfInertiaUnit.TonneSquareMeter)] [InlineData("en-US", "t·mm²", MassMomentOfInertiaUnit.TonneSquareMilimeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MassMomentOfInertiaUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MassMomentOfInertiaUnit expectedUnit) { Assert.True(MassMomentOfInertia.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassMomentOfInertiaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs index c7ef259756..cd3f3f30dc 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MassTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1433,10 +1434,135 @@ public void TryParse() [InlineData("M⊙", MassUnit.SolarMass)] [InlineData("st", MassUnit.Stone)] [InlineData("t", MassUnit.Tonne)] - public void ParseUnit(string abbreviation, MassUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MassUnit parsedUnit = Mass.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MassUnit parsedUnit = Mass.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg", MassUnit.Centigram)] + [InlineData("dag", MassUnit.Decagram)] + [InlineData("dg", MassUnit.Decigram)] + [InlineData("em", MassUnit.EarthMass)] + [InlineData("fg", MassUnit.Femtogram)] + [InlineData("gr", MassUnit.Grain)] + [InlineData("g", MassUnit.Gram)] + [InlineData("hg", MassUnit.Hectogram)] + [InlineData("kg", MassUnit.Kilogram)] + [InlineData("klb", MassUnit.Kilopound)] + [InlineData("klbs", MassUnit.Kilopound)] + [InlineData("klbm", MassUnit.Kilopound)] + [InlineData("kt", MassUnit.Kilotonne)] + [InlineData("long tn", MassUnit.LongTon)] + [InlineData("Mlb", MassUnit.Megapound)] + [InlineData("Mlbs", MassUnit.Megapound)] + [InlineData("Mlbm", MassUnit.Megapound)] + [InlineData("Mt", MassUnit.Megatonne)] + [InlineData("µg", MassUnit.Microgram)] + [InlineData("mg", MassUnit.Milligram)] + [InlineData("ng", MassUnit.Nanogram)] + [InlineData("oz", MassUnit.Ounce)] + [InlineData("pg", MassUnit.Picogram)] + [InlineData("lb", MassUnit.Pound)] + [InlineData("lbs", MassUnit.Pound)] + [InlineData("lbm", MassUnit.Pound)] + [InlineData("t (short)", MassUnit.ShortTon)] + [InlineData("short tn", MassUnit.ShortTon)] + [InlineData("ST", MassUnit.ShortTon)] + [InlineData("slug", MassUnit.Slug)] + [InlineData("M☉", MassUnit.SolarMass)] + [InlineData("M⊙", MassUnit.SolarMass)] + [InlineData("st", MassUnit.Stone)] + [InlineData("t", MassUnit.Tonne)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MassUnit parsedUnit = Mass.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg", MassUnit.Centigram)] + [InlineData("en-US", "dag", MassUnit.Decagram)] + [InlineData("en-US", "dg", MassUnit.Decigram)] + [InlineData("en-US", "em", MassUnit.EarthMass)] + [InlineData("en-US", "fg", MassUnit.Femtogram)] + [InlineData("en-US", "gr", MassUnit.Grain)] + [InlineData("en-US", "g", MassUnit.Gram)] + [InlineData("en-US", "hg", MassUnit.Hectogram)] + [InlineData("en-US", "kg", MassUnit.Kilogram)] + [InlineData("en-US", "klb", MassUnit.Kilopound)] + [InlineData("en-US", "klbs", MassUnit.Kilopound)] + [InlineData("en-US", "klbm", MassUnit.Kilopound)] + [InlineData("en-US", "kt", MassUnit.Kilotonne)] + [InlineData("en-US", "long tn", MassUnit.LongTon)] + [InlineData("en-US", "Mlb", MassUnit.Megapound)] + [InlineData("en-US", "Mlbs", MassUnit.Megapound)] + [InlineData("en-US", "Mlbm", MassUnit.Megapound)] + [InlineData("en-US", "Mt", MassUnit.Megatonne)] + [InlineData("en-US", "µg", MassUnit.Microgram)] + [InlineData("en-US", "mg", MassUnit.Milligram)] + [InlineData("en-US", "ng", MassUnit.Nanogram)] + [InlineData("en-US", "oz", MassUnit.Ounce)] + [InlineData("en-US", "pg", MassUnit.Picogram)] + [InlineData("en-US", "lb", MassUnit.Pound)] + [InlineData("en-US", "lbs", MassUnit.Pound)] + [InlineData("en-US", "lbm", MassUnit.Pound)] + [InlineData("en-US", "t (short)", MassUnit.ShortTon)] + [InlineData("en-US", "short tn", MassUnit.ShortTon)] + [InlineData("en-US", "ST", MassUnit.ShortTon)] + [InlineData("en-US", "slug", MassUnit.Slug)] + [InlineData("en-US", "M☉", MassUnit.SolarMass)] + [InlineData("en-US", "M⊙", MassUnit.SolarMass)] + [InlineData("en-US", "st", MassUnit.Stone)] + [InlineData("en-US", "t", MassUnit.Tonne)] + [InlineData("ru-RU", "сг", MassUnit.Centigram)] + [InlineData("ru-RU", "даг", MassUnit.Decagram)] + [InlineData("ru-RU", "дг", MassUnit.Decigram)] + [InlineData("ru-RU", "фг", MassUnit.Femtogram)] + [InlineData("ru-RU", "г", MassUnit.Gram)] + [InlineData("ru-RU", "гг", MassUnit.Hectogram)] + [InlineData("ru-RU", "кг", MassUnit.Kilogram)] + [InlineData("ru-RU", "кфунт", MassUnit.Kilopound)] + [InlineData("ru-RU", "кт", MassUnit.Kilotonne)] + [InlineData("ru-RU", "тонна большая", MassUnit.LongTon)] + [InlineData("ru-RU", "Мфунт", MassUnit.Megapound)] + [InlineData("ru-RU", "Мт", MassUnit.Megatonne)] + [InlineData("ru-RU", "мкг", MassUnit.Microgram)] + [InlineData("ru-RU", "мг", MassUnit.Milligram)] + [InlineData("ru-RU", "нг", MassUnit.Nanogram)] + [InlineData("ru-RU", "пг", MassUnit.Picogram)] + [InlineData("ru-RU", "фунт", MassUnit.Pound)] + [InlineData("ru-RU", "тонна малая", MassUnit.ShortTon)] + [InlineData("ru-RU", "т", MassUnit.Tonne)] + [InlineData("zh-CN", "厘克", MassUnit.Centigram)] + [InlineData("zh-CN", "十克", MassUnit.Decagram)] + [InlineData("zh-CN", "分克", MassUnit.Decigram)] + [InlineData("zh-CN", "飞克", MassUnit.Femtogram)] + [InlineData("zh-CN", "克", MassUnit.Gram)] + [InlineData("zh-CN", "百克", MassUnit.Hectogram)] + [InlineData("zh-CN", "千克", MassUnit.Kilogram)] + [InlineData("zh-CN", "千磅", MassUnit.Kilopound)] + [InlineData("zh-CN", "千吨", MassUnit.Kilotonne)] + [InlineData("zh-CN", "长吨", MassUnit.LongTon)] + [InlineData("zh-CN", "兆磅", MassUnit.Megapound)] + [InlineData("zh-CN", "兆吨", MassUnit.Megatonne)] + [InlineData("zh-CN", "微克", MassUnit.Microgram)] + [InlineData("zh-CN", "毫克", MassUnit.Milligram)] + [InlineData("zh-CN", "纳克", MassUnit.Nanogram)] + [InlineData("zh-CN", "盎司", MassUnit.Ounce)] + [InlineData("zh-CN", "皮克", MassUnit.Picogram)] + [InlineData("zh-CN", "磅", MassUnit.Pound)] + [InlineData("zh-CN", "短吨", MassUnit.ShortTon)] + [InlineData("zh-CN", "吨", MassUnit.Tonne)] + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MassUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MassUnit parsedUnit = Mass.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1514,7 +1640,7 @@ public void ParseUnit(string abbreviation, MassUnit expectedUnit) [InlineData("zh-CN", "磅", MassUnit.Pound)] [InlineData("zh-CN", "短吨", MassUnit.ShortTon)] [InlineData("zh-CN", "吨", MassUnit.Tonne)] - public void ParseUnitWithCulture(string culture, string abbreviation, MassUnit expectedUnit) + public void ParseUnit_WithCulture(string culture, string abbreviation, MassUnit expectedUnit) { MassUnit parsedUnit = Mass.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1562,9 +1688,134 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati [InlineData("M⊙", MassUnit.SolarMass)] [InlineData("st", MassUnit.Stone)] [InlineData("t", MassUnit.Tonne)] - public void TryParseUnit(string abbreviation, MassUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MassUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Mass.TryParseUnit(abbreviation, out MassUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg", MassUnit.Centigram)] + [InlineData("dag", MassUnit.Decagram)] + [InlineData("dg", MassUnit.Decigram)] + [InlineData("em", MassUnit.EarthMass)] + [InlineData("fg", MassUnit.Femtogram)] + [InlineData("gr", MassUnit.Grain)] + [InlineData("g", MassUnit.Gram)] + [InlineData("hg", MassUnit.Hectogram)] + [InlineData("kg", MassUnit.Kilogram)] + [InlineData("klb", MassUnit.Kilopound)] + [InlineData("klbs", MassUnit.Kilopound)] + [InlineData("klbm", MassUnit.Kilopound)] + [InlineData("kt", MassUnit.Kilotonne)] + [InlineData("long tn", MassUnit.LongTon)] + [InlineData("Mlb", MassUnit.Megapound)] + [InlineData("Mlbs", MassUnit.Megapound)] + [InlineData("Mlbm", MassUnit.Megapound)] + [InlineData("Mt", MassUnit.Megatonne)] + [InlineData("µg", MassUnit.Microgram)] + [InlineData("mg", MassUnit.Milligram)] + [InlineData("ng", MassUnit.Nanogram)] + [InlineData("oz", MassUnit.Ounce)] + [InlineData("pg", MassUnit.Picogram)] + [InlineData("lb", MassUnit.Pound)] + [InlineData("lbs", MassUnit.Pound)] + [InlineData("lbm", MassUnit.Pound)] + [InlineData("t (short)", MassUnit.ShortTon)] + [InlineData("short tn", MassUnit.ShortTon)] + [InlineData("ST", MassUnit.ShortTon)] + [InlineData("slug", MassUnit.Slug)] + [InlineData("M☉", MassUnit.SolarMass)] + [InlineData("M⊙", MassUnit.SolarMass)] + [InlineData("st", MassUnit.Stone)] + [InlineData("t", MassUnit.Tonne)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MassUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Mass.TryParseUnit(abbreviation, out MassUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg", MassUnit.Centigram)] + [InlineData("en-US", "dag", MassUnit.Decagram)] + [InlineData("en-US", "dg", MassUnit.Decigram)] + [InlineData("en-US", "em", MassUnit.EarthMass)] + [InlineData("en-US", "fg", MassUnit.Femtogram)] + [InlineData("en-US", "gr", MassUnit.Grain)] + [InlineData("en-US", "g", MassUnit.Gram)] + [InlineData("en-US", "hg", MassUnit.Hectogram)] + [InlineData("en-US", "kg", MassUnit.Kilogram)] + [InlineData("en-US", "klb", MassUnit.Kilopound)] + [InlineData("en-US", "klbs", MassUnit.Kilopound)] + [InlineData("en-US", "klbm", MassUnit.Kilopound)] + [InlineData("en-US", "kt", MassUnit.Kilotonne)] + [InlineData("en-US", "long tn", MassUnit.LongTon)] + [InlineData("en-US", "Mlb", MassUnit.Megapound)] + [InlineData("en-US", "Mlbs", MassUnit.Megapound)] + [InlineData("en-US", "Mlbm", MassUnit.Megapound)] + [InlineData("en-US", "Mt", MassUnit.Megatonne)] + [InlineData("en-US", "µg", MassUnit.Microgram)] + [InlineData("en-US", "mg", MassUnit.Milligram)] + [InlineData("en-US", "ng", MassUnit.Nanogram)] + [InlineData("en-US", "oz", MassUnit.Ounce)] + [InlineData("en-US", "pg", MassUnit.Picogram)] + [InlineData("en-US", "lb", MassUnit.Pound)] + [InlineData("en-US", "lbs", MassUnit.Pound)] + [InlineData("en-US", "lbm", MassUnit.Pound)] + [InlineData("en-US", "t (short)", MassUnit.ShortTon)] + [InlineData("en-US", "short tn", MassUnit.ShortTon)] + [InlineData("en-US", "ST", MassUnit.ShortTon)] + [InlineData("en-US", "slug", MassUnit.Slug)] + [InlineData("en-US", "M☉", MassUnit.SolarMass)] + [InlineData("en-US", "M⊙", MassUnit.SolarMass)] + [InlineData("en-US", "st", MassUnit.Stone)] + [InlineData("en-US", "t", MassUnit.Tonne)] + [InlineData("ru-RU", "сг", MassUnit.Centigram)] + [InlineData("ru-RU", "даг", MassUnit.Decagram)] + [InlineData("ru-RU", "дг", MassUnit.Decigram)] + [InlineData("ru-RU", "фг", MassUnit.Femtogram)] + [InlineData("ru-RU", "г", MassUnit.Gram)] + [InlineData("ru-RU", "гг", MassUnit.Hectogram)] + [InlineData("ru-RU", "кг", MassUnit.Kilogram)] + [InlineData("ru-RU", "кфунт", MassUnit.Kilopound)] + [InlineData("ru-RU", "кт", MassUnit.Kilotonne)] + [InlineData("ru-RU", "тонна большая", MassUnit.LongTon)] + [InlineData("ru-RU", "Мфунт", MassUnit.Megapound)] + [InlineData("ru-RU", "Мт", MassUnit.Megatonne)] + [InlineData("ru-RU", "мкг", MassUnit.Microgram)] + [InlineData("ru-RU", "мг", MassUnit.Milligram)] + [InlineData("ru-RU", "нг", MassUnit.Nanogram)] + [InlineData("ru-RU", "пг", MassUnit.Picogram)] + [InlineData("ru-RU", "фунт", MassUnit.Pound)] + [InlineData("ru-RU", "тонна малая", MassUnit.ShortTon)] + [InlineData("ru-RU", "т", MassUnit.Tonne)] + [InlineData("zh-CN", "厘克", MassUnit.Centigram)] + [InlineData("zh-CN", "十克", MassUnit.Decagram)] + [InlineData("zh-CN", "分克", MassUnit.Decigram)] + [InlineData("zh-CN", "飞克", MassUnit.Femtogram)] + [InlineData("zh-CN", "克", MassUnit.Gram)] + [InlineData("zh-CN", "百克", MassUnit.Hectogram)] + [InlineData("zh-CN", "千克", MassUnit.Kilogram)] + [InlineData("zh-CN", "千磅", MassUnit.Kilopound)] + [InlineData("zh-CN", "千吨", MassUnit.Kilotonne)] + [InlineData("zh-CN", "长吨", MassUnit.LongTon)] + [InlineData("zh-CN", "兆磅", MassUnit.Megapound)] + [InlineData("zh-CN", "兆吨", MassUnit.Megatonne)] + [InlineData("zh-CN", "微克", MassUnit.Microgram)] + [InlineData("zh-CN", "毫克", MassUnit.Milligram)] + [InlineData("zh-CN", "纳克", MassUnit.Nanogram)] + [InlineData("zh-CN", "盎司", MassUnit.Ounce)] + [InlineData("zh-CN", "皮克", MassUnit.Picogram)] + [InlineData("zh-CN", "磅", MassUnit.Pound)] + [InlineData("zh-CN", "短吨", MassUnit.ShortTon)] + [InlineData("zh-CN", "吨", MassUnit.Tonne)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MassUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Mass.TryParseUnit(abbreviation, out MassUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1643,7 +1894,7 @@ public void TryParseUnit(string abbreviation, MassUnit expectedUnit) [InlineData("zh-CN", "磅", MassUnit.Pound)] [InlineData("zh-CN", "短吨", MassUnit.ShortTon)] [InlineData("zh-CN", "吨", MassUnit.Tonne)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MassUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MassUnit expectedUnit) { Assert.True(Mass.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MassUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs index a577ebf0ba..6cf7bed52c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolalityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -250,10 +251,23 @@ public void TryParse() [InlineData("mmol/kg", MolalityUnit.MillimolePerKilogram)] [InlineData("mol/g", MolalityUnit.MolePerGram)] [InlineData("mol/kg", MolalityUnit.MolePerKilogram)] - public void ParseUnit(string abbreviation, MolalityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolalityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MolalityUnit parsedUnit = Molality.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MolalityUnit parsedUnit = Molality.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("mmol/kg", MolalityUnit.MillimolePerKilogram)] + [InlineData("mol/g", MolalityUnit.MolePerGram)] + [InlineData("mol/kg", MolalityUnit.MolePerKilogram)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolalityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MolalityUnit parsedUnit = Molality.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -261,7 +275,18 @@ public void ParseUnit(string abbreviation, MolalityUnit expectedUnit) [InlineData("en-US", "mmol/kg", MolalityUnit.MillimolePerKilogram)] [InlineData("en-US", "mol/g", MolalityUnit.MolePerGram)] [InlineData("en-US", "mol/kg", MolalityUnit.MolePerKilogram)] - public void ParseUnitWithCulture(string culture, string abbreviation, MolalityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MolalityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MolalityUnit parsedUnit = Molality.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "mmol/kg", MolalityUnit.MillimolePerKilogram)] + [InlineData("en-US", "mol/g", MolalityUnit.MolePerGram)] + [InlineData("en-US", "mol/kg", MolalityUnit.MolePerKilogram)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MolalityUnit expectedUnit) { MolalityUnit parsedUnit = Molality.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -271,9 +296,33 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MolalityUn [InlineData("mmol/kg", MolalityUnit.MillimolePerKilogram)] [InlineData("mol/g", MolalityUnit.MolePerGram)] [InlineData("mol/kg", MolalityUnit.MolePerKilogram)] - public void TryParseUnit(string abbreviation, MolalityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolalityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Molality.TryParseUnit(abbreviation, out MolalityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("mmol/kg", MolalityUnit.MillimolePerKilogram)] + [InlineData("mol/g", MolalityUnit.MolePerGram)] + [InlineData("mol/kg", MolalityUnit.MolePerKilogram)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolalityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Molality.TryParseUnit(abbreviation, out MolalityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "mmol/kg", MolalityUnit.MillimolePerKilogram)] + [InlineData("en-US", "mol/g", MolalityUnit.MolePerGram)] + [InlineData("en-US", "mol/kg", MolalityUnit.MolePerKilogram)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MolalityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Molality.TryParseUnit(abbreviation, out MolalityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -282,7 +331,7 @@ public void TryParseUnit(string abbreviation, MolalityUnit expectedUnit) [InlineData("en-US", "mmol/kg", MolalityUnit.MillimolePerKilogram)] [InlineData("en-US", "mol/g", MolalityUnit.MolePerGram)] [InlineData("en-US", "mol/kg", MolalityUnit.MolePerKilogram)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MolalityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MolalityUnit expectedUnit) { Assert.True(Molality.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolalityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs index 0442cfaf67..eec539fb11 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEnergyTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -250,10 +251,23 @@ public void TryParse() [InlineData("J/mol", MolarEnergyUnit.JoulePerMole)] [InlineData("kJ/mol", MolarEnergyUnit.KilojoulePerMole)] [InlineData("MJ/mol", MolarEnergyUnit.MegajoulePerMole)] - public void ParseUnit(string abbreviation, MolarEnergyUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolarEnergyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MolarEnergyUnit parsedUnit = MolarEnergy.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MolarEnergyUnit parsedUnit = MolarEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("J/mol", MolarEnergyUnit.JoulePerMole)] + [InlineData("kJ/mol", MolarEnergyUnit.KilojoulePerMole)] + [InlineData("MJ/mol", MolarEnergyUnit.MegajoulePerMole)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolarEnergyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MolarEnergyUnit parsedUnit = MolarEnergy.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -261,7 +275,18 @@ public void ParseUnit(string abbreviation, MolarEnergyUnit expectedUnit) [InlineData("en-US", "J/mol", MolarEnergyUnit.JoulePerMole)] [InlineData("en-US", "kJ/mol", MolarEnergyUnit.KilojoulePerMole)] [InlineData("en-US", "MJ/mol", MolarEnergyUnit.MegajoulePerMole)] - public void ParseUnitWithCulture(string culture, string abbreviation, MolarEnergyUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MolarEnergyUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MolarEnergyUnit parsedUnit = MolarEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "J/mol", MolarEnergyUnit.JoulePerMole)] + [InlineData("en-US", "kJ/mol", MolarEnergyUnit.KilojoulePerMole)] + [InlineData("en-US", "MJ/mol", MolarEnergyUnit.MegajoulePerMole)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MolarEnergyUnit expectedUnit) { MolarEnergyUnit parsedUnit = MolarEnergy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -271,9 +296,33 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MolarEnerg [InlineData("J/mol", MolarEnergyUnit.JoulePerMole)] [InlineData("kJ/mol", MolarEnergyUnit.KilojoulePerMole)] [InlineData("MJ/mol", MolarEnergyUnit.MegajoulePerMole)] - public void TryParseUnit(string abbreviation, MolarEnergyUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolarEnergyUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(MolarEnergy.TryParseUnit(abbreviation, out MolarEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("J/mol", MolarEnergyUnit.JoulePerMole)] + [InlineData("kJ/mol", MolarEnergyUnit.KilojoulePerMole)] + [InlineData("MJ/mol", MolarEnergyUnit.MegajoulePerMole)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolarEnergyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(MolarEnergy.TryParseUnit(abbreviation, out MolarEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "J/mol", MolarEnergyUnit.JoulePerMole)] + [InlineData("en-US", "kJ/mol", MolarEnergyUnit.KilojoulePerMole)] + [InlineData("en-US", "MJ/mol", MolarEnergyUnit.MegajoulePerMole)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MolarEnergyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(MolarEnergy.TryParseUnit(abbreviation, out MolarEnergyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -282,7 +331,7 @@ public void TryParseUnit(string abbreviation, MolarEnergyUnit expectedUnit) [InlineData("en-US", "J/mol", MolarEnergyUnit.JoulePerMole)] [InlineData("en-US", "kJ/mol", MolarEnergyUnit.KilojoulePerMole)] [InlineData("en-US", "MJ/mol", MolarEnergyUnit.MegajoulePerMole)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MolarEnergyUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MolarEnergyUnit expectedUnit) { Assert.True(MolarEnergy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolarEnergyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs index 67149f5dff..61e6db612d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarEntropyTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -250,10 +251,23 @@ public void TryParse() [InlineData("J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] [InlineData("kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] [InlineData("MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] - public void ParseUnit(string abbreviation, MolarEntropyUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolarEntropyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MolarEntropyUnit parsedUnit = MolarEntropy.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MolarEntropyUnit parsedUnit = MolarEntropy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] + [InlineData("kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] + [InlineData("MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolarEntropyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MolarEntropyUnit parsedUnit = MolarEntropy.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -261,7 +275,18 @@ public void ParseUnit(string abbreviation, MolarEntropyUnit expectedUnit) [InlineData("en-US", "J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] [InlineData("en-US", "kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] [InlineData("en-US", "MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] - public void ParseUnitWithCulture(string culture, string abbreviation, MolarEntropyUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MolarEntropyUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MolarEntropyUnit parsedUnit = MolarEntropy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] + [InlineData("en-US", "kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] + [InlineData("en-US", "MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MolarEntropyUnit expectedUnit) { MolarEntropyUnit parsedUnit = MolarEntropy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -271,9 +296,33 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MolarEntro [InlineData("J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] [InlineData("kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] [InlineData("MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] - public void TryParseUnit(string abbreviation, MolarEntropyUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolarEntropyUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(MolarEntropy.TryParseUnit(abbreviation, out MolarEntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] + [InlineData("kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] + [InlineData("MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolarEntropyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(MolarEntropy.TryParseUnit(abbreviation, out MolarEntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] + [InlineData("en-US", "kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] + [InlineData("en-US", "MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MolarEntropyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(MolarEntropy.TryParseUnit(abbreviation, out MolarEntropyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -282,7 +331,7 @@ public void TryParseUnit(string abbreviation, MolarEntropyUnit expectedUnit) [InlineData("en-US", "J/(mol*K)", MolarEntropyUnit.JoulePerMoleKelvin)] [InlineData("en-US", "kJ/(mol*K)", MolarEntropyUnit.KilojoulePerMoleKelvin)] [InlineData("en-US", "MJ/(mol*K)", MolarEntropyUnit.MegajoulePerMoleKelvin)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MolarEntropyUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MolarEntropyUnit expectedUnit) { Assert.True(MolarEntropy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolarEntropyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs index 500387ddb9..579eed059a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarFlowTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -394,10 +395,29 @@ public void TryParse() [InlineData("lbmol/h", MolarFlowUnit.PoundMolePerHour)] [InlineData("lbmol/min", MolarFlowUnit.PoundMolePerMinute)] [InlineData("lbmol/s", MolarFlowUnit.PoundMolePerSecond)] - public void ParseUnit(string abbreviation, MolarFlowUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolarFlowUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MolarFlowUnit parsedUnit = MolarFlow.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MolarFlowUnit parsedUnit = MolarFlow.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kkmol/h", MolarFlowUnit.KilomolePerHour)] + [InlineData("kmol/min", MolarFlowUnit.KilomolePerMinute)] + [InlineData("kmol/s", MolarFlowUnit.KilomolePerSecond)] + [InlineData("kmol/h", MolarFlowUnit.MolePerHour)] + [InlineData("mol/min", MolarFlowUnit.MolePerMinute)] + [InlineData("mol/s", MolarFlowUnit.MolePerSecond)] + [InlineData("lbmol/h", MolarFlowUnit.PoundMolePerHour)] + [InlineData("lbmol/min", MolarFlowUnit.PoundMolePerMinute)] + [InlineData("lbmol/s", MolarFlowUnit.PoundMolePerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolarFlowUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MolarFlowUnit parsedUnit = MolarFlow.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -411,7 +431,24 @@ public void ParseUnit(string abbreviation, MolarFlowUnit expectedUnit) [InlineData("en-US", "lbmol/h", MolarFlowUnit.PoundMolePerHour)] [InlineData("en-US", "lbmol/min", MolarFlowUnit.PoundMolePerMinute)] [InlineData("en-US", "lbmol/s", MolarFlowUnit.PoundMolePerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, MolarFlowUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MolarFlowUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MolarFlowUnit parsedUnit = MolarFlow.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kkmol/h", MolarFlowUnit.KilomolePerHour)] + [InlineData("en-US", "kmol/min", MolarFlowUnit.KilomolePerMinute)] + [InlineData("en-US", "kmol/s", MolarFlowUnit.KilomolePerSecond)] + [InlineData("en-US", "kmol/h", MolarFlowUnit.MolePerHour)] + [InlineData("en-US", "mol/min", MolarFlowUnit.MolePerMinute)] + [InlineData("en-US", "mol/s", MolarFlowUnit.MolePerSecond)] + [InlineData("en-US", "lbmol/h", MolarFlowUnit.PoundMolePerHour)] + [InlineData("en-US", "lbmol/min", MolarFlowUnit.PoundMolePerMinute)] + [InlineData("en-US", "lbmol/s", MolarFlowUnit.PoundMolePerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MolarFlowUnit expectedUnit) { MolarFlowUnit parsedUnit = MolarFlow.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -427,9 +464,45 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MolarFlowU [InlineData("lbmol/h", MolarFlowUnit.PoundMolePerHour)] [InlineData("lbmol/min", MolarFlowUnit.PoundMolePerMinute)] [InlineData("lbmol/s", MolarFlowUnit.PoundMolePerSecond)] - public void TryParseUnit(string abbreviation, MolarFlowUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolarFlowUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(MolarFlow.TryParseUnit(abbreviation, out MolarFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kkmol/h", MolarFlowUnit.KilomolePerHour)] + [InlineData("kmol/min", MolarFlowUnit.KilomolePerMinute)] + [InlineData("kmol/s", MolarFlowUnit.KilomolePerSecond)] + [InlineData("kmol/h", MolarFlowUnit.MolePerHour)] + [InlineData("mol/min", MolarFlowUnit.MolePerMinute)] + [InlineData("mol/s", MolarFlowUnit.MolePerSecond)] + [InlineData("lbmol/h", MolarFlowUnit.PoundMolePerHour)] + [InlineData("lbmol/min", MolarFlowUnit.PoundMolePerMinute)] + [InlineData("lbmol/s", MolarFlowUnit.PoundMolePerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolarFlowUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(MolarFlow.TryParseUnit(abbreviation, out MolarFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kkmol/h", MolarFlowUnit.KilomolePerHour)] + [InlineData("en-US", "kmol/min", MolarFlowUnit.KilomolePerMinute)] + [InlineData("en-US", "kmol/s", MolarFlowUnit.KilomolePerSecond)] + [InlineData("en-US", "kmol/h", MolarFlowUnit.MolePerHour)] + [InlineData("en-US", "mol/min", MolarFlowUnit.MolePerMinute)] + [InlineData("en-US", "mol/s", MolarFlowUnit.MolePerSecond)] + [InlineData("en-US", "lbmol/h", MolarFlowUnit.PoundMolePerHour)] + [InlineData("en-US", "lbmol/min", MolarFlowUnit.PoundMolePerMinute)] + [InlineData("en-US", "lbmol/s", MolarFlowUnit.PoundMolePerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MolarFlowUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(MolarFlow.TryParseUnit(abbreviation, out MolarFlowUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -444,7 +517,7 @@ public void TryParseUnit(string abbreviation, MolarFlowUnit expectedUnit) [InlineData("en-US", "lbmol/h", MolarFlowUnit.PoundMolePerHour)] [InlineData("en-US", "lbmol/min", MolarFlowUnit.PoundMolePerMinute)] [InlineData("en-US", "lbmol/s", MolarFlowUnit.PoundMolePerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MolarFlowUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MolarFlowUnit expectedUnit) { Assert.True(MolarFlow.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolarFlowUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs index 61cf49b07f..fe5393cb31 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarMassTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -646,10 +647,33 @@ public void TryParse() [InlineData("mg/mol", MolarMassUnit.MilligramPerMole)] [InlineData("ng/mol", MolarMassUnit.NanogramPerMole)] [InlineData("lb/mol", MolarMassUnit.PoundPerMole)] - public void ParseUnit(string abbreviation, MolarMassUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolarMassUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MolarMassUnit parsedUnit = MolarMass.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MolarMassUnit parsedUnit = MolarMass.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg/mol", MolarMassUnit.CentigramPerMole)] + [InlineData("dag/mol", MolarMassUnit.DecagramPerMole)] + [InlineData("dg/mol", MolarMassUnit.DecigramPerMole)] + [InlineData("g/mol", MolarMassUnit.GramPerMole)] + [InlineData("hg/mol", MolarMassUnit.HectogramPerMole)] + [InlineData("kg/kmol", MolarMassUnit.KilogramPerKilomole)] + [InlineData("kg/mol", MolarMassUnit.KilogramPerMole)] + [InlineData("klb/mol", MolarMassUnit.KilopoundPerMole)] + [InlineData("Mlb/mol", MolarMassUnit.MegapoundPerMole)] + [InlineData("µg/mol", MolarMassUnit.MicrogramPerMole)] + [InlineData("mg/mol", MolarMassUnit.MilligramPerMole)] + [InlineData("ng/mol", MolarMassUnit.NanogramPerMole)] + [InlineData("lb/mol", MolarMassUnit.PoundPerMole)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolarMassUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MolarMassUnit parsedUnit = MolarMass.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -679,7 +703,40 @@ public void ParseUnit(string abbreviation, MolarMassUnit expectedUnit) [InlineData("ru-RU", "мг/моль", MolarMassUnit.MilligramPerMole)] [InlineData("ru-RU", "нг/моль", MolarMassUnit.NanogramPerMole)] [InlineData("ru-RU", "фунт/моль", MolarMassUnit.PoundPerMole)] - public void ParseUnitWithCulture(string culture, string abbreviation, MolarMassUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MolarMassUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MolarMassUnit parsedUnit = MolarMass.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg/mol", MolarMassUnit.CentigramPerMole)] + [InlineData("en-US", "dag/mol", MolarMassUnit.DecagramPerMole)] + [InlineData("en-US", "dg/mol", MolarMassUnit.DecigramPerMole)] + [InlineData("en-US", "g/mol", MolarMassUnit.GramPerMole)] + [InlineData("en-US", "hg/mol", MolarMassUnit.HectogramPerMole)] + [InlineData("en-US", "kg/kmol", MolarMassUnit.KilogramPerKilomole)] + [InlineData("en-US", "kg/mol", MolarMassUnit.KilogramPerMole)] + [InlineData("en-US", "klb/mol", MolarMassUnit.KilopoundPerMole)] + [InlineData("en-US", "Mlb/mol", MolarMassUnit.MegapoundPerMole)] + [InlineData("en-US", "µg/mol", MolarMassUnit.MicrogramPerMole)] + [InlineData("en-US", "mg/mol", MolarMassUnit.MilligramPerMole)] + [InlineData("en-US", "ng/mol", MolarMassUnit.NanogramPerMole)] + [InlineData("en-US", "lb/mol", MolarMassUnit.PoundPerMole)] + [InlineData("ru-RU", "сг/моль", MolarMassUnit.CentigramPerMole)] + [InlineData("ru-RU", "даг/моль", MolarMassUnit.DecagramPerMole)] + [InlineData("ru-RU", "дг/моль", MolarMassUnit.DecigramPerMole)] + [InlineData("ru-RU", "г/моль", MolarMassUnit.GramPerMole)] + [InlineData("ru-RU", "гг/моль", MolarMassUnit.HectogramPerMole)] + [InlineData("ru-RU", "кг/моль", MolarMassUnit.KilogramPerMole)] + [InlineData("ru-RU", "кфунт/моль", MolarMassUnit.KilopoundPerMole)] + [InlineData("ru-RU", "Мфунт/моль", MolarMassUnit.MegapoundPerMole)] + [InlineData("ru-RU", "мкг/моль", MolarMassUnit.MicrogramPerMole)] + [InlineData("ru-RU", "мг/моль", MolarMassUnit.MilligramPerMole)] + [InlineData("ru-RU", "нг/моль", MolarMassUnit.NanogramPerMole)] + [InlineData("ru-RU", "фунт/моль", MolarMassUnit.PoundPerMole)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MolarMassUnit expectedUnit) { MolarMassUnit parsedUnit = MolarMass.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -699,9 +756,65 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MolarMassU [InlineData("mg/mol", MolarMassUnit.MilligramPerMole)] [InlineData("ng/mol", MolarMassUnit.NanogramPerMole)] [InlineData("lb/mol", MolarMassUnit.PoundPerMole)] - public void TryParseUnit(string abbreviation, MolarMassUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolarMassUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(MolarMass.TryParseUnit(abbreviation, out MolarMassUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cg/mol", MolarMassUnit.CentigramPerMole)] + [InlineData("dag/mol", MolarMassUnit.DecagramPerMole)] + [InlineData("dg/mol", MolarMassUnit.DecigramPerMole)] + [InlineData("g/mol", MolarMassUnit.GramPerMole)] + [InlineData("hg/mol", MolarMassUnit.HectogramPerMole)] + [InlineData("kg/kmol", MolarMassUnit.KilogramPerKilomole)] + [InlineData("kg/mol", MolarMassUnit.KilogramPerMole)] + [InlineData("klb/mol", MolarMassUnit.KilopoundPerMole)] + [InlineData("Mlb/mol", MolarMassUnit.MegapoundPerMole)] + [InlineData("µg/mol", MolarMassUnit.MicrogramPerMole)] + [InlineData("mg/mol", MolarMassUnit.MilligramPerMole)] + [InlineData("ng/mol", MolarMassUnit.NanogramPerMole)] + [InlineData("lb/mol", MolarMassUnit.PoundPerMole)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolarMassUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(MolarMass.TryParseUnit(abbreviation, out MolarMassUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cg/mol", MolarMassUnit.CentigramPerMole)] + [InlineData("en-US", "dag/mol", MolarMassUnit.DecagramPerMole)] + [InlineData("en-US", "dg/mol", MolarMassUnit.DecigramPerMole)] + [InlineData("en-US", "g/mol", MolarMassUnit.GramPerMole)] + [InlineData("en-US", "hg/mol", MolarMassUnit.HectogramPerMole)] + [InlineData("en-US", "kg/kmol", MolarMassUnit.KilogramPerKilomole)] + [InlineData("en-US", "kg/mol", MolarMassUnit.KilogramPerMole)] + [InlineData("en-US", "klb/mol", MolarMassUnit.KilopoundPerMole)] + [InlineData("en-US", "Mlb/mol", MolarMassUnit.MegapoundPerMole)] + [InlineData("en-US", "µg/mol", MolarMassUnit.MicrogramPerMole)] + [InlineData("en-US", "mg/mol", MolarMassUnit.MilligramPerMole)] + [InlineData("en-US", "ng/mol", MolarMassUnit.NanogramPerMole)] + [InlineData("en-US", "lb/mol", MolarMassUnit.PoundPerMole)] + [InlineData("ru-RU", "сг/моль", MolarMassUnit.CentigramPerMole)] + [InlineData("ru-RU", "даг/моль", MolarMassUnit.DecagramPerMole)] + [InlineData("ru-RU", "дг/моль", MolarMassUnit.DecigramPerMole)] + [InlineData("ru-RU", "г/моль", MolarMassUnit.GramPerMole)] + [InlineData("ru-RU", "гг/моль", MolarMassUnit.HectogramPerMole)] + [InlineData("ru-RU", "кг/моль", MolarMassUnit.KilogramPerMole)] + [InlineData("ru-RU", "кфунт/моль", MolarMassUnit.KilopoundPerMole)] + [InlineData("ru-RU", "Мфунт/моль", MolarMassUnit.MegapoundPerMole)] + [InlineData("ru-RU", "мкг/моль", MolarMassUnit.MicrogramPerMole)] + [InlineData("ru-RU", "мг/моль", MolarMassUnit.MilligramPerMole)] + [InlineData("ru-RU", "нг/моль", MolarMassUnit.NanogramPerMole)] + [InlineData("ru-RU", "фунт/моль", MolarMassUnit.PoundPerMole)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MolarMassUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(MolarMass.TryParseUnit(abbreviation, out MolarMassUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -732,7 +845,7 @@ public void TryParseUnit(string abbreviation, MolarMassUnit expectedUnit) [InlineData("ru-RU", "мг/моль", MolarMassUnit.MilligramPerMole)] [InlineData("ru-RU", "нг/моль", MolarMassUnit.NanogramPerMole)] [InlineData("ru-RU", "фунт/моль", MolarMassUnit.PoundPerMole)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MolarMassUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MolarMassUnit expectedUnit) { Assert.True(MolarMass.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolarMassUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs index af17b73475..ab8a271fef 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/MolarityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -554,10 +555,39 @@ public void TryParse() [InlineData("pmol/l", MolarityUnit.PicomolePerLiter)] [InlineData("pM", MolarityUnit.PicomolePerLiter)] [InlineData("lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] - public void ParseUnit(string abbreviation, MolarityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolarityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - MolarityUnit parsedUnit = Molarity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + MolarityUnit parsedUnit = Molarity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cmol/l", MolarityUnit.CentimolePerLiter)] + [InlineData("cM", MolarityUnit.CentimolePerLiter)] + [InlineData("dmol/l", MolarityUnit.DecimolePerLiter)] + [InlineData("dM", MolarityUnit.DecimolePerLiter)] + [InlineData("fmol/l", MolarityUnit.FemtomolePerLiter)] + [InlineData("fM", MolarityUnit.FemtomolePerLiter)] + [InlineData("kmol/m³", MolarityUnit.KilomolePerCubicMeter)] + [InlineData("µmol/l", MolarityUnit.MicromolePerLiter)] + [InlineData("µM", MolarityUnit.MicromolePerLiter)] + [InlineData("mmol/l", MolarityUnit.MillimolePerLiter)] + [InlineData("mM", MolarityUnit.MillimolePerLiter)] + [InlineData("mol/m³", MolarityUnit.MolePerCubicMeter)] + [InlineData("mol/l", MolarityUnit.MolePerLiter)] + [InlineData("M", MolarityUnit.MolePerLiter)] + [InlineData("nmol/l", MolarityUnit.NanomolePerLiter)] + [InlineData("nM", MolarityUnit.NanomolePerLiter)] + [InlineData("pmol/l", MolarityUnit.PicomolePerLiter)] + [InlineData("pM", MolarityUnit.PicomolePerLiter)] + [InlineData("lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolarityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + MolarityUnit parsedUnit = Molarity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -581,7 +611,34 @@ public void ParseUnit(string abbreviation, MolarityUnit expectedUnit) [InlineData("en-US", "pmol/l", MolarityUnit.PicomolePerLiter)] [InlineData("en-US", "pM", MolarityUnit.PicomolePerLiter)] [InlineData("en-US", "lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] - public void ParseUnitWithCulture(string culture, string abbreviation, MolarityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, MolarityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + MolarityUnit parsedUnit = Molarity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cmol/l", MolarityUnit.CentimolePerLiter)] + [InlineData("en-US", "cM", MolarityUnit.CentimolePerLiter)] + [InlineData("en-US", "dmol/l", MolarityUnit.DecimolePerLiter)] + [InlineData("en-US", "dM", MolarityUnit.DecimolePerLiter)] + [InlineData("en-US", "fmol/l", MolarityUnit.FemtomolePerLiter)] + [InlineData("en-US", "fM", MolarityUnit.FemtomolePerLiter)] + [InlineData("en-US", "kmol/m³", MolarityUnit.KilomolePerCubicMeter)] + [InlineData("en-US", "µmol/l", MolarityUnit.MicromolePerLiter)] + [InlineData("en-US", "µM", MolarityUnit.MicromolePerLiter)] + [InlineData("en-US", "mmol/l", MolarityUnit.MillimolePerLiter)] + [InlineData("en-US", "mM", MolarityUnit.MillimolePerLiter)] + [InlineData("en-US", "mol/m³", MolarityUnit.MolePerCubicMeter)] + [InlineData("en-US", "mol/l", MolarityUnit.MolePerLiter)] + [InlineData("en-US", "M", MolarityUnit.MolePerLiter)] + [InlineData("en-US", "nmol/l", MolarityUnit.NanomolePerLiter)] + [InlineData("en-US", "nM", MolarityUnit.NanomolePerLiter)] + [InlineData("en-US", "pmol/l", MolarityUnit.PicomolePerLiter)] + [InlineData("en-US", "pM", MolarityUnit.PicomolePerLiter)] + [InlineData("en-US", "lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] + public void ParseUnit_WithCulture(string culture, string abbreviation, MolarityUnit expectedUnit) { MolarityUnit parsedUnit = Molarity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -607,9 +664,65 @@ public void ParseUnitWithCulture(string culture, string abbreviation, MolarityUn [InlineData("pmol/l", MolarityUnit.PicomolePerLiter)] [InlineData("pM", MolarityUnit.PicomolePerLiter)] [InlineData("lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] - public void TryParseUnit(string abbreviation, MolarityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, MolarityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Molarity.TryParseUnit(abbreviation, out MolarityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cmol/l", MolarityUnit.CentimolePerLiter)] + [InlineData("cM", MolarityUnit.CentimolePerLiter)] + [InlineData("dmol/l", MolarityUnit.DecimolePerLiter)] + [InlineData("dM", MolarityUnit.DecimolePerLiter)] + [InlineData("fmol/l", MolarityUnit.FemtomolePerLiter)] + [InlineData("fM", MolarityUnit.FemtomolePerLiter)] + [InlineData("kmol/m³", MolarityUnit.KilomolePerCubicMeter)] + [InlineData("µmol/l", MolarityUnit.MicromolePerLiter)] + [InlineData("µM", MolarityUnit.MicromolePerLiter)] + [InlineData("mmol/l", MolarityUnit.MillimolePerLiter)] + [InlineData("mM", MolarityUnit.MillimolePerLiter)] + [InlineData("mol/m³", MolarityUnit.MolePerCubicMeter)] + [InlineData("mol/l", MolarityUnit.MolePerLiter)] + [InlineData("M", MolarityUnit.MolePerLiter)] + [InlineData("nmol/l", MolarityUnit.NanomolePerLiter)] + [InlineData("nM", MolarityUnit.NanomolePerLiter)] + [InlineData("pmol/l", MolarityUnit.PicomolePerLiter)] + [InlineData("pM", MolarityUnit.PicomolePerLiter)] + [InlineData("lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, MolarityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Molarity.TryParseUnit(abbreviation, out MolarityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cmol/l", MolarityUnit.CentimolePerLiter)] + [InlineData("en-US", "cM", MolarityUnit.CentimolePerLiter)] + [InlineData("en-US", "dmol/l", MolarityUnit.DecimolePerLiter)] + [InlineData("en-US", "dM", MolarityUnit.DecimolePerLiter)] + [InlineData("en-US", "fmol/l", MolarityUnit.FemtomolePerLiter)] + [InlineData("en-US", "fM", MolarityUnit.FemtomolePerLiter)] + [InlineData("en-US", "kmol/m³", MolarityUnit.KilomolePerCubicMeter)] + [InlineData("en-US", "µmol/l", MolarityUnit.MicromolePerLiter)] + [InlineData("en-US", "µM", MolarityUnit.MicromolePerLiter)] + [InlineData("en-US", "mmol/l", MolarityUnit.MillimolePerLiter)] + [InlineData("en-US", "mM", MolarityUnit.MillimolePerLiter)] + [InlineData("en-US", "mol/m³", MolarityUnit.MolePerCubicMeter)] + [InlineData("en-US", "mol/l", MolarityUnit.MolePerLiter)] + [InlineData("en-US", "M", MolarityUnit.MolePerLiter)] + [InlineData("en-US", "nmol/l", MolarityUnit.NanomolePerLiter)] + [InlineData("en-US", "nM", MolarityUnit.NanomolePerLiter)] + [InlineData("en-US", "pmol/l", MolarityUnit.PicomolePerLiter)] + [InlineData("en-US", "pM", MolarityUnit.PicomolePerLiter)] + [InlineData("en-US", "lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, MolarityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Molarity.TryParseUnit(abbreviation, out MolarityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -634,7 +747,7 @@ public void TryParseUnit(string abbreviation, MolarityUnit expectedUnit) [InlineData("en-US", "pmol/l", MolarityUnit.PicomolePerLiter)] [InlineData("en-US", "pM", MolarityUnit.PicomolePerLiter)] [InlineData("en-US", "lbmol/ft³", MolarityUnit.PoundMolePerCubicFoot)] - public void TryParseUnitWithCulture(string culture, string abbreviation, MolarityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, MolarityUnit expectedUnit) { Assert.True(Molarity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out MolarityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs index 430c05d0d7..7115a1e784 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermeabilityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("H/m", PermeabilityUnit.HenryPerMeter)] - public void ParseUnit(string abbreviation, PermeabilityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PermeabilityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - PermeabilityUnit parsedUnit = Permeability.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + PermeabilityUnit parsedUnit = Permeability.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("H/m", PermeabilityUnit.HenryPerMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PermeabilityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + PermeabilityUnit parsedUnit = Permeability.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "H/m", PermeabilityUnit.HenryPerMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, PermeabilityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, PermeabilityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + PermeabilityUnit parsedUnit = Permeability.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "H/m", PermeabilityUnit.HenryPerMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, PermeabilityUnit expectedUnit) { PermeabilityUnit parsedUnit = Permeability.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Permeabili [Theory] [InlineData("H/m", PermeabilityUnit.HenryPerMeter)] - public void TryParseUnit(string abbreviation, PermeabilityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PermeabilityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Permeability.TryParseUnit(abbreviation, out PermeabilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("H/m", PermeabilityUnit.HenryPerMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PermeabilityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Permeability.TryParseUnit(abbreviation, out PermeabilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "H/m", PermeabilityUnit.HenryPerMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, PermeabilityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Permeability.TryParseUnit(abbreviation, out PermeabilityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "H/m", PermeabilityUnit.HenryPerMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, PermeabilityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, PermeabilityUnit expectedUnit) { Assert.True(Permeability.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PermeabilityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs index 23bb2df94f..d78cfdd787 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PermittivityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("F/m", PermittivityUnit.FaradPerMeter)] - public void ParseUnit(string abbreviation, PermittivityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PermittivityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - PermittivityUnit parsedUnit = Permittivity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + PermittivityUnit parsedUnit = Permittivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("F/m", PermittivityUnit.FaradPerMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PermittivityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + PermittivityUnit parsedUnit = Permittivity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "F/m", PermittivityUnit.FaradPerMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, PermittivityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, PermittivityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + PermittivityUnit parsedUnit = Permittivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "F/m", PermittivityUnit.FaradPerMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, PermittivityUnit expectedUnit) { PermittivityUnit parsedUnit = Permittivity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Permittivi [Theory] [InlineData("F/m", PermittivityUnit.FaradPerMeter)] - public void TryParseUnit(string abbreviation, PermittivityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PermittivityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Permittivity.TryParseUnit(abbreviation, out PermittivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("F/m", PermittivityUnit.FaradPerMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PermittivityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Permittivity.TryParseUnit(abbreviation, out PermittivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "F/m", PermittivityUnit.FaradPerMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, PermittivityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Permittivity.TryParseUnit(abbreviation, out PermittivityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "F/m", PermittivityUnit.FaradPerMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, PermittivityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, PermittivityUnit expectedUnit) { Assert.True(Permittivity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PermittivityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs index 46fddd08b0..d868af356e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PorousMediumPermeabilityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -298,10 +299,25 @@ public void TryParse() [InlineData("mD", PorousMediumPermeabilityUnit.Millidarcy)] [InlineData("cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] [InlineData("m²", PorousMediumPermeabilityUnit.SquareMeter)] - public void ParseUnit(string abbreviation, PorousMediumPermeabilityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PorousMediumPermeabilityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - PorousMediumPermeabilityUnit parsedUnit = PorousMediumPermeability.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + PorousMediumPermeabilityUnit parsedUnit = PorousMediumPermeability.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("D", PorousMediumPermeabilityUnit.Darcy)] + [InlineData("µD", PorousMediumPermeabilityUnit.Microdarcy)] + [InlineData("mD", PorousMediumPermeabilityUnit.Millidarcy)] + [InlineData("cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] + [InlineData("m²", PorousMediumPermeabilityUnit.SquareMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PorousMediumPermeabilityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + PorousMediumPermeabilityUnit parsedUnit = PorousMediumPermeability.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -311,7 +327,20 @@ public void ParseUnit(string abbreviation, PorousMediumPermeabilityUnit expected [InlineData("en-US", "mD", PorousMediumPermeabilityUnit.Millidarcy)] [InlineData("en-US", "cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] [InlineData("en-US", "m²", PorousMediumPermeabilityUnit.SquareMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, PorousMediumPermeabilityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, PorousMediumPermeabilityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + PorousMediumPermeabilityUnit parsedUnit = PorousMediumPermeability.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "D", PorousMediumPermeabilityUnit.Darcy)] + [InlineData("en-US", "µD", PorousMediumPermeabilityUnit.Microdarcy)] + [InlineData("en-US", "mD", PorousMediumPermeabilityUnit.Millidarcy)] + [InlineData("en-US", "cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] + [InlineData("en-US", "m²", PorousMediumPermeabilityUnit.SquareMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, PorousMediumPermeabilityUnit expectedUnit) { PorousMediumPermeabilityUnit parsedUnit = PorousMediumPermeability.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -323,9 +352,37 @@ public void ParseUnitWithCulture(string culture, string abbreviation, PorousMedi [InlineData("mD", PorousMediumPermeabilityUnit.Millidarcy)] [InlineData("cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] [InlineData("m²", PorousMediumPermeabilityUnit.SquareMeter)] - public void TryParseUnit(string abbreviation, PorousMediumPermeabilityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PorousMediumPermeabilityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(PorousMediumPermeability.TryParseUnit(abbreviation, out PorousMediumPermeabilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("D", PorousMediumPermeabilityUnit.Darcy)] + [InlineData("µD", PorousMediumPermeabilityUnit.Microdarcy)] + [InlineData("mD", PorousMediumPermeabilityUnit.Millidarcy)] + [InlineData("cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] + [InlineData("m²", PorousMediumPermeabilityUnit.SquareMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PorousMediumPermeabilityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(PorousMediumPermeability.TryParseUnit(abbreviation, out PorousMediumPermeabilityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "D", PorousMediumPermeabilityUnit.Darcy)] + [InlineData("en-US", "µD", PorousMediumPermeabilityUnit.Microdarcy)] + [InlineData("en-US", "mD", PorousMediumPermeabilityUnit.Millidarcy)] + [InlineData("en-US", "cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] + [InlineData("en-US", "m²", PorousMediumPermeabilityUnit.SquareMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, PorousMediumPermeabilityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(PorousMediumPermeability.TryParseUnit(abbreviation, out PorousMediumPermeabilityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -336,7 +393,7 @@ public void TryParseUnit(string abbreviation, PorousMediumPermeabilityUnit expec [InlineData("en-US", "mD", PorousMediumPermeabilityUnit.Millidarcy)] [InlineData("en-US", "cm²", PorousMediumPermeabilityUnit.SquareCentimeter)] [InlineData("en-US", "m²", PorousMediumPermeabilityUnit.SquareMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, PorousMediumPermeabilityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, PorousMediumPermeabilityUnit expectedUnit) { Assert.True(PorousMediumPermeability.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PorousMediumPermeabilityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs index bf4c539243..df6f06df5a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerDensityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1186,10 +1187,64 @@ public void TryParse() [InlineData("W/in³", PowerDensityUnit.WattPerCubicInch)] [InlineData("W/m³", PowerDensityUnit.WattPerCubicMeter)] [InlineData("W/l", PowerDensityUnit.WattPerLiter)] - public void ParseUnit(string abbreviation, PowerDensityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PowerDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - PowerDensityUnit parsedUnit = PowerDensity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + PowerDensityUnit parsedUnit = PowerDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("daW/ft³", PowerDensityUnit.DecawattPerCubicFoot)] + [InlineData("daW/in³", PowerDensityUnit.DecawattPerCubicInch)] + [InlineData("daW/m³", PowerDensityUnit.DecawattPerCubicMeter)] + [InlineData("daW/l", PowerDensityUnit.DecawattPerLiter)] + [InlineData("dW/ft³", PowerDensityUnit.DeciwattPerCubicFoot)] + [InlineData("dW/in³", PowerDensityUnit.DeciwattPerCubicInch)] + [InlineData("dW/m³", PowerDensityUnit.DeciwattPerCubicMeter)] + [InlineData("dW/l", PowerDensityUnit.DeciwattPerLiter)] + [InlineData("GW/ft³", PowerDensityUnit.GigawattPerCubicFoot)] + [InlineData("GW/in³", PowerDensityUnit.GigawattPerCubicInch)] + [InlineData("GW/m³", PowerDensityUnit.GigawattPerCubicMeter)] + [InlineData("GW/l", PowerDensityUnit.GigawattPerLiter)] + [InlineData("kW/ft³", PowerDensityUnit.KilowattPerCubicFoot)] + [InlineData("kW/in³", PowerDensityUnit.KilowattPerCubicInch)] + [InlineData("kW/m³", PowerDensityUnit.KilowattPerCubicMeter)] + [InlineData("kW/l", PowerDensityUnit.KilowattPerLiter)] + [InlineData("MW/ft³", PowerDensityUnit.MegawattPerCubicFoot)] + [InlineData("MW/in³", PowerDensityUnit.MegawattPerCubicInch)] + [InlineData("MW/m³", PowerDensityUnit.MegawattPerCubicMeter)] + [InlineData("MW/l", PowerDensityUnit.MegawattPerLiter)] + [InlineData("µW/ft³", PowerDensityUnit.MicrowattPerCubicFoot)] + [InlineData("µW/in³", PowerDensityUnit.MicrowattPerCubicInch)] + [InlineData("µW/m³", PowerDensityUnit.MicrowattPerCubicMeter)] + [InlineData("µW/l", PowerDensityUnit.MicrowattPerLiter)] + [InlineData("mW/ft³", PowerDensityUnit.MilliwattPerCubicFoot)] + [InlineData("mW/in³", PowerDensityUnit.MilliwattPerCubicInch)] + [InlineData("mW/m³", PowerDensityUnit.MilliwattPerCubicMeter)] + [InlineData("mW/l", PowerDensityUnit.MilliwattPerLiter)] + [InlineData("nW/ft³", PowerDensityUnit.NanowattPerCubicFoot)] + [InlineData("nW/in³", PowerDensityUnit.NanowattPerCubicInch)] + [InlineData("nW/m³", PowerDensityUnit.NanowattPerCubicMeter)] + [InlineData("nW/l", PowerDensityUnit.NanowattPerLiter)] + [InlineData("pW/ft³", PowerDensityUnit.PicowattPerCubicFoot)] + [InlineData("pW/in³", PowerDensityUnit.PicowattPerCubicInch)] + [InlineData("pW/m³", PowerDensityUnit.PicowattPerCubicMeter)] + [InlineData("pW/l", PowerDensityUnit.PicowattPerLiter)] + [InlineData("TW/ft³", PowerDensityUnit.TerawattPerCubicFoot)] + [InlineData("TW/in³", PowerDensityUnit.TerawattPerCubicInch)] + [InlineData("TW/m³", PowerDensityUnit.TerawattPerCubicMeter)] + [InlineData("TW/l", PowerDensityUnit.TerawattPerLiter)] + [InlineData("W/ft³", PowerDensityUnit.WattPerCubicFoot)] + [InlineData("W/in³", PowerDensityUnit.WattPerCubicInch)] + [InlineData("W/m³", PowerDensityUnit.WattPerCubicMeter)] + [InlineData("W/l", PowerDensityUnit.WattPerLiter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PowerDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + PowerDensityUnit parsedUnit = PowerDensity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1238,7 +1293,59 @@ public void ParseUnit(string abbreviation, PowerDensityUnit expectedUnit) [InlineData("en-US", "W/in³", PowerDensityUnit.WattPerCubicInch)] [InlineData("en-US", "W/m³", PowerDensityUnit.WattPerCubicMeter)] [InlineData("en-US", "W/l", PowerDensityUnit.WattPerLiter)] - public void ParseUnitWithCulture(string culture, string abbreviation, PowerDensityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, PowerDensityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + PowerDensityUnit parsedUnit = PowerDensity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "daW/ft³", PowerDensityUnit.DecawattPerCubicFoot)] + [InlineData("en-US", "daW/in³", PowerDensityUnit.DecawattPerCubicInch)] + [InlineData("en-US", "daW/m³", PowerDensityUnit.DecawattPerCubicMeter)] + [InlineData("en-US", "daW/l", PowerDensityUnit.DecawattPerLiter)] + [InlineData("en-US", "dW/ft³", PowerDensityUnit.DeciwattPerCubicFoot)] + [InlineData("en-US", "dW/in³", PowerDensityUnit.DeciwattPerCubicInch)] + [InlineData("en-US", "dW/m³", PowerDensityUnit.DeciwattPerCubicMeter)] + [InlineData("en-US", "dW/l", PowerDensityUnit.DeciwattPerLiter)] + [InlineData("en-US", "GW/ft³", PowerDensityUnit.GigawattPerCubicFoot)] + [InlineData("en-US", "GW/in³", PowerDensityUnit.GigawattPerCubicInch)] + [InlineData("en-US", "GW/m³", PowerDensityUnit.GigawattPerCubicMeter)] + [InlineData("en-US", "GW/l", PowerDensityUnit.GigawattPerLiter)] + [InlineData("en-US", "kW/ft³", PowerDensityUnit.KilowattPerCubicFoot)] + [InlineData("en-US", "kW/in³", PowerDensityUnit.KilowattPerCubicInch)] + [InlineData("en-US", "kW/m³", PowerDensityUnit.KilowattPerCubicMeter)] + [InlineData("en-US", "kW/l", PowerDensityUnit.KilowattPerLiter)] + [InlineData("en-US", "MW/ft³", PowerDensityUnit.MegawattPerCubicFoot)] + [InlineData("en-US", "MW/in³", PowerDensityUnit.MegawattPerCubicInch)] + [InlineData("en-US", "MW/m³", PowerDensityUnit.MegawattPerCubicMeter)] + [InlineData("en-US", "MW/l", PowerDensityUnit.MegawattPerLiter)] + [InlineData("en-US", "µW/ft³", PowerDensityUnit.MicrowattPerCubicFoot)] + [InlineData("en-US", "µW/in³", PowerDensityUnit.MicrowattPerCubicInch)] + [InlineData("en-US", "µW/m³", PowerDensityUnit.MicrowattPerCubicMeter)] + [InlineData("en-US", "µW/l", PowerDensityUnit.MicrowattPerLiter)] + [InlineData("en-US", "mW/ft³", PowerDensityUnit.MilliwattPerCubicFoot)] + [InlineData("en-US", "mW/in³", PowerDensityUnit.MilliwattPerCubicInch)] + [InlineData("en-US", "mW/m³", PowerDensityUnit.MilliwattPerCubicMeter)] + [InlineData("en-US", "mW/l", PowerDensityUnit.MilliwattPerLiter)] + [InlineData("en-US", "nW/ft³", PowerDensityUnit.NanowattPerCubicFoot)] + [InlineData("en-US", "nW/in³", PowerDensityUnit.NanowattPerCubicInch)] + [InlineData("en-US", "nW/m³", PowerDensityUnit.NanowattPerCubicMeter)] + [InlineData("en-US", "nW/l", PowerDensityUnit.NanowattPerLiter)] + [InlineData("en-US", "pW/ft³", PowerDensityUnit.PicowattPerCubicFoot)] + [InlineData("en-US", "pW/in³", PowerDensityUnit.PicowattPerCubicInch)] + [InlineData("en-US", "pW/m³", PowerDensityUnit.PicowattPerCubicMeter)] + [InlineData("en-US", "pW/l", PowerDensityUnit.PicowattPerLiter)] + [InlineData("en-US", "TW/ft³", PowerDensityUnit.TerawattPerCubicFoot)] + [InlineData("en-US", "TW/in³", PowerDensityUnit.TerawattPerCubicInch)] + [InlineData("en-US", "TW/m³", PowerDensityUnit.TerawattPerCubicMeter)] + [InlineData("en-US", "TW/l", PowerDensityUnit.TerawattPerLiter)] + [InlineData("en-US", "W/ft³", PowerDensityUnit.WattPerCubicFoot)] + [InlineData("en-US", "W/in³", PowerDensityUnit.WattPerCubicInch)] + [InlineData("en-US", "W/m³", PowerDensityUnit.WattPerCubicMeter)] + [InlineData("en-US", "W/l", PowerDensityUnit.WattPerLiter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, PowerDensityUnit expectedUnit) { PowerDensityUnit parsedUnit = PowerDensity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1289,9 +1396,115 @@ public void ParseUnitWithCulture(string culture, string abbreviation, PowerDensi [InlineData("W/in³", PowerDensityUnit.WattPerCubicInch)] [InlineData("W/m³", PowerDensityUnit.WattPerCubicMeter)] [InlineData("W/l", PowerDensityUnit.WattPerLiter)] - public void TryParseUnit(string abbreviation, PowerDensityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PowerDensityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(PowerDensity.TryParseUnit(abbreviation, out PowerDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("daW/ft³", PowerDensityUnit.DecawattPerCubicFoot)] + [InlineData("daW/in³", PowerDensityUnit.DecawattPerCubicInch)] + [InlineData("daW/m³", PowerDensityUnit.DecawattPerCubicMeter)] + [InlineData("daW/l", PowerDensityUnit.DecawattPerLiter)] + [InlineData("dW/ft³", PowerDensityUnit.DeciwattPerCubicFoot)] + [InlineData("dW/in³", PowerDensityUnit.DeciwattPerCubicInch)] + [InlineData("dW/m³", PowerDensityUnit.DeciwattPerCubicMeter)] + [InlineData("dW/l", PowerDensityUnit.DeciwattPerLiter)] + [InlineData("GW/ft³", PowerDensityUnit.GigawattPerCubicFoot)] + [InlineData("GW/in³", PowerDensityUnit.GigawattPerCubicInch)] + [InlineData("GW/m³", PowerDensityUnit.GigawattPerCubicMeter)] + [InlineData("GW/l", PowerDensityUnit.GigawattPerLiter)] + [InlineData("kW/ft³", PowerDensityUnit.KilowattPerCubicFoot)] + [InlineData("kW/in³", PowerDensityUnit.KilowattPerCubicInch)] + [InlineData("kW/m³", PowerDensityUnit.KilowattPerCubicMeter)] + [InlineData("kW/l", PowerDensityUnit.KilowattPerLiter)] + [InlineData("MW/ft³", PowerDensityUnit.MegawattPerCubicFoot)] + [InlineData("MW/in³", PowerDensityUnit.MegawattPerCubicInch)] + [InlineData("MW/m³", PowerDensityUnit.MegawattPerCubicMeter)] + [InlineData("MW/l", PowerDensityUnit.MegawattPerLiter)] + [InlineData("µW/ft³", PowerDensityUnit.MicrowattPerCubicFoot)] + [InlineData("µW/in³", PowerDensityUnit.MicrowattPerCubicInch)] + [InlineData("µW/m³", PowerDensityUnit.MicrowattPerCubicMeter)] + [InlineData("µW/l", PowerDensityUnit.MicrowattPerLiter)] + [InlineData("mW/ft³", PowerDensityUnit.MilliwattPerCubicFoot)] + [InlineData("mW/in³", PowerDensityUnit.MilliwattPerCubicInch)] + [InlineData("mW/m³", PowerDensityUnit.MilliwattPerCubicMeter)] + [InlineData("mW/l", PowerDensityUnit.MilliwattPerLiter)] + [InlineData("nW/ft³", PowerDensityUnit.NanowattPerCubicFoot)] + [InlineData("nW/in³", PowerDensityUnit.NanowattPerCubicInch)] + [InlineData("nW/m³", PowerDensityUnit.NanowattPerCubicMeter)] + [InlineData("nW/l", PowerDensityUnit.NanowattPerLiter)] + [InlineData("pW/ft³", PowerDensityUnit.PicowattPerCubicFoot)] + [InlineData("pW/in³", PowerDensityUnit.PicowattPerCubicInch)] + [InlineData("pW/m³", PowerDensityUnit.PicowattPerCubicMeter)] + [InlineData("pW/l", PowerDensityUnit.PicowattPerLiter)] + [InlineData("TW/ft³", PowerDensityUnit.TerawattPerCubicFoot)] + [InlineData("TW/in³", PowerDensityUnit.TerawattPerCubicInch)] + [InlineData("TW/m³", PowerDensityUnit.TerawattPerCubicMeter)] + [InlineData("TW/l", PowerDensityUnit.TerawattPerLiter)] + [InlineData("W/ft³", PowerDensityUnit.WattPerCubicFoot)] + [InlineData("W/in³", PowerDensityUnit.WattPerCubicInch)] + [InlineData("W/m³", PowerDensityUnit.WattPerCubicMeter)] + [InlineData("W/l", PowerDensityUnit.WattPerLiter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PowerDensityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(PowerDensity.TryParseUnit(abbreviation, out PowerDensityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "daW/ft³", PowerDensityUnit.DecawattPerCubicFoot)] + [InlineData("en-US", "daW/in³", PowerDensityUnit.DecawattPerCubicInch)] + [InlineData("en-US", "daW/m³", PowerDensityUnit.DecawattPerCubicMeter)] + [InlineData("en-US", "daW/l", PowerDensityUnit.DecawattPerLiter)] + [InlineData("en-US", "dW/ft³", PowerDensityUnit.DeciwattPerCubicFoot)] + [InlineData("en-US", "dW/in³", PowerDensityUnit.DeciwattPerCubicInch)] + [InlineData("en-US", "dW/m³", PowerDensityUnit.DeciwattPerCubicMeter)] + [InlineData("en-US", "dW/l", PowerDensityUnit.DeciwattPerLiter)] + [InlineData("en-US", "GW/ft³", PowerDensityUnit.GigawattPerCubicFoot)] + [InlineData("en-US", "GW/in³", PowerDensityUnit.GigawattPerCubicInch)] + [InlineData("en-US", "GW/m³", PowerDensityUnit.GigawattPerCubicMeter)] + [InlineData("en-US", "GW/l", PowerDensityUnit.GigawattPerLiter)] + [InlineData("en-US", "kW/ft³", PowerDensityUnit.KilowattPerCubicFoot)] + [InlineData("en-US", "kW/in³", PowerDensityUnit.KilowattPerCubicInch)] + [InlineData("en-US", "kW/m³", PowerDensityUnit.KilowattPerCubicMeter)] + [InlineData("en-US", "kW/l", PowerDensityUnit.KilowattPerLiter)] + [InlineData("en-US", "MW/ft³", PowerDensityUnit.MegawattPerCubicFoot)] + [InlineData("en-US", "MW/in³", PowerDensityUnit.MegawattPerCubicInch)] + [InlineData("en-US", "MW/m³", PowerDensityUnit.MegawattPerCubicMeter)] + [InlineData("en-US", "MW/l", PowerDensityUnit.MegawattPerLiter)] + [InlineData("en-US", "µW/ft³", PowerDensityUnit.MicrowattPerCubicFoot)] + [InlineData("en-US", "µW/in³", PowerDensityUnit.MicrowattPerCubicInch)] + [InlineData("en-US", "µW/m³", PowerDensityUnit.MicrowattPerCubicMeter)] + [InlineData("en-US", "µW/l", PowerDensityUnit.MicrowattPerLiter)] + [InlineData("en-US", "mW/ft³", PowerDensityUnit.MilliwattPerCubicFoot)] + [InlineData("en-US", "mW/in³", PowerDensityUnit.MilliwattPerCubicInch)] + [InlineData("en-US", "mW/m³", PowerDensityUnit.MilliwattPerCubicMeter)] + [InlineData("en-US", "mW/l", PowerDensityUnit.MilliwattPerLiter)] + [InlineData("en-US", "nW/ft³", PowerDensityUnit.NanowattPerCubicFoot)] + [InlineData("en-US", "nW/in³", PowerDensityUnit.NanowattPerCubicInch)] + [InlineData("en-US", "nW/m³", PowerDensityUnit.NanowattPerCubicMeter)] + [InlineData("en-US", "nW/l", PowerDensityUnit.NanowattPerLiter)] + [InlineData("en-US", "pW/ft³", PowerDensityUnit.PicowattPerCubicFoot)] + [InlineData("en-US", "pW/in³", PowerDensityUnit.PicowattPerCubicInch)] + [InlineData("en-US", "pW/m³", PowerDensityUnit.PicowattPerCubicMeter)] + [InlineData("en-US", "pW/l", PowerDensityUnit.PicowattPerLiter)] + [InlineData("en-US", "TW/ft³", PowerDensityUnit.TerawattPerCubicFoot)] + [InlineData("en-US", "TW/in³", PowerDensityUnit.TerawattPerCubicInch)] + [InlineData("en-US", "TW/m³", PowerDensityUnit.TerawattPerCubicMeter)] + [InlineData("en-US", "TW/l", PowerDensityUnit.TerawattPerLiter)] + [InlineData("en-US", "W/ft³", PowerDensityUnit.WattPerCubicFoot)] + [InlineData("en-US", "W/in³", PowerDensityUnit.WattPerCubicInch)] + [InlineData("en-US", "W/m³", PowerDensityUnit.WattPerCubicMeter)] + [InlineData("en-US", "W/l", PowerDensityUnit.WattPerLiter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, PowerDensityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(PowerDensity.TryParseUnit(abbreviation, out PowerDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1341,7 +1554,7 @@ public void TryParseUnit(string abbreviation, PowerDensityUnit expectedUnit) [InlineData("en-US", "W/in³", PowerDensityUnit.WattPerCubicInch)] [InlineData("en-US", "W/m³", PowerDensityUnit.WattPerCubicMeter)] [InlineData("en-US", "W/l", PowerDensityUnit.WattPerLiter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, PowerDensityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, PowerDensityUnit expectedUnit) { Assert.True(PowerDensity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PowerDensityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs index 2006e16671..2e6a11a64c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerRatioTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -240,10 +241,23 @@ public void TryParse() [InlineData("dBmW", PowerRatioUnit.DecibelMilliwatt)] [InlineData("dBm", PowerRatioUnit.DecibelMilliwatt)] [InlineData("dBW", PowerRatioUnit.DecibelWatt)] - public void ParseUnit(string abbreviation, PowerRatioUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PowerRatioUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - PowerRatioUnit parsedUnit = PowerRatio.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + PowerRatioUnit parsedUnit = PowerRatio.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("dBmW", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("dBm", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("dBW", PowerRatioUnit.DecibelWatt)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PowerRatioUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + PowerRatioUnit parsedUnit = PowerRatio.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -251,7 +265,18 @@ public void ParseUnit(string abbreviation, PowerRatioUnit expectedUnit) [InlineData("en-US", "dBmW", PowerRatioUnit.DecibelMilliwatt)] [InlineData("en-US", "dBm", PowerRatioUnit.DecibelMilliwatt)] [InlineData("en-US", "dBW", PowerRatioUnit.DecibelWatt)] - public void ParseUnitWithCulture(string culture, string abbreviation, PowerRatioUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, PowerRatioUnit expectedUnit) + { + using var _ = new CultureScope(culture); + PowerRatioUnit parsedUnit = PowerRatio.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "dBmW", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("en-US", "dBm", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("en-US", "dBW", PowerRatioUnit.DecibelWatt)] + public void ParseUnit_WithCulture(string culture, string abbreviation, PowerRatioUnit expectedUnit) { PowerRatioUnit parsedUnit = PowerRatio.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -261,9 +286,33 @@ public void ParseUnitWithCulture(string culture, string abbreviation, PowerRatio [InlineData("dBmW", PowerRatioUnit.DecibelMilliwatt)] [InlineData("dBm", PowerRatioUnit.DecibelMilliwatt)] [InlineData("dBW", PowerRatioUnit.DecibelWatt)] - public void TryParseUnit(string abbreviation, PowerRatioUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PowerRatioUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(PowerRatio.TryParseUnit(abbreviation, out PowerRatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("dBmW", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("dBm", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("dBW", PowerRatioUnit.DecibelWatt)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PowerRatioUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(PowerRatio.TryParseUnit(abbreviation, out PowerRatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "dBmW", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("en-US", "dBm", PowerRatioUnit.DecibelMilliwatt)] + [InlineData("en-US", "dBW", PowerRatioUnit.DecibelWatt)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, PowerRatioUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(PowerRatio.TryParseUnit(abbreviation, out PowerRatioUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -272,7 +321,7 @@ public void TryParseUnit(string abbreviation, PowerRatioUnit expectedUnit) [InlineData("en-US", "dBmW", PowerRatioUnit.DecibelMilliwatt)] [InlineData("en-US", "dBm", PowerRatioUnit.DecibelMilliwatt)] [InlineData("en-US", "dBW", PowerRatioUnit.DecibelWatt)] - public void TryParseUnitWithCulture(string culture, string abbreviation, PowerRatioUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, PowerRatioUnit expectedUnit) { Assert.True(PowerRatio.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PowerRatioUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs index dec2afc552..0630e6dff2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PowerTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -832,10 +833,50 @@ public void TryParse() [InlineData("TW", PowerUnit.Terawatt)] [InlineData("TR", PowerUnit.TonOfRefrigeration)] [InlineData("W", PowerUnit.Watt)] - public void ParseUnit(string abbreviation, PowerUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PowerUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - PowerUnit parsedUnit = Power.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + PowerUnit parsedUnit = Power.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("hp(S)", PowerUnit.BoilerHorsepower)] + [InlineData("Btu/h", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("Btu/hr", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("daW", PowerUnit.Decawatt)] + [InlineData("dW", PowerUnit.Deciwatt)] + [InlineData("hp(E)", PowerUnit.ElectricalHorsepower)] + [InlineData("fW", PowerUnit.Femtowatt)] + [InlineData("GJ/h", PowerUnit.GigajoulePerHour)] + [InlineData("GW", PowerUnit.Gigawatt)] + [InlineData("hp(H)", PowerUnit.HydraulicHorsepower)] + [InlineData("J/h", PowerUnit.JoulePerHour)] + [InlineData("kBtu/h", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("kBtu/hr", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("kJ/h", PowerUnit.KilojoulePerHour)] + [InlineData("kW", PowerUnit.Kilowatt)] + [InlineData("hp(I)", PowerUnit.MechanicalHorsepower)] + [InlineData("MBtu/h", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("MBtu/hr", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("MJ/h", PowerUnit.MegajoulePerHour)] + [InlineData("MW", PowerUnit.Megawatt)] + [InlineData("hp(M)", PowerUnit.MetricHorsepower)] + [InlineData("µW", PowerUnit.Microwatt)] + [InlineData("mJ/h", PowerUnit.MillijoulePerHour)] + [InlineData("mW", PowerUnit.Milliwatt)] + [InlineData("nW", PowerUnit.Nanowatt)] + [InlineData("PW", PowerUnit.Petawatt)] + [InlineData("pW", PowerUnit.Picowatt)] + [InlineData("TW", PowerUnit.Terawatt)] + [InlineData("TR", PowerUnit.TonOfRefrigeration)] + [InlineData("W", PowerUnit.Watt)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PowerUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + PowerUnit parsedUnit = Power.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -870,7 +911,45 @@ public void ParseUnit(string abbreviation, PowerUnit expectedUnit) [InlineData("en-US", "TW", PowerUnit.Terawatt)] [InlineData("en-US", "TR", PowerUnit.TonOfRefrigeration)] [InlineData("en-US", "W", PowerUnit.Watt)] - public void ParseUnitWithCulture(string culture, string abbreviation, PowerUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, PowerUnit expectedUnit) + { + using var _ = new CultureScope(culture); + PowerUnit parsedUnit = Power.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "hp(S)", PowerUnit.BoilerHorsepower)] + [InlineData("en-US", "Btu/h", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("en-US", "Btu/hr", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("en-US", "daW", PowerUnit.Decawatt)] + [InlineData("en-US", "dW", PowerUnit.Deciwatt)] + [InlineData("en-US", "hp(E)", PowerUnit.ElectricalHorsepower)] + [InlineData("en-US", "fW", PowerUnit.Femtowatt)] + [InlineData("en-US", "GJ/h", PowerUnit.GigajoulePerHour)] + [InlineData("en-US", "GW", PowerUnit.Gigawatt)] + [InlineData("en-US", "hp(H)", PowerUnit.HydraulicHorsepower)] + [InlineData("en-US", "J/h", PowerUnit.JoulePerHour)] + [InlineData("en-US", "kBtu/h", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("en-US", "kBtu/hr", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("en-US", "kJ/h", PowerUnit.KilojoulePerHour)] + [InlineData("en-US", "kW", PowerUnit.Kilowatt)] + [InlineData("en-US", "hp(I)", PowerUnit.MechanicalHorsepower)] + [InlineData("en-US", "MBtu/h", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("en-US", "MBtu/hr", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("en-US", "MJ/h", PowerUnit.MegajoulePerHour)] + [InlineData("en-US", "MW", PowerUnit.Megawatt)] + [InlineData("en-US", "hp(M)", PowerUnit.MetricHorsepower)] + [InlineData("en-US", "µW", PowerUnit.Microwatt)] + [InlineData("en-US", "mJ/h", PowerUnit.MillijoulePerHour)] + [InlineData("en-US", "mW", PowerUnit.Milliwatt)] + [InlineData("en-US", "nW", PowerUnit.Nanowatt)] + [InlineData("en-US", "PW", PowerUnit.Petawatt)] + [InlineData("en-US", "pW", PowerUnit.Picowatt)] + [InlineData("en-US", "TW", PowerUnit.Terawatt)] + [InlineData("en-US", "TR", PowerUnit.TonOfRefrigeration)] + [InlineData("en-US", "W", PowerUnit.Watt)] + public void ParseUnit_WithCulture(string culture, string abbreviation, PowerUnit expectedUnit) { PowerUnit parsedUnit = Power.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -907,9 +986,87 @@ public void ParseUnitWithCulture(string culture, string abbreviation, PowerUnit [InlineData("TW", PowerUnit.Terawatt)] [InlineData("TR", PowerUnit.TonOfRefrigeration)] [InlineData("W", PowerUnit.Watt)] - public void TryParseUnit(string abbreviation, PowerUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PowerUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Power.TryParseUnit(abbreviation, out PowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("hp(S)", PowerUnit.BoilerHorsepower)] + [InlineData("Btu/h", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("Btu/hr", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("daW", PowerUnit.Decawatt)] + [InlineData("dW", PowerUnit.Deciwatt)] + [InlineData("hp(E)", PowerUnit.ElectricalHorsepower)] + [InlineData("fW", PowerUnit.Femtowatt)] + [InlineData("GJ/h", PowerUnit.GigajoulePerHour)] + [InlineData("GW", PowerUnit.Gigawatt)] + [InlineData("hp(H)", PowerUnit.HydraulicHorsepower)] + [InlineData("J/h", PowerUnit.JoulePerHour)] + [InlineData("kBtu/h", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("kBtu/hr", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("kJ/h", PowerUnit.KilojoulePerHour)] + [InlineData("kW", PowerUnit.Kilowatt)] + [InlineData("hp(I)", PowerUnit.MechanicalHorsepower)] + [InlineData("MBtu/h", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("MBtu/hr", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("MJ/h", PowerUnit.MegajoulePerHour)] + [InlineData("MW", PowerUnit.Megawatt)] + [InlineData("hp(M)", PowerUnit.MetricHorsepower)] + [InlineData("µW", PowerUnit.Microwatt)] + [InlineData("mJ/h", PowerUnit.MillijoulePerHour)] + [InlineData("mW", PowerUnit.Milliwatt)] + [InlineData("nW", PowerUnit.Nanowatt)] + [InlineData("PW", PowerUnit.Petawatt)] + [InlineData("pW", PowerUnit.Picowatt)] + [InlineData("TW", PowerUnit.Terawatt)] + [InlineData("TR", PowerUnit.TonOfRefrigeration)] + [InlineData("W", PowerUnit.Watt)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PowerUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Power.TryParseUnit(abbreviation, out PowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "hp(S)", PowerUnit.BoilerHorsepower)] + [InlineData("en-US", "Btu/h", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("en-US", "Btu/hr", PowerUnit.BritishThermalUnitPerHour)] + [InlineData("en-US", "daW", PowerUnit.Decawatt)] + [InlineData("en-US", "dW", PowerUnit.Deciwatt)] + [InlineData("en-US", "hp(E)", PowerUnit.ElectricalHorsepower)] + [InlineData("en-US", "fW", PowerUnit.Femtowatt)] + [InlineData("en-US", "GJ/h", PowerUnit.GigajoulePerHour)] + [InlineData("en-US", "GW", PowerUnit.Gigawatt)] + [InlineData("en-US", "hp(H)", PowerUnit.HydraulicHorsepower)] + [InlineData("en-US", "J/h", PowerUnit.JoulePerHour)] + [InlineData("en-US", "kBtu/h", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("en-US", "kBtu/hr", PowerUnit.KilobritishThermalUnitPerHour)] + [InlineData("en-US", "kJ/h", PowerUnit.KilojoulePerHour)] + [InlineData("en-US", "kW", PowerUnit.Kilowatt)] + [InlineData("en-US", "hp(I)", PowerUnit.MechanicalHorsepower)] + [InlineData("en-US", "MBtu/h", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("en-US", "MBtu/hr", PowerUnit.MegabritishThermalUnitPerHour)] + [InlineData("en-US", "MJ/h", PowerUnit.MegajoulePerHour)] + [InlineData("en-US", "MW", PowerUnit.Megawatt)] + [InlineData("en-US", "hp(M)", PowerUnit.MetricHorsepower)] + [InlineData("en-US", "µW", PowerUnit.Microwatt)] + [InlineData("en-US", "mJ/h", PowerUnit.MillijoulePerHour)] + [InlineData("en-US", "mW", PowerUnit.Milliwatt)] + [InlineData("en-US", "nW", PowerUnit.Nanowatt)] + [InlineData("en-US", "PW", PowerUnit.Petawatt)] + [InlineData("en-US", "pW", PowerUnit.Picowatt)] + [InlineData("en-US", "TW", PowerUnit.Terawatt)] + [InlineData("en-US", "TR", PowerUnit.TonOfRefrigeration)] + [InlineData("en-US", "W", PowerUnit.Watt)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, PowerUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Power.TryParseUnit(abbreviation, out PowerUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -945,7 +1102,7 @@ public void TryParseUnit(string abbreviation, PowerUnit expectedUnit) [InlineData("en-US", "TW", PowerUnit.Terawatt)] [InlineData("en-US", "TR", PowerUnit.TonOfRefrigeration)] [InlineData("en-US", "W", PowerUnit.Watt)] - public void TryParseUnitWithCulture(string culture, string abbreviation, PowerUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, PowerUnit expectedUnit) { Assert.True(Power.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PowerUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs index c95e405394..8541542822 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureChangeRateTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1006,10 +1007,44 @@ public void TryParse() [InlineData("lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] [InlineData("psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] [InlineData("lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] - public void ParseUnit(string abbreviation, PressureChangeRateUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PressureChangeRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - PressureChangeRateUnit parsedUnit = PressureChangeRate.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + PressureChangeRateUnit parsedUnit = PressureChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("atm/s", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("bar/min", PressureChangeRateUnit.BarPerMinute)] + [InlineData("bar/s", PressureChangeRateUnit.BarPerSecond)] + [InlineData("kPa/min", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("kPa/s", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("ksi/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("kipf/in²/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ksi/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("kipf/in²/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("MPa/min", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("MPa/s", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("Mpsi/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("Mlb/in²/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("Mpsi/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("Mlb/in²/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("mbar/min", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("mbar/s", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("mmHg/s", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("Pa/min", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("Pa/s", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("psi/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PressureChangeRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + PressureChangeRateUnit parsedUnit = PressureChangeRate.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1062,7 +1097,63 @@ public void ParseUnit(string abbreviation, PressureChangeRateUnit expectedUnit) [InlineData("ru-RU", "lb/in²/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] [InlineData("ru-RU", "psi/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] [InlineData("ru-RU", "lb/in²/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, PressureChangeRateUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, PressureChangeRateUnit expectedUnit) + { + using var _ = new CultureScope(culture); + PressureChangeRateUnit parsedUnit = PressureChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "atm/s", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("en-US", "bar/min", PressureChangeRateUnit.BarPerMinute)] + [InlineData("en-US", "bar/s", PressureChangeRateUnit.BarPerSecond)] + [InlineData("en-US", "kPa/min", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("en-US", "kPa/s", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("en-US", "ksi/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "kipf/in²/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "ksi/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "kipf/in²/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "MPa/min", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("en-US", "MPa/s", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("en-US", "Mpsi/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "Mlb/in²/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "Mpsi/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "Mlb/in²/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "mbar/min", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("en-US", "mbar/s", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("en-US", "mmHg/s", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("en-US", "Pa/min", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("en-US", "Pa/s", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("en-US", "psi/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "атм/с", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("ru-RU", "бар/мин", PressureChangeRateUnit.BarPerMinute)] + [InlineData("ru-RU", "бар/с", PressureChangeRateUnit.BarPerSecond)] + [InlineData("ru-RU", "кПа/мин", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("ru-RU", "кПа/с", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("ru-RU", "ksi/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "kipf/in²/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "ksi/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "kipf/in²/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "МПа/мин", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("ru-RU", "МПа/с", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("ru-RU", "Мpsi/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "Мlb/in²/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "Мpsi/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "Мlb/in²/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "мбар/мин", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("ru-RU", "мбар/с", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("ru-RU", "mmHg/с", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("ru-RU", "Па/мин", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("ru-RU", "Па/с", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("ru-RU", "psi/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "lb/in²/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "psi/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "lb/in²/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, PressureChangeRateUnit expectedUnit) { PressureChangeRateUnit parsedUnit = PressureChangeRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1093,9 +1184,99 @@ public void ParseUnitWithCulture(string culture, string abbreviation, PressureCh [InlineData("lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] [InlineData("psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] [InlineData("lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] - public void TryParseUnit(string abbreviation, PressureChangeRateUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PressureChangeRateUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(PressureChangeRate.TryParseUnit(abbreviation, out PressureChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("atm/s", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("bar/min", PressureChangeRateUnit.BarPerMinute)] + [InlineData("bar/s", PressureChangeRateUnit.BarPerSecond)] + [InlineData("kPa/min", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("kPa/s", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("ksi/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("kipf/in²/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ksi/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("kipf/in²/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("MPa/min", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("MPa/s", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("Mpsi/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("Mlb/in²/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("Mpsi/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("Mlb/in²/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("mbar/min", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("mbar/s", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("mmHg/s", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("Pa/min", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("Pa/s", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("psi/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PressureChangeRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(PressureChangeRate.TryParseUnit(abbreviation, out PressureChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "atm/s", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("en-US", "bar/min", PressureChangeRateUnit.BarPerMinute)] + [InlineData("en-US", "bar/s", PressureChangeRateUnit.BarPerSecond)] + [InlineData("en-US", "kPa/min", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("en-US", "kPa/s", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("en-US", "ksi/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "kipf/in²/min", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "ksi/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "kipf/in²/s", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "MPa/min", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("en-US", "MPa/s", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("en-US", "Mpsi/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "Mlb/in²/min", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "Mpsi/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "Mlb/in²/s", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "mbar/min", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("en-US", "mbar/s", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("en-US", "mmHg/s", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("en-US", "Pa/min", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("en-US", "Pa/s", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("en-US", "psi/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "lb/in²/min", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("en-US", "psi/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("en-US", "lb/in²/s", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "атм/с", PressureChangeRateUnit.AtmospherePerSecond)] + [InlineData("ru-RU", "бар/мин", PressureChangeRateUnit.BarPerMinute)] + [InlineData("ru-RU", "бар/с", PressureChangeRateUnit.BarPerSecond)] + [InlineData("ru-RU", "кПа/мин", PressureChangeRateUnit.KilopascalPerMinute)] + [InlineData("ru-RU", "кПа/с", PressureChangeRateUnit.KilopascalPerSecond)] + [InlineData("ru-RU", "ksi/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "kipf/in²/мин", PressureChangeRateUnit.KilopoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "ksi/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "kipf/in²/с", PressureChangeRateUnit.KilopoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "МПа/мин", PressureChangeRateUnit.MegapascalPerMinute)] + [InlineData("ru-RU", "МПа/с", PressureChangeRateUnit.MegapascalPerSecond)] + [InlineData("ru-RU", "Мpsi/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "Мlb/in²/мин", PressureChangeRateUnit.MegapoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "Мpsi/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "Мlb/in²/с", PressureChangeRateUnit.MegapoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "мбар/мин", PressureChangeRateUnit.MillibarPerMinute)] + [InlineData("ru-RU", "мбар/с", PressureChangeRateUnit.MillibarPerSecond)] + [InlineData("ru-RU", "mmHg/с", PressureChangeRateUnit.MillimeterOfMercuryPerSecond)] + [InlineData("ru-RU", "Па/мин", PressureChangeRateUnit.PascalPerMinute)] + [InlineData("ru-RU", "Па/с", PressureChangeRateUnit.PascalPerSecond)] + [InlineData("ru-RU", "psi/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "lb/in²/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] + [InlineData("ru-RU", "psi/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + [InlineData("ru-RU", "lb/in²/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, PressureChangeRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(PressureChangeRate.TryParseUnit(abbreviation, out PressureChangeRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1149,7 +1330,7 @@ public void TryParseUnit(string abbreviation, PressureChangeRateUnit expectedUni [InlineData("ru-RU", "lb/in²/мин", PressureChangeRateUnit.PoundForcePerSquareInchPerMinute)] [InlineData("ru-RU", "psi/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] [InlineData("ru-RU", "lb/in²/с", PressureChangeRateUnit.PoundForcePerSquareInchPerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, PressureChangeRateUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, PressureChangeRateUnit expectedUnit) { Assert.True(PressureChangeRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PressureChangeRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs index 0653b58774..21fea9cf58 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/PressureTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1933,10 +1934,189 @@ public void TryParse() [InlineData("tf/m²", PressureUnit.TonneForcePerSquareMeter)] [InlineData("tf/mm²", PressureUnit.TonneForcePerSquareMillimeter)] [InlineData("torr", PressureUnit.Torr)] - public void ParseUnit(string abbreviation, PressureUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PressureUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - PressureUnit parsedUnit = Pressure.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + PressureUnit parsedUnit = Pressure.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("atm", PressureUnit.Atmosphere)] + [InlineData("bar", PressureUnit.Bar)] + [InlineData("cbar", PressureUnit.Centibar)] + [InlineData("cmH₂O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cmH2O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cm wc", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cm wg", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("daPa", PressureUnit.Decapascal)] + [InlineData("dbar", PressureUnit.Decibar)] + [InlineData("dyn/cm²", PressureUnit.DynePerSquareCentimeter)] + [InlineData("ft of elevation", PressureUnit.FootOfElevation)] + [InlineData("ft of head", PressureUnit.FootOfHead)] + [InlineData("GPa", PressureUnit.Gigapascal)] + [InlineData("hPa", PressureUnit.Hectopascal)] + [InlineData("inHg", PressureUnit.InchOfMercury)] + [InlineData("inH2O", PressureUnit.InchOfWaterColumn)] + [InlineData("inch wc", PressureUnit.InchOfWaterColumn)] + [InlineData("wc", PressureUnit.InchOfWaterColumn)] + [InlineData("kbar", PressureUnit.Kilobar)] + [InlineData("kgf/cm²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("kgf/m²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("kgf/mm²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("kN/cm²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("kN/m²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("kN/mm²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("kPa", PressureUnit.Kilopascal)] + [InlineData("kipf/ft²", PressureUnit.KilopoundForcePerSquareFoot)] + [InlineData("ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("kipf/mil²", PressureUnit.KilopoundForcePerSquareMil)] + [InlineData("Mbar", PressureUnit.Megabar)] + [InlineData("MN/m²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("MPa", PressureUnit.Megapascal)] + [InlineData("m of elevation", PressureUnit.MeterOfElevation)] + [InlineData("m of head", PressureUnit.MeterOfHead)] + [InlineData("mH₂O", PressureUnit.MeterOfWaterColumn)] + [InlineData("mH2O", PressureUnit.MeterOfWaterColumn)] + [InlineData("m wc", PressureUnit.MeterOfWaterColumn)] + [InlineData("m wg", PressureUnit.MeterOfWaterColumn)] + [InlineData("µbar", PressureUnit.Microbar)] + [InlineData("µPa", PressureUnit.Micropascal)] + [InlineData("mbar", PressureUnit.Millibar)] + [InlineData("mmHg", PressureUnit.MillimeterOfMercury)] + [InlineData("mmH₂O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mmH2O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mm wc", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mm wg", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mPa", PressureUnit.Millipascal)] + [InlineData("N/cm²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("N/m²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("N/mm²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("Pa", PressureUnit.Pascal)] + [InlineData("lb/ft²", PressureUnit.PoundForcePerSquareFoot)] + [InlineData("psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("lb/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("lbs/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("lbm/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("lb/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("at", PressureUnit.TechnicalAtmosphere)] + [InlineData("tf/cm²", PressureUnit.TonneForcePerSquareCentimeter)] + [InlineData("tf/m²", PressureUnit.TonneForcePerSquareMeter)] + [InlineData("tf/mm²", PressureUnit.TonneForcePerSquareMillimeter)] + [InlineData("torr", PressureUnit.Torr)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PressureUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + PressureUnit parsedUnit = Pressure.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "atm", PressureUnit.Atmosphere)] + [InlineData("en-US", "bar", PressureUnit.Bar)] + [InlineData("en-US", "cbar", PressureUnit.Centibar)] + [InlineData("en-US", "cmH₂O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cmH2O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cm wc", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cm wg", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "daPa", PressureUnit.Decapascal)] + [InlineData("en-US", "dbar", PressureUnit.Decibar)] + [InlineData("en-US", "dyn/cm²", PressureUnit.DynePerSquareCentimeter)] + [InlineData("en-US", "ft of elevation", PressureUnit.FootOfElevation)] + [InlineData("en-US", "ft of head", PressureUnit.FootOfHead)] + [InlineData("en-US", "GPa", PressureUnit.Gigapascal)] + [InlineData("en-US", "hPa", PressureUnit.Hectopascal)] + [InlineData("en-US", "inHg", PressureUnit.InchOfMercury)] + [InlineData("en-US", "inH2O", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "inch wc", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "wc", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "kbar", PressureUnit.Kilobar)] + [InlineData("en-US", "kgf/cm²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("en-US", "kgf/m²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("en-US", "kgf/mm²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("en-US", "kN/cm²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("en-US", "kN/m²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("en-US", "kN/mm²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("en-US", "kPa", PressureUnit.Kilopascal)] + [InlineData("en-US", "kipf/ft²", PressureUnit.KilopoundForcePerSquareFoot)] + [InlineData("en-US", "ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("en-US", "kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("en-US", "kipf/mil²", PressureUnit.KilopoundForcePerSquareMil)] + [InlineData("en-US", "Mbar", PressureUnit.Megabar)] + [InlineData("en-US", "MN/m²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("en-US", "MPa", PressureUnit.Megapascal)] + [InlineData("en-US", "m of elevation", PressureUnit.MeterOfElevation)] + [InlineData("en-US", "m of head", PressureUnit.MeterOfHead)] + [InlineData("en-US", "mH₂O", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "mH2O", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "m wc", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "m wg", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "µbar", PressureUnit.Microbar)] + [InlineData("en-US", "µPa", PressureUnit.Micropascal)] + [InlineData("en-US", "mbar", PressureUnit.Millibar)] + [InlineData("en-US", "mmHg", PressureUnit.MillimeterOfMercury)] + [InlineData("en-US", "mmH₂O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mmH2O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mm wc", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mm wg", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mPa", PressureUnit.Millipascal)] + [InlineData("en-US", "N/cm²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("en-US", "N/m²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("en-US", "N/mm²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("en-US", "Pa", PressureUnit.Pascal)] + [InlineData("en-US", "lb/ft²", PressureUnit.PoundForcePerSquareFoot)] + [InlineData("en-US", "psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("en-US", "lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("en-US", "lb/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("en-US", "lbs/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("en-US", "lbm/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("en-US", "lb/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("en-US", "at", PressureUnit.TechnicalAtmosphere)] + [InlineData("en-US", "tf/cm²", PressureUnit.TonneForcePerSquareCentimeter)] + [InlineData("en-US", "tf/m²", PressureUnit.TonneForcePerSquareMeter)] + [InlineData("en-US", "tf/mm²", PressureUnit.TonneForcePerSquareMillimeter)] + [InlineData("en-US", "torr", PressureUnit.Torr)] + [InlineData("ru-RU", "атм", PressureUnit.Atmosphere)] + [InlineData("ru-RU", "бар", PressureUnit.Bar)] + [InlineData("ru-RU", "сбар", PressureUnit.Centibar)] + [InlineData("ru-RU", "даПа", PressureUnit.Decapascal)] + [InlineData("ru-RU", "дбар", PressureUnit.Decibar)] + [InlineData("ru-RU", "ГПа", PressureUnit.Gigapascal)] + [InlineData("ru-RU", "гПа", PressureUnit.Hectopascal)] + [InlineData("ru-RU", "кбар", PressureUnit.Kilobar)] + [InlineData("ru-RU", "кгс/см²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("ru-RU", "кгс/м²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("ru-RU", "кгс/мм²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("ru-RU", "кН/см²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("ru-RU", "кН/м²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("ru-RU", "кН/мм²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("ru-RU", "кПа", PressureUnit.Kilopascal)] + [InlineData("ru-RU", "ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("ru-RU", "kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("ru-RU", "Мбар", PressureUnit.Megabar)] + [InlineData("ru-RU", "МН/м²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("ru-RU", "МПа", PressureUnit.Megapascal)] + [InlineData("ru-RU", "мкбар", PressureUnit.Microbar)] + [InlineData("ru-RU", "мкПа", PressureUnit.Micropascal)] + [InlineData("ru-RU", "мбар", PressureUnit.Millibar)] + [InlineData("ru-RU", "мм рт.ст.", PressureUnit.MillimeterOfMercury)] + [InlineData("ru-RU", "мПа", PressureUnit.Millipascal)] + [InlineData("ru-RU", "Н/см²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("ru-RU", "Н/м²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("ru-RU", "Н/мм²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("ru-RU", "Па", PressureUnit.Pascal)] + [InlineData("ru-RU", "psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("ru-RU", "lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("ru-RU", "ат", PressureUnit.TechnicalAtmosphere)] + [InlineData("ru-RU", "торр", PressureUnit.Torr)] + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, PressureUnit expectedUnit) + { + using var _ = new CultureScope(culture); + PressureUnit parsedUnit = Pressure.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -2038,7 +2218,7 @@ public void ParseUnit(string abbreviation, PressureUnit expectedUnit) [InlineData("ru-RU", "lb/in²", PressureUnit.PoundForcePerSquareInch)] [InlineData("ru-RU", "ат", PressureUnit.TechnicalAtmosphere)] [InlineData("ru-RU", "торр", PressureUnit.Torr)] - public void ParseUnitWithCulture(string culture, string abbreviation, PressureUnit expectedUnit) + public void ParseUnit_WithCulture(string culture, string abbreviation, PressureUnit expectedUnit) { PressureUnit parsedUnit = Pressure.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -2109,9 +2289,188 @@ public void ParseUnitWithCulture(string culture, string abbreviation, PressureUn [InlineData("tf/m²", PressureUnit.TonneForcePerSquareMeter)] [InlineData("tf/mm²", PressureUnit.TonneForcePerSquareMillimeter)] [InlineData("torr", PressureUnit.Torr)] - public void TryParseUnit(string abbreviation, PressureUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, PressureUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Pressure.TryParseUnit(abbreviation, out PressureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("atm", PressureUnit.Atmosphere)] + [InlineData("bar", PressureUnit.Bar)] + [InlineData("cbar", PressureUnit.Centibar)] + [InlineData("cmH₂O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cmH2O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cm wc", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("cm wg", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("daPa", PressureUnit.Decapascal)] + [InlineData("dbar", PressureUnit.Decibar)] + [InlineData("dyn/cm²", PressureUnit.DynePerSquareCentimeter)] + [InlineData("ft of elevation", PressureUnit.FootOfElevation)] + [InlineData("ft of head", PressureUnit.FootOfHead)] + [InlineData("GPa", PressureUnit.Gigapascal)] + [InlineData("hPa", PressureUnit.Hectopascal)] + [InlineData("inHg", PressureUnit.InchOfMercury)] + [InlineData("inH2O", PressureUnit.InchOfWaterColumn)] + [InlineData("inch wc", PressureUnit.InchOfWaterColumn)] + [InlineData("wc", PressureUnit.InchOfWaterColumn)] + [InlineData("kbar", PressureUnit.Kilobar)] + [InlineData("kgf/cm²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("kgf/m²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("kgf/mm²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("kN/cm²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("kN/m²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("kN/mm²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("kPa", PressureUnit.Kilopascal)] + [InlineData("kipf/ft²", PressureUnit.KilopoundForcePerSquareFoot)] + [InlineData("ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("kipf/mil²", PressureUnit.KilopoundForcePerSquareMil)] + [InlineData("Mbar", PressureUnit.Megabar)] + [InlineData("MN/m²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("MPa", PressureUnit.Megapascal)] + [InlineData("m of elevation", PressureUnit.MeterOfElevation)] + [InlineData("m of head", PressureUnit.MeterOfHead)] + [InlineData("mH₂O", PressureUnit.MeterOfWaterColumn)] + [InlineData("mH2O", PressureUnit.MeterOfWaterColumn)] + [InlineData("m wc", PressureUnit.MeterOfWaterColumn)] + [InlineData("m wg", PressureUnit.MeterOfWaterColumn)] + [InlineData("µbar", PressureUnit.Microbar)] + [InlineData("µPa", PressureUnit.Micropascal)] + [InlineData("mbar", PressureUnit.Millibar)] + [InlineData("mmHg", PressureUnit.MillimeterOfMercury)] + [InlineData("mmH₂O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mmH2O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mm wc", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mm wg", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("mPa", PressureUnit.Millipascal)] + [InlineData("N/cm²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("N/m²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("N/mm²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("Pa", PressureUnit.Pascal)] + [InlineData("lb/ft²", PressureUnit.PoundForcePerSquareFoot)] + [InlineData("psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("lb/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("lbs/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("lbm/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("lb/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("at", PressureUnit.TechnicalAtmosphere)] + [InlineData("tf/cm²", PressureUnit.TonneForcePerSquareCentimeter)] + [InlineData("tf/m²", PressureUnit.TonneForcePerSquareMeter)] + [InlineData("tf/mm²", PressureUnit.TonneForcePerSquareMillimeter)] + [InlineData("torr", PressureUnit.Torr)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, PressureUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Pressure.TryParseUnit(abbreviation, out PressureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "atm", PressureUnit.Atmosphere)] + [InlineData("en-US", "bar", PressureUnit.Bar)] + [InlineData("en-US", "cbar", PressureUnit.Centibar)] + [InlineData("en-US", "cmH₂O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cmH2O", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cm wc", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "cm wg", PressureUnit.CentimeterOfWaterColumn)] + [InlineData("en-US", "daPa", PressureUnit.Decapascal)] + [InlineData("en-US", "dbar", PressureUnit.Decibar)] + [InlineData("en-US", "dyn/cm²", PressureUnit.DynePerSquareCentimeter)] + [InlineData("en-US", "ft of elevation", PressureUnit.FootOfElevation)] + [InlineData("en-US", "ft of head", PressureUnit.FootOfHead)] + [InlineData("en-US", "GPa", PressureUnit.Gigapascal)] + [InlineData("en-US", "hPa", PressureUnit.Hectopascal)] + [InlineData("en-US", "inHg", PressureUnit.InchOfMercury)] + [InlineData("en-US", "inH2O", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "inch wc", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "wc", PressureUnit.InchOfWaterColumn)] + [InlineData("en-US", "kbar", PressureUnit.Kilobar)] + [InlineData("en-US", "kgf/cm²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("en-US", "kgf/m²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("en-US", "kgf/mm²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("en-US", "kN/cm²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("en-US", "kN/m²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("en-US", "kN/mm²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("en-US", "kPa", PressureUnit.Kilopascal)] + [InlineData("en-US", "kipf/ft²", PressureUnit.KilopoundForcePerSquareFoot)] + [InlineData("en-US", "ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("en-US", "kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("en-US", "kipf/mil²", PressureUnit.KilopoundForcePerSquareMil)] + [InlineData("en-US", "Mbar", PressureUnit.Megabar)] + [InlineData("en-US", "MN/m²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("en-US", "MPa", PressureUnit.Megapascal)] + [InlineData("en-US", "m of elevation", PressureUnit.MeterOfElevation)] + [InlineData("en-US", "m of head", PressureUnit.MeterOfHead)] + [InlineData("en-US", "mH₂O", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "mH2O", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "m wc", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "m wg", PressureUnit.MeterOfWaterColumn)] + [InlineData("en-US", "µbar", PressureUnit.Microbar)] + [InlineData("en-US", "µPa", PressureUnit.Micropascal)] + [InlineData("en-US", "mbar", PressureUnit.Millibar)] + [InlineData("en-US", "mmHg", PressureUnit.MillimeterOfMercury)] + [InlineData("en-US", "mmH₂O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mmH2O", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mm wc", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mm wg", PressureUnit.MillimeterOfWaterColumn)] + [InlineData("en-US", "mPa", PressureUnit.Millipascal)] + [InlineData("en-US", "N/cm²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("en-US", "N/m²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("en-US", "N/mm²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("en-US", "Pa", PressureUnit.Pascal)] + [InlineData("en-US", "lb/ft²", PressureUnit.PoundForcePerSquareFoot)] + [InlineData("en-US", "psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("en-US", "lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("en-US", "lb/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("en-US", "lbs/mil²", PressureUnit.PoundForcePerSquareMil)] + [InlineData("en-US", "lbm/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("en-US", "lb/(in·s²)", PressureUnit.PoundPerInchSecondSquared)] + [InlineData("en-US", "at", PressureUnit.TechnicalAtmosphere)] + [InlineData("en-US", "tf/cm²", PressureUnit.TonneForcePerSquareCentimeter)] + [InlineData("en-US", "tf/m²", PressureUnit.TonneForcePerSquareMeter)] + [InlineData("en-US", "tf/mm²", PressureUnit.TonneForcePerSquareMillimeter)] + [InlineData("en-US", "torr", PressureUnit.Torr)] + [InlineData("ru-RU", "атм", PressureUnit.Atmosphere)] + [InlineData("ru-RU", "бар", PressureUnit.Bar)] + [InlineData("ru-RU", "сбар", PressureUnit.Centibar)] + [InlineData("ru-RU", "даПа", PressureUnit.Decapascal)] + [InlineData("ru-RU", "дбар", PressureUnit.Decibar)] + [InlineData("ru-RU", "ГПа", PressureUnit.Gigapascal)] + [InlineData("ru-RU", "гПа", PressureUnit.Hectopascal)] + [InlineData("ru-RU", "кбар", PressureUnit.Kilobar)] + [InlineData("ru-RU", "кгс/см²", PressureUnit.KilogramForcePerSquareCentimeter)] + [InlineData("ru-RU", "кгс/м²", PressureUnit.KilogramForcePerSquareMeter)] + [InlineData("ru-RU", "кгс/мм²", PressureUnit.KilogramForcePerSquareMillimeter)] + [InlineData("ru-RU", "кН/см²", PressureUnit.KilonewtonPerSquareCentimeter)] + [InlineData("ru-RU", "кН/м²", PressureUnit.KilonewtonPerSquareMeter)] + [InlineData("ru-RU", "кН/мм²", PressureUnit.KilonewtonPerSquareMillimeter)] + [InlineData("ru-RU", "кПа", PressureUnit.Kilopascal)] + [InlineData("ru-RU", "ksi", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("ru-RU", "kipf/in²", PressureUnit.KilopoundForcePerSquareInch)] + [InlineData("ru-RU", "Мбар", PressureUnit.Megabar)] + [InlineData("ru-RU", "МН/м²", PressureUnit.MeganewtonPerSquareMeter)] + [InlineData("ru-RU", "МПа", PressureUnit.Megapascal)] + [InlineData("ru-RU", "мкбар", PressureUnit.Microbar)] + [InlineData("ru-RU", "мкПа", PressureUnit.Micropascal)] + [InlineData("ru-RU", "мбар", PressureUnit.Millibar)] + [InlineData("ru-RU", "мм рт.ст.", PressureUnit.MillimeterOfMercury)] + [InlineData("ru-RU", "мПа", PressureUnit.Millipascal)] + [InlineData("ru-RU", "Н/см²", PressureUnit.NewtonPerSquareCentimeter)] + [InlineData("ru-RU", "Н/м²", PressureUnit.NewtonPerSquareMeter)] + [InlineData("ru-RU", "Н/мм²", PressureUnit.NewtonPerSquareMillimeter)] + [InlineData("ru-RU", "Па", PressureUnit.Pascal)] + [InlineData("ru-RU", "psi", PressureUnit.PoundForcePerSquareInch)] + [InlineData("ru-RU", "lb/in²", PressureUnit.PoundForcePerSquareInch)] + [InlineData("ru-RU", "ат", PressureUnit.TechnicalAtmosphere)] + [InlineData("ru-RU", "торр", PressureUnit.Torr)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, PressureUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Pressure.TryParseUnit(abbreviation, out PressureUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -2214,7 +2573,7 @@ public void TryParseUnit(string abbreviation, PressureUnit expectedUnit) [InlineData("ru-RU", "lb/in²", PressureUnit.PoundForcePerSquareInch)] [InlineData("ru-RU", "ат", PressureUnit.TechnicalAtmosphere)] [InlineData("ru-RU", "торр", PressureUnit.Torr)] - public void TryParseUnitWithCulture(string culture, string abbreviation, PressureUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, PressureUnit expectedUnit) { Assert.True(Pressure.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out PressureUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs index 6bd1b755d9..5a05bdafe2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationEquivalentDoseTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -374,10 +375,26 @@ public void TryParse() [InlineData("nSv", RadiationEquivalentDoseUnit.Nanosievert)] [InlineData("rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan)] [InlineData("Sv", RadiationEquivalentDoseUnit.Sievert)] - public void ParseUnit(string abbreviation, RadiationEquivalentDoseUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RadiationEquivalentDoseUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - RadiationEquivalentDoseUnit parsedUnit = RadiationEquivalentDose.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + RadiationEquivalentDoseUnit parsedUnit = RadiationEquivalentDose.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("µSv", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("mrem", RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan)] + [InlineData("mSv", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("nSv", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan)] + [InlineData("Sv", RadiationEquivalentDoseUnit.Sievert)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RadiationEquivalentDoseUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + RadiationEquivalentDoseUnit parsedUnit = RadiationEquivalentDose.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -392,7 +409,25 @@ public void ParseUnit(string abbreviation, RadiationEquivalentDoseUnit expectedU [InlineData("ru-RU", "мЗв", RadiationEquivalentDoseUnit.Millisievert)] [InlineData("ru-RU", "нЗв", RadiationEquivalentDoseUnit.Nanosievert)] [InlineData("ru-RU", "Зв", RadiationEquivalentDoseUnit.Sievert)] - public void ParseUnitWithCulture(string culture, string abbreviation, RadiationEquivalentDoseUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, RadiationEquivalentDoseUnit expectedUnit) + { + using var _ = new CultureScope(culture); + RadiationEquivalentDoseUnit parsedUnit = RadiationEquivalentDose.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "µSv", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("en-US", "mrem", RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan)] + [InlineData("en-US", "mSv", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("en-US", "nSv", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("en-US", "rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan)] + [InlineData("en-US", "Sv", RadiationEquivalentDoseUnit.Sievert)] + [InlineData("ru-RU", "мкЗв", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("ru-RU", "мЗв", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("ru-RU", "нЗв", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("ru-RU", "Зв", RadiationEquivalentDoseUnit.Sievert)] + public void ParseUnit_WithCulture(string culture, string abbreviation, RadiationEquivalentDoseUnit expectedUnit) { RadiationEquivalentDoseUnit parsedUnit = RadiationEquivalentDose.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -405,9 +440,43 @@ public void ParseUnitWithCulture(string culture, string abbreviation, RadiationE [InlineData("nSv", RadiationEquivalentDoseUnit.Nanosievert)] [InlineData("rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan)] [InlineData("Sv", RadiationEquivalentDoseUnit.Sievert)] - public void TryParseUnit(string abbreviation, RadiationEquivalentDoseUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RadiationEquivalentDoseUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(RadiationEquivalentDose.TryParseUnit(abbreviation, out RadiationEquivalentDoseUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("µSv", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("mrem", RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan)] + [InlineData("mSv", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("nSv", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan)] + [InlineData("Sv", RadiationEquivalentDoseUnit.Sievert)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RadiationEquivalentDoseUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(RadiationEquivalentDose.TryParseUnit(abbreviation, out RadiationEquivalentDoseUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "µSv", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("en-US", "mrem", RadiationEquivalentDoseUnit.MilliroentgenEquivalentMan)] + [InlineData("en-US", "mSv", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("en-US", "nSv", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("en-US", "rem", RadiationEquivalentDoseUnit.RoentgenEquivalentMan)] + [InlineData("en-US", "Sv", RadiationEquivalentDoseUnit.Sievert)] + [InlineData("ru-RU", "мкЗв", RadiationEquivalentDoseUnit.Microsievert)] + [InlineData("ru-RU", "мЗв", RadiationEquivalentDoseUnit.Millisievert)] + [InlineData("ru-RU", "нЗв", RadiationEquivalentDoseUnit.Nanosievert)] + [InlineData("ru-RU", "Зв", RadiationEquivalentDoseUnit.Sievert)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, RadiationEquivalentDoseUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(RadiationEquivalentDose.TryParseUnit(abbreviation, out RadiationEquivalentDoseUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -423,7 +492,7 @@ public void TryParseUnit(string abbreviation, RadiationEquivalentDoseUnit expect [InlineData("ru-RU", "мЗв", RadiationEquivalentDoseUnit.Millisievert)] [InlineData("ru-RU", "нЗв", RadiationEquivalentDoseUnit.Nanosievert)] [InlineData("ru-RU", "Зв", RadiationEquivalentDoseUnit.Sievert)] - public void TryParseUnitWithCulture(string culture, string abbreviation, RadiationEquivalentDoseUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, RadiationEquivalentDoseUnit expectedUnit) { Assert.True(RadiationEquivalentDose.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RadiationEquivalentDoseUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs index a0d36bdc80..db6237f64c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadiationExposureTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -370,10 +371,28 @@ public void TryParse() [InlineData("nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] [InlineData("pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] [InlineData("R", RadiationExposureUnit.Roentgen)] - public void ParseUnit(string abbreviation, RadiationExposureUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RadiationExposureUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - RadiationExposureUnit parsedUnit = RadiationExposure.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + RadiationExposureUnit parsedUnit = RadiationExposure.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("C/kg", RadiationExposureUnit.CoulombPerKilogram)] + [InlineData("µC/kg", RadiationExposureUnit.MicrocoulombPerKilogram)] + [InlineData("µR", RadiationExposureUnit.Microroentgen)] + [InlineData("mC/kg", RadiationExposureUnit.MillicoulombPerKilogram)] + [InlineData("mR", RadiationExposureUnit.Milliroentgen)] + [InlineData("nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] + [InlineData("pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] + [InlineData("R", RadiationExposureUnit.Roentgen)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RadiationExposureUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + RadiationExposureUnit parsedUnit = RadiationExposure.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -386,7 +405,23 @@ public void ParseUnit(string abbreviation, RadiationExposureUnit expectedUnit) [InlineData("en-US", "nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] [InlineData("en-US", "pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] [InlineData("en-US", "R", RadiationExposureUnit.Roentgen)] - public void ParseUnitWithCulture(string culture, string abbreviation, RadiationExposureUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, RadiationExposureUnit expectedUnit) + { + using var _ = new CultureScope(culture); + RadiationExposureUnit parsedUnit = RadiationExposure.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "C/kg", RadiationExposureUnit.CoulombPerKilogram)] + [InlineData("en-US", "µC/kg", RadiationExposureUnit.MicrocoulombPerKilogram)] + [InlineData("en-US", "µR", RadiationExposureUnit.Microroentgen)] + [InlineData("en-US", "mC/kg", RadiationExposureUnit.MillicoulombPerKilogram)] + [InlineData("en-US", "mR", RadiationExposureUnit.Milliroentgen)] + [InlineData("en-US", "nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] + [InlineData("en-US", "pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] + [InlineData("en-US", "R", RadiationExposureUnit.Roentgen)] + public void ParseUnit_WithCulture(string culture, string abbreviation, RadiationExposureUnit expectedUnit) { RadiationExposureUnit parsedUnit = RadiationExposure.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -401,9 +436,43 @@ public void ParseUnitWithCulture(string culture, string abbreviation, RadiationE [InlineData("nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] [InlineData("pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] [InlineData("R", RadiationExposureUnit.Roentgen)] - public void TryParseUnit(string abbreviation, RadiationExposureUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RadiationExposureUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(RadiationExposure.TryParseUnit(abbreviation, out RadiationExposureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("C/kg", RadiationExposureUnit.CoulombPerKilogram)] + [InlineData("µC/kg", RadiationExposureUnit.MicrocoulombPerKilogram)] + [InlineData("µR", RadiationExposureUnit.Microroentgen)] + [InlineData("mC/kg", RadiationExposureUnit.MillicoulombPerKilogram)] + [InlineData("mR", RadiationExposureUnit.Milliroentgen)] + [InlineData("nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] + [InlineData("pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] + [InlineData("R", RadiationExposureUnit.Roentgen)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RadiationExposureUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(RadiationExposure.TryParseUnit(abbreviation, out RadiationExposureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "C/kg", RadiationExposureUnit.CoulombPerKilogram)] + [InlineData("en-US", "µC/kg", RadiationExposureUnit.MicrocoulombPerKilogram)] + [InlineData("en-US", "µR", RadiationExposureUnit.Microroentgen)] + [InlineData("en-US", "mC/kg", RadiationExposureUnit.MillicoulombPerKilogram)] + [InlineData("en-US", "mR", RadiationExposureUnit.Milliroentgen)] + [InlineData("en-US", "nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] + [InlineData("en-US", "pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] + [InlineData("en-US", "R", RadiationExposureUnit.Roentgen)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, RadiationExposureUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(RadiationExposure.TryParseUnit(abbreviation, out RadiationExposureUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -417,7 +486,7 @@ public void TryParseUnit(string abbreviation, RadiationExposureUnit expectedUnit [InlineData("en-US", "nC/kg", RadiationExposureUnit.NanocoulombPerKilogram)] [InlineData("en-US", "pC/kg", RadiationExposureUnit.PicocoulombPerKilogram)] [InlineData("en-US", "R", RadiationExposureUnit.Roentgen)] - public void TryParseUnitWithCulture(string culture, string abbreviation, RadiationExposureUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, RadiationExposureUnit expectedUnit) { Assert.True(RadiationExposure.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RadiationExposureUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs index ddb230ffc5..cfc79df5ba 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RadioactivityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1155,10 +1156,115 @@ public void TryParse() [InlineData("TBq", RadioactivityUnit.Terabecquerel)] [InlineData("TCi", RadioactivityUnit.Teracurie)] [InlineData("TRd", RadioactivityUnit.Terarutherford)] - public void ParseUnit(string abbreviation, RadioactivityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RadioactivityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - RadioactivityUnit parsedUnit = Radioactivity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + RadioactivityUnit parsedUnit = Radioactivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Bq", RadioactivityUnit.Becquerel)] + [InlineData("Ci", RadioactivityUnit.Curie)] + [InlineData("EBq", RadioactivityUnit.Exabecquerel)] + [InlineData("GBq", RadioactivityUnit.Gigabecquerel)] + [InlineData("GCi", RadioactivityUnit.Gigacurie)] + [InlineData("GRd", RadioactivityUnit.Gigarutherford)] + [InlineData("kBq", RadioactivityUnit.Kilobecquerel)] + [InlineData("kCi", RadioactivityUnit.Kilocurie)] + [InlineData("kRd", RadioactivityUnit.Kilorutherford)] + [InlineData("MBq", RadioactivityUnit.Megabecquerel)] + [InlineData("MCi", RadioactivityUnit.Megacurie)] + [InlineData("MRd", RadioactivityUnit.Megarutherford)] + [InlineData("µBq", RadioactivityUnit.Microbecquerel)] + [InlineData("µCi", RadioactivityUnit.Microcurie)] + [InlineData("µRd", RadioactivityUnit.Microrutherford)] + [InlineData("mBq", RadioactivityUnit.Millibecquerel)] + [InlineData("mCi", RadioactivityUnit.Millicurie)] + [InlineData("mRd", RadioactivityUnit.Millirutherford)] + [InlineData("nBq", RadioactivityUnit.Nanobecquerel)] + [InlineData("nCi", RadioactivityUnit.Nanocurie)] + [InlineData("nRd", RadioactivityUnit.Nanorutherford)] + [InlineData("PBq", RadioactivityUnit.Petabecquerel)] + [InlineData("pBq", RadioactivityUnit.Picobecquerel)] + [InlineData("pCi", RadioactivityUnit.Picocurie)] + [InlineData("pRd", RadioactivityUnit.Picorutherford)] + [InlineData("Rd", RadioactivityUnit.Rutherford)] + [InlineData("TBq", RadioactivityUnit.Terabecquerel)] + [InlineData("TCi", RadioactivityUnit.Teracurie)] + [InlineData("TRd", RadioactivityUnit.Terarutherford)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RadioactivityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + RadioactivityUnit parsedUnit = Radioactivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Bq", RadioactivityUnit.Becquerel)] + [InlineData("en-US", "Ci", RadioactivityUnit.Curie)] + [InlineData("en-US", "EBq", RadioactivityUnit.Exabecquerel)] + [InlineData("en-US", "GBq", RadioactivityUnit.Gigabecquerel)] + [InlineData("en-US", "GCi", RadioactivityUnit.Gigacurie)] + [InlineData("en-US", "GRd", RadioactivityUnit.Gigarutherford)] + [InlineData("en-US", "kBq", RadioactivityUnit.Kilobecquerel)] + [InlineData("en-US", "kCi", RadioactivityUnit.Kilocurie)] + [InlineData("en-US", "kRd", RadioactivityUnit.Kilorutherford)] + [InlineData("en-US", "MBq", RadioactivityUnit.Megabecquerel)] + [InlineData("en-US", "MCi", RadioactivityUnit.Megacurie)] + [InlineData("en-US", "MRd", RadioactivityUnit.Megarutherford)] + [InlineData("en-US", "µBq", RadioactivityUnit.Microbecquerel)] + [InlineData("en-US", "µCi", RadioactivityUnit.Microcurie)] + [InlineData("en-US", "µRd", RadioactivityUnit.Microrutherford)] + [InlineData("en-US", "mBq", RadioactivityUnit.Millibecquerel)] + [InlineData("en-US", "mCi", RadioactivityUnit.Millicurie)] + [InlineData("en-US", "mRd", RadioactivityUnit.Millirutherford)] + [InlineData("en-US", "nBq", RadioactivityUnit.Nanobecquerel)] + [InlineData("en-US", "nCi", RadioactivityUnit.Nanocurie)] + [InlineData("en-US", "nRd", RadioactivityUnit.Nanorutherford)] + [InlineData("en-US", "PBq", RadioactivityUnit.Petabecquerel)] + [InlineData("en-US", "pBq", RadioactivityUnit.Picobecquerel)] + [InlineData("en-US", "pCi", RadioactivityUnit.Picocurie)] + [InlineData("en-US", "pRd", RadioactivityUnit.Picorutherford)] + [InlineData("en-US", "Rd", RadioactivityUnit.Rutherford)] + [InlineData("en-US", "TBq", RadioactivityUnit.Terabecquerel)] + [InlineData("en-US", "TCi", RadioactivityUnit.Teracurie)] + [InlineData("en-US", "TRd", RadioactivityUnit.Terarutherford)] + [InlineData("ru-RU", "Бк", RadioactivityUnit.Becquerel)] + [InlineData("ru-RU", "Ки", RadioactivityUnit.Curie)] + [InlineData("ru-RU", "ЭБк", RadioactivityUnit.Exabecquerel)] + [InlineData("ru-RU", "ГБк", RadioactivityUnit.Gigabecquerel)] + [InlineData("ru-RU", "ГКи", RadioactivityUnit.Gigacurie)] + [InlineData("ru-RU", "ГРд", RadioactivityUnit.Gigarutherford)] + [InlineData("ru-RU", "кБк", RadioactivityUnit.Kilobecquerel)] + [InlineData("ru-RU", "кКи", RadioactivityUnit.Kilocurie)] + [InlineData("ru-RU", "кРд", RadioactivityUnit.Kilorutherford)] + [InlineData("ru-RU", "МБк", RadioactivityUnit.Megabecquerel)] + [InlineData("ru-RU", "МКи", RadioactivityUnit.Megacurie)] + [InlineData("ru-RU", "МРд", RadioactivityUnit.Megarutherford)] + [InlineData("ru-RU", "мкБк", RadioactivityUnit.Microbecquerel)] + [InlineData("ru-RU", "мкКи", RadioactivityUnit.Microcurie)] + [InlineData("ru-RU", "мкРд", RadioactivityUnit.Microrutherford)] + [InlineData("ru-RU", "мБк", RadioactivityUnit.Millibecquerel)] + [InlineData("ru-RU", "мКи", RadioactivityUnit.Millicurie)] + [InlineData("ru-RU", "мРд", RadioactivityUnit.Millirutherford)] + [InlineData("ru-RU", "нБк", RadioactivityUnit.Nanobecquerel)] + [InlineData("ru-RU", "нКи", RadioactivityUnit.Nanocurie)] + [InlineData("ru-RU", "нРд", RadioactivityUnit.Nanorutherford)] + [InlineData("ru-RU", "ПБк", RadioactivityUnit.Petabecquerel)] + [InlineData("ru-RU", "пБк", RadioactivityUnit.Picobecquerel)] + [InlineData("ru-RU", "пКи", RadioactivityUnit.Picocurie)] + [InlineData("ru-RU", "пРд", RadioactivityUnit.Picorutherford)] + [InlineData("ru-RU", "Рд", RadioactivityUnit.Rutherford)] + [InlineData("ru-RU", "ТБк", RadioactivityUnit.Terabecquerel)] + [InlineData("ru-RU", "ТКи", RadioactivityUnit.Teracurie)] + [InlineData("ru-RU", "ТРд", RadioactivityUnit.Terarutherford)] + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, RadioactivityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + RadioactivityUnit parsedUnit = Radioactivity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1221,7 +1327,7 @@ public void ParseUnit(string abbreviation, RadioactivityUnit expectedUnit) [InlineData("ru-RU", "ТБк", RadioactivityUnit.Terabecquerel)] [InlineData("ru-RU", "ТКи", RadioactivityUnit.Teracurie)] [InlineData("ru-RU", "ТРд", RadioactivityUnit.Terarutherford)] - public void ParseUnitWithCulture(string culture, string abbreviation, RadioactivityUnit expectedUnit) + public void ParseUnit_WithCulture(string culture, string abbreviation, RadioactivityUnit expectedUnit) { RadioactivityUnit parsedUnit = Radioactivity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1257,9 +1363,114 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Radioactiv [InlineData("TBq", RadioactivityUnit.Terabecquerel)] [InlineData("TCi", RadioactivityUnit.Teracurie)] [InlineData("TRd", RadioactivityUnit.Terarutherford)] - public void TryParseUnit(string abbreviation, RadioactivityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RadioactivityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Radioactivity.TryParseUnit(abbreviation, out RadioactivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Bq", RadioactivityUnit.Becquerel)] + [InlineData("Ci", RadioactivityUnit.Curie)] + [InlineData("EBq", RadioactivityUnit.Exabecquerel)] + [InlineData("GBq", RadioactivityUnit.Gigabecquerel)] + [InlineData("GCi", RadioactivityUnit.Gigacurie)] + [InlineData("GRd", RadioactivityUnit.Gigarutherford)] + [InlineData("kBq", RadioactivityUnit.Kilobecquerel)] + [InlineData("kCi", RadioactivityUnit.Kilocurie)] + [InlineData("kRd", RadioactivityUnit.Kilorutherford)] + [InlineData("MBq", RadioactivityUnit.Megabecquerel)] + [InlineData("MCi", RadioactivityUnit.Megacurie)] + [InlineData("MRd", RadioactivityUnit.Megarutherford)] + [InlineData("µBq", RadioactivityUnit.Microbecquerel)] + [InlineData("µCi", RadioactivityUnit.Microcurie)] + [InlineData("µRd", RadioactivityUnit.Microrutherford)] + [InlineData("mBq", RadioactivityUnit.Millibecquerel)] + [InlineData("mCi", RadioactivityUnit.Millicurie)] + [InlineData("mRd", RadioactivityUnit.Millirutherford)] + [InlineData("nBq", RadioactivityUnit.Nanobecquerel)] + [InlineData("nCi", RadioactivityUnit.Nanocurie)] + [InlineData("nRd", RadioactivityUnit.Nanorutherford)] + [InlineData("PBq", RadioactivityUnit.Petabecquerel)] + [InlineData("pBq", RadioactivityUnit.Picobecquerel)] + [InlineData("pCi", RadioactivityUnit.Picocurie)] + [InlineData("pRd", RadioactivityUnit.Picorutherford)] + [InlineData("Rd", RadioactivityUnit.Rutherford)] + [InlineData("TBq", RadioactivityUnit.Terabecquerel)] + [InlineData("TCi", RadioactivityUnit.Teracurie)] + [InlineData("TRd", RadioactivityUnit.Terarutherford)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RadioactivityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Radioactivity.TryParseUnit(abbreviation, out RadioactivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Bq", RadioactivityUnit.Becquerel)] + [InlineData("en-US", "Ci", RadioactivityUnit.Curie)] + [InlineData("en-US", "EBq", RadioactivityUnit.Exabecquerel)] + [InlineData("en-US", "GBq", RadioactivityUnit.Gigabecquerel)] + [InlineData("en-US", "GCi", RadioactivityUnit.Gigacurie)] + [InlineData("en-US", "GRd", RadioactivityUnit.Gigarutherford)] + [InlineData("en-US", "kBq", RadioactivityUnit.Kilobecquerel)] + [InlineData("en-US", "kCi", RadioactivityUnit.Kilocurie)] + [InlineData("en-US", "kRd", RadioactivityUnit.Kilorutherford)] + [InlineData("en-US", "MBq", RadioactivityUnit.Megabecquerel)] + [InlineData("en-US", "MCi", RadioactivityUnit.Megacurie)] + [InlineData("en-US", "MRd", RadioactivityUnit.Megarutherford)] + [InlineData("en-US", "µBq", RadioactivityUnit.Microbecquerel)] + [InlineData("en-US", "µCi", RadioactivityUnit.Microcurie)] + [InlineData("en-US", "µRd", RadioactivityUnit.Microrutherford)] + [InlineData("en-US", "mBq", RadioactivityUnit.Millibecquerel)] + [InlineData("en-US", "mCi", RadioactivityUnit.Millicurie)] + [InlineData("en-US", "mRd", RadioactivityUnit.Millirutherford)] + [InlineData("en-US", "nBq", RadioactivityUnit.Nanobecquerel)] + [InlineData("en-US", "nCi", RadioactivityUnit.Nanocurie)] + [InlineData("en-US", "nRd", RadioactivityUnit.Nanorutherford)] + [InlineData("en-US", "PBq", RadioactivityUnit.Petabecquerel)] + [InlineData("en-US", "pBq", RadioactivityUnit.Picobecquerel)] + [InlineData("en-US", "pCi", RadioactivityUnit.Picocurie)] + [InlineData("en-US", "pRd", RadioactivityUnit.Picorutherford)] + [InlineData("en-US", "Rd", RadioactivityUnit.Rutherford)] + [InlineData("en-US", "TBq", RadioactivityUnit.Terabecquerel)] + [InlineData("en-US", "TCi", RadioactivityUnit.Teracurie)] + [InlineData("en-US", "TRd", RadioactivityUnit.Terarutherford)] + [InlineData("ru-RU", "Бк", RadioactivityUnit.Becquerel)] + [InlineData("ru-RU", "Ки", RadioactivityUnit.Curie)] + [InlineData("ru-RU", "ЭБк", RadioactivityUnit.Exabecquerel)] + [InlineData("ru-RU", "ГБк", RadioactivityUnit.Gigabecquerel)] + [InlineData("ru-RU", "ГКи", RadioactivityUnit.Gigacurie)] + [InlineData("ru-RU", "ГРд", RadioactivityUnit.Gigarutherford)] + [InlineData("ru-RU", "кБк", RadioactivityUnit.Kilobecquerel)] + [InlineData("ru-RU", "кКи", RadioactivityUnit.Kilocurie)] + [InlineData("ru-RU", "кРд", RadioactivityUnit.Kilorutherford)] + [InlineData("ru-RU", "МБк", RadioactivityUnit.Megabecquerel)] + [InlineData("ru-RU", "МКи", RadioactivityUnit.Megacurie)] + [InlineData("ru-RU", "МРд", RadioactivityUnit.Megarutherford)] + [InlineData("ru-RU", "мкБк", RadioactivityUnit.Microbecquerel)] + [InlineData("ru-RU", "мкКи", RadioactivityUnit.Microcurie)] + [InlineData("ru-RU", "мкРд", RadioactivityUnit.Microrutherford)] + [InlineData("ru-RU", "мБк", RadioactivityUnit.Millibecquerel)] + [InlineData("ru-RU", "мКи", RadioactivityUnit.Millicurie)] + [InlineData("ru-RU", "мРд", RadioactivityUnit.Millirutherford)] + [InlineData("ru-RU", "нБк", RadioactivityUnit.Nanobecquerel)] + [InlineData("ru-RU", "нКи", RadioactivityUnit.Nanocurie)] + [InlineData("ru-RU", "нРд", RadioactivityUnit.Nanorutherford)] + [InlineData("ru-RU", "ПБк", RadioactivityUnit.Petabecquerel)] + [InlineData("ru-RU", "пБк", RadioactivityUnit.Picobecquerel)] + [InlineData("ru-RU", "пКи", RadioactivityUnit.Picocurie)] + [InlineData("ru-RU", "пРд", RadioactivityUnit.Picorutherford)] + [InlineData("ru-RU", "Рд", RadioactivityUnit.Rutherford)] + [InlineData("ru-RU", "ТБк", RadioactivityUnit.Terabecquerel)] + [InlineData("ru-RU", "ТКи", RadioactivityUnit.Teracurie)] + [InlineData("ru-RU", "ТРд", RadioactivityUnit.Terarutherford)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, RadioactivityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Radioactivity.TryParseUnit(abbreviation, out RadioactivityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1323,7 +1534,7 @@ public void TryParseUnit(string abbreviation, RadioactivityUnit expectedUnit) [InlineData("ru-RU", "ТБк", RadioactivityUnit.Terabecquerel)] [InlineData("ru-RU", "ТКи", RadioactivityUnit.Teracurie)] [InlineData("ru-RU", "ТРд", RadioactivityUnit.Terarutherford)] - public void TryParseUnitWithCulture(string culture, string abbreviation, RadioactivityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, RadioactivityUnit expectedUnit) { Assert.True(Radioactivity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RadioactivityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs index 8d19b404f6..b71a34fc05 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioChangeRateTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -226,17 +227,39 @@ public void TryParse() [Theory] [InlineData("/s", RatioChangeRateUnit.DecimalFractionPerSecond)] [InlineData("%/s", RatioChangeRateUnit.PercentPerSecond)] - public void ParseUnit(string abbreviation, RatioChangeRateUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RatioChangeRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - RatioChangeRateUnit parsedUnit = RatioChangeRate.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + RatioChangeRateUnit parsedUnit = RatioChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("/s", RatioChangeRateUnit.DecimalFractionPerSecond)] + [InlineData("%/s", RatioChangeRateUnit.PercentPerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RatioChangeRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + RatioChangeRateUnit parsedUnit = RatioChangeRate.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "/s", RatioChangeRateUnit.DecimalFractionPerSecond)] [InlineData("en-US", "%/s", RatioChangeRateUnit.PercentPerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, RatioChangeRateUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, RatioChangeRateUnit expectedUnit) + { + using var _ = new CultureScope(culture); + RatioChangeRateUnit parsedUnit = RatioChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "/s", RatioChangeRateUnit.DecimalFractionPerSecond)] + [InlineData("en-US", "%/s", RatioChangeRateUnit.PercentPerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, RatioChangeRateUnit expectedUnit) { RatioChangeRateUnit parsedUnit = RatioChangeRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -245,9 +268,31 @@ public void ParseUnitWithCulture(string culture, string abbreviation, RatioChang [Theory] [InlineData("/s", RatioChangeRateUnit.DecimalFractionPerSecond)] [InlineData("%/s", RatioChangeRateUnit.PercentPerSecond)] - public void TryParseUnit(string abbreviation, RatioChangeRateUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RatioChangeRateUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(RatioChangeRate.TryParseUnit(abbreviation, out RatioChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("/s", RatioChangeRateUnit.DecimalFractionPerSecond)] + [InlineData("%/s", RatioChangeRateUnit.PercentPerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RatioChangeRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(RatioChangeRate.TryParseUnit(abbreviation, out RatioChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "/s", RatioChangeRateUnit.DecimalFractionPerSecond)] + [InlineData("en-US", "%/s", RatioChangeRateUnit.PercentPerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, RatioChangeRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(RatioChangeRate.TryParseUnit(abbreviation, out RatioChangeRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -255,7 +300,7 @@ public void TryParseUnit(string abbreviation, RatioChangeRateUnit expectedUnit) [Theory] [InlineData("en-US", "/s", RatioChangeRateUnit.DecimalFractionPerSecond)] [InlineData("en-US", "%/s", RatioChangeRateUnit.PercentPerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, RatioChangeRateUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, RatioChangeRateUnit expectedUnit) { Assert.True(RatioChangeRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RatioChangeRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs index 805a3cb5d0..fc5009167f 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RatioTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -322,10 +323,26 @@ public void TryParse() [InlineData("‰", RatioUnit.PartPerThousand)] [InlineData("ppt", RatioUnit.PartPerTrillion)] [InlineData("%", RatioUnit.Percent)] - public void ParseUnit(string abbreviation, RatioUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RatioUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - RatioUnit parsedUnit = Ratio.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + RatioUnit parsedUnit = Ratio.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("", RatioUnit.DecimalFraction)] + [InlineData("ppb", RatioUnit.PartPerBillion)] + [InlineData("ppm", RatioUnit.PartPerMillion)] + [InlineData("‰", RatioUnit.PartPerThousand)] + [InlineData("ppt", RatioUnit.PartPerTrillion)] + [InlineData("%", RatioUnit.Percent)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RatioUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + RatioUnit parsedUnit = Ratio.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -336,7 +353,21 @@ public void ParseUnit(string abbreviation, RatioUnit expectedUnit) [InlineData("en-US", "‰", RatioUnit.PartPerThousand)] [InlineData("en-US", "ppt", RatioUnit.PartPerTrillion)] [InlineData("en-US", "%", RatioUnit.Percent)] - public void ParseUnitWithCulture(string culture, string abbreviation, RatioUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, RatioUnit expectedUnit) + { + using var _ = new CultureScope(culture); + RatioUnit parsedUnit = Ratio.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "", RatioUnit.DecimalFraction)] + [InlineData("en-US", "ppb", RatioUnit.PartPerBillion)] + [InlineData("en-US", "ppm", RatioUnit.PartPerMillion)] + [InlineData("en-US", "‰", RatioUnit.PartPerThousand)] + [InlineData("en-US", "ppt", RatioUnit.PartPerTrillion)] + [InlineData("en-US", "%", RatioUnit.Percent)] + public void ParseUnit_WithCulture(string culture, string abbreviation, RatioUnit expectedUnit) { RatioUnit parsedUnit = Ratio.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -349,9 +380,39 @@ public void ParseUnitWithCulture(string culture, string abbreviation, RatioUnit [InlineData("‰", RatioUnit.PartPerThousand)] [InlineData("ppt", RatioUnit.PartPerTrillion)] [InlineData("%", RatioUnit.Percent)] - public void TryParseUnit(string abbreviation, RatioUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RatioUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Ratio.TryParseUnit(abbreviation, out RatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("", RatioUnit.DecimalFraction)] + [InlineData("ppb", RatioUnit.PartPerBillion)] + [InlineData("ppm", RatioUnit.PartPerMillion)] + [InlineData("‰", RatioUnit.PartPerThousand)] + [InlineData("ppt", RatioUnit.PartPerTrillion)] + [InlineData("%", RatioUnit.Percent)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RatioUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Ratio.TryParseUnit(abbreviation, out RatioUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "", RatioUnit.DecimalFraction)] + [InlineData("en-US", "ppb", RatioUnit.PartPerBillion)] + [InlineData("en-US", "ppm", RatioUnit.PartPerMillion)] + [InlineData("en-US", "‰", RatioUnit.PartPerThousand)] + [InlineData("en-US", "ppt", RatioUnit.PartPerTrillion)] + [InlineData("en-US", "%", RatioUnit.Percent)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, RatioUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Ratio.TryParseUnit(abbreviation, out RatioUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -363,7 +424,7 @@ public void TryParseUnit(string abbreviation, RatioUnit expectedUnit) [InlineData("en-US", "‰", RatioUnit.PartPerThousand)] [InlineData("en-US", "ppt", RatioUnit.PartPerTrillion)] [InlineData("en-US", "%", RatioUnit.Percent)] - public void TryParseUnitWithCulture(string culture, string abbreviation, RatioUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, RatioUnit expectedUnit) { Assert.True(Ratio.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RatioUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs index d1b37c0393..4b64986062 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactiveEnergyTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -250,10 +251,23 @@ public void TryParse() [InlineData("kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] [InlineData("Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] [InlineData("varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void ParseUnit(string abbreviation, ReactiveEnergyUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReactiveEnergyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ReactiveEnergyUnit parsedUnit = ReactiveEnergy.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ReactiveEnergyUnit parsedUnit = ReactiveEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] + [InlineData("Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] + [InlineData("varh", ReactiveEnergyUnit.VoltampereReactiveHour)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReactiveEnergyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ReactiveEnergyUnit parsedUnit = ReactiveEnergy.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -261,7 +275,18 @@ public void ParseUnit(string abbreviation, ReactiveEnergyUnit expectedUnit) [InlineData("en-US", "kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] [InlineData("en-US", "Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] [InlineData("en-US", "varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void ParseUnitWithCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ReactiveEnergyUnit parsedUnit = ReactiveEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] + [InlineData("en-US", "Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] + [InlineData("en-US", "varh", ReactiveEnergyUnit.VoltampereReactiveHour)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) { ReactiveEnergyUnit parsedUnit = ReactiveEnergy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -271,9 +296,33 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ReactiveEn [InlineData("kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] [InlineData("Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] [InlineData("varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void TryParseUnit(string abbreviation, ReactiveEnergyUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReactiveEnergyUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ReactiveEnergy.TryParseUnit(abbreviation, out ReactiveEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] + [InlineData("Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] + [InlineData("varh", ReactiveEnergyUnit.VoltampereReactiveHour)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReactiveEnergyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ReactiveEnergy.TryParseUnit(abbreviation, out ReactiveEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] + [InlineData("en-US", "Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] + [InlineData("en-US", "varh", ReactiveEnergyUnit.VoltampereReactiveHour)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ReactiveEnergy.TryParseUnit(abbreviation, out ReactiveEnergyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -282,7 +331,7 @@ public void TryParseUnit(string abbreviation, ReactiveEnergyUnit expectedUnit) [InlineData("en-US", "kvarh", ReactiveEnergyUnit.KilovoltampereReactiveHour)] [InlineData("en-US", "Mvarh", ReactiveEnergyUnit.MegavoltampereReactiveHour)] [InlineData("en-US", "varh", ReactiveEnergyUnit.VoltampereReactiveHour)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ReactiveEnergyUnit expectedUnit) { Assert.True(ReactiveEnergy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ReactiveEnergyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs index 667e941bc1..2187322540 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReactivePowerTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -274,10 +275,24 @@ public void TryParse() [InlineData("kvar", ReactivePowerUnit.KilovoltampereReactive)] [InlineData("Mvar", ReactivePowerUnit.MegavoltampereReactive)] [InlineData("var", ReactivePowerUnit.VoltampereReactive)] - public void ParseUnit(string abbreviation, ReactivePowerUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReactivePowerUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ReactivePowerUnit parsedUnit = ReactivePower.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ReactivePowerUnit parsedUnit = ReactivePower.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Gvar", ReactivePowerUnit.GigavoltampereReactive)] + [InlineData("kvar", ReactivePowerUnit.KilovoltampereReactive)] + [InlineData("Mvar", ReactivePowerUnit.MegavoltampereReactive)] + [InlineData("var", ReactivePowerUnit.VoltampereReactive)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReactivePowerUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ReactivePowerUnit parsedUnit = ReactivePower.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -286,7 +301,19 @@ public void ParseUnit(string abbreviation, ReactivePowerUnit expectedUnit) [InlineData("en-US", "kvar", ReactivePowerUnit.KilovoltampereReactive)] [InlineData("en-US", "Mvar", ReactivePowerUnit.MegavoltampereReactive)] [InlineData("en-US", "var", ReactivePowerUnit.VoltampereReactive)] - public void ParseUnitWithCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ReactivePowerUnit parsedUnit = ReactivePower.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Gvar", ReactivePowerUnit.GigavoltampereReactive)] + [InlineData("en-US", "kvar", ReactivePowerUnit.KilovoltampereReactive)] + [InlineData("en-US", "Mvar", ReactivePowerUnit.MegavoltampereReactive)] + [InlineData("en-US", "var", ReactivePowerUnit.VoltampereReactive)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) { ReactivePowerUnit parsedUnit = ReactivePower.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -297,9 +324,35 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ReactivePo [InlineData("kvar", ReactivePowerUnit.KilovoltampereReactive)] [InlineData("Mvar", ReactivePowerUnit.MegavoltampereReactive)] [InlineData("var", ReactivePowerUnit.VoltampereReactive)] - public void TryParseUnit(string abbreviation, ReactivePowerUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReactivePowerUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ReactivePower.TryParseUnit(abbreviation, out ReactivePowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Gvar", ReactivePowerUnit.GigavoltampereReactive)] + [InlineData("kvar", ReactivePowerUnit.KilovoltampereReactive)] + [InlineData("Mvar", ReactivePowerUnit.MegavoltampereReactive)] + [InlineData("var", ReactivePowerUnit.VoltampereReactive)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReactivePowerUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ReactivePower.TryParseUnit(abbreviation, out ReactivePowerUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Gvar", ReactivePowerUnit.GigavoltampereReactive)] + [InlineData("en-US", "kvar", ReactivePowerUnit.KilovoltampereReactive)] + [InlineData("en-US", "Mvar", ReactivePowerUnit.MegavoltampereReactive)] + [InlineData("en-US", "var", ReactivePowerUnit.VoltampereReactive)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ReactivePower.TryParseUnit(abbreviation, out ReactivePowerUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -309,7 +362,7 @@ public void TryParseUnit(string abbreviation, ReactivePowerUnit expectedUnit) [InlineData("en-US", "kvar", ReactivePowerUnit.KilovoltampereReactive)] [InlineData("en-US", "Mvar", ReactivePowerUnit.MegavoltampereReactive)] [InlineData("en-US", "var", ReactivePowerUnit.VoltampereReactive)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ReactivePowerUnit expectedUnit) { Assert.True(ReactivePower.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ReactivePowerUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs index 40540610c6..dd38cf8f16 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalAreaTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -442,10 +443,31 @@ public void TryParse() [InlineData("mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] [InlineData("yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] [InlineData("ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] - public void ParseUnit(string abbreviation, ReciprocalAreaUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReciprocalAreaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ReciprocalAreaUnit parsedUnit = ReciprocalArea.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ReciprocalAreaUnit parsedUnit = ReciprocalArea.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm⁻²", ReciprocalAreaUnit.InverseSquareCentimeter)] + [InlineData("dm⁻²", ReciprocalAreaUnit.InverseSquareDecimeter)] + [InlineData("ft⁻²", ReciprocalAreaUnit.InverseSquareFoot)] + [InlineData("in⁻²", ReciprocalAreaUnit.InverseSquareInch)] + [InlineData("km⁻²", ReciprocalAreaUnit.InverseSquareKilometer)] + [InlineData("m⁻²", ReciprocalAreaUnit.InverseSquareMeter)] + [InlineData("µm⁻²", ReciprocalAreaUnit.InverseSquareMicrometer)] + [InlineData("mi⁻²", ReciprocalAreaUnit.InverseSquareMile)] + [InlineData("mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] + [InlineData("yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] + [InlineData("ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReciprocalAreaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ReciprocalAreaUnit parsedUnit = ReciprocalArea.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -461,7 +483,26 @@ public void ParseUnit(string abbreviation, ReciprocalAreaUnit expectedUnit) [InlineData("en-US", "mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] [InlineData("en-US", "yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] [InlineData("en-US", "ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] - public void ParseUnitWithCulture(string culture, string abbreviation, ReciprocalAreaUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ReciprocalAreaUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ReciprocalAreaUnit parsedUnit = ReciprocalArea.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm⁻²", ReciprocalAreaUnit.InverseSquareCentimeter)] + [InlineData("en-US", "dm⁻²", ReciprocalAreaUnit.InverseSquareDecimeter)] + [InlineData("en-US", "ft⁻²", ReciprocalAreaUnit.InverseSquareFoot)] + [InlineData("en-US", "in⁻²", ReciprocalAreaUnit.InverseSquareInch)] + [InlineData("en-US", "km⁻²", ReciprocalAreaUnit.InverseSquareKilometer)] + [InlineData("en-US", "m⁻²", ReciprocalAreaUnit.InverseSquareMeter)] + [InlineData("en-US", "µm⁻²", ReciprocalAreaUnit.InverseSquareMicrometer)] + [InlineData("en-US", "mi⁻²", ReciprocalAreaUnit.InverseSquareMile)] + [InlineData("en-US", "mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] + [InlineData("en-US", "yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] + [InlineData("en-US", "ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ReciprocalAreaUnit expectedUnit) { ReciprocalAreaUnit parsedUnit = ReciprocalArea.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -479,9 +520,49 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Reciprocal [InlineData("mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] [InlineData("yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] [InlineData("ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] - public void TryParseUnit(string abbreviation, ReciprocalAreaUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReciprocalAreaUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ReciprocalArea.TryParseUnit(abbreviation, out ReciprocalAreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm⁻²", ReciprocalAreaUnit.InverseSquareCentimeter)] + [InlineData("dm⁻²", ReciprocalAreaUnit.InverseSquareDecimeter)] + [InlineData("ft⁻²", ReciprocalAreaUnit.InverseSquareFoot)] + [InlineData("in⁻²", ReciprocalAreaUnit.InverseSquareInch)] + [InlineData("km⁻²", ReciprocalAreaUnit.InverseSquareKilometer)] + [InlineData("m⁻²", ReciprocalAreaUnit.InverseSquareMeter)] + [InlineData("µm⁻²", ReciprocalAreaUnit.InverseSquareMicrometer)] + [InlineData("mi⁻²", ReciprocalAreaUnit.InverseSquareMile)] + [InlineData("mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] + [InlineData("yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] + [InlineData("ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReciprocalAreaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ReciprocalArea.TryParseUnit(abbreviation, out ReciprocalAreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm⁻²", ReciprocalAreaUnit.InverseSquareCentimeter)] + [InlineData("en-US", "dm⁻²", ReciprocalAreaUnit.InverseSquareDecimeter)] + [InlineData("en-US", "ft⁻²", ReciprocalAreaUnit.InverseSquareFoot)] + [InlineData("en-US", "in⁻²", ReciprocalAreaUnit.InverseSquareInch)] + [InlineData("en-US", "km⁻²", ReciprocalAreaUnit.InverseSquareKilometer)] + [InlineData("en-US", "m⁻²", ReciprocalAreaUnit.InverseSquareMeter)] + [InlineData("en-US", "µm⁻²", ReciprocalAreaUnit.InverseSquareMicrometer)] + [InlineData("en-US", "mi⁻²", ReciprocalAreaUnit.InverseSquareMile)] + [InlineData("en-US", "mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] + [InlineData("en-US", "yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] + [InlineData("en-US", "ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ReciprocalAreaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ReciprocalArea.TryParseUnit(abbreviation, out ReciprocalAreaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -498,7 +579,7 @@ public void TryParseUnit(string abbreviation, ReciprocalAreaUnit expectedUnit) [InlineData("en-US", "mm⁻²", ReciprocalAreaUnit.InverseSquareMillimeter)] [InlineData("en-US", "yd⁻²", ReciprocalAreaUnit.InverseSquareYard)] [InlineData("en-US", "ft⁻² (US)", ReciprocalAreaUnit.InverseUsSurveySquareFoot)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ReciprocalAreaUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ReciprocalAreaUnit expectedUnit) { Assert.True(ReciprocalArea.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ReciprocalAreaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs index 7d78a86264..f1260610ef 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ReciprocalLengthTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -558,10 +559,40 @@ public void TryParse() [InlineData("1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] [InlineData("yd⁻¹", ReciprocalLengthUnit.InverseYard)] [InlineData("1/yd", ReciprocalLengthUnit.InverseYard)] - public void ParseUnit(string abbreviation, ReciprocalLengthUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReciprocalLengthUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ReciprocalLengthUnit parsedUnit = ReciprocalLength.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ReciprocalLengthUnit parsedUnit = ReciprocalLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm⁻¹", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("1/cm", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("ft⁻¹", ReciprocalLengthUnit.InverseFoot)] + [InlineData("1/ft", ReciprocalLengthUnit.InverseFoot)] + [InlineData("in⁻¹", ReciprocalLengthUnit.InverseInch)] + [InlineData("1/in", ReciprocalLengthUnit.InverseInch)] + [InlineData("m⁻¹", ReciprocalLengthUnit.InverseMeter)] + [InlineData("1/m", ReciprocalLengthUnit.InverseMeter)] + [InlineData("µin⁻¹", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("1/µin", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("mil⁻¹", ReciprocalLengthUnit.InverseMil)] + [InlineData("1/mil", ReciprocalLengthUnit.InverseMil)] + [InlineData("mi⁻¹", ReciprocalLengthUnit.InverseMile)] + [InlineData("1/mi", ReciprocalLengthUnit.InverseMile)] + [InlineData("mm⁻¹", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("1/mm", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("ftUS⁻¹", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("yd⁻¹", ReciprocalLengthUnit.InverseYard)] + [InlineData("1/yd", ReciprocalLengthUnit.InverseYard)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReciprocalLengthUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ReciprocalLengthUnit parsedUnit = ReciprocalLength.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -586,7 +617,35 @@ public void ParseUnit(string abbreviation, ReciprocalLengthUnit expectedUnit) [InlineData("en-US", "1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] [InlineData("en-US", "yd⁻¹", ReciprocalLengthUnit.InverseYard)] [InlineData("en-US", "1/yd", ReciprocalLengthUnit.InverseYard)] - public void ParseUnitWithCulture(string culture, string abbreviation, ReciprocalLengthUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ReciprocalLengthUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ReciprocalLengthUnit parsedUnit = ReciprocalLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm⁻¹", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("en-US", "1/cm", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("en-US", "ft⁻¹", ReciprocalLengthUnit.InverseFoot)] + [InlineData("en-US", "1/ft", ReciprocalLengthUnit.InverseFoot)] + [InlineData("en-US", "in⁻¹", ReciprocalLengthUnit.InverseInch)] + [InlineData("en-US", "1/in", ReciprocalLengthUnit.InverseInch)] + [InlineData("en-US", "m⁻¹", ReciprocalLengthUnit.InverseMeter)] + [InlineData("en-US", "1/m", ReciprocalLengthUnit.InverseMeter)] + [InlineData("en-US", "µin⁻¹", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("en-US", "1/µin", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("en-US", "mil⁻¹", ReciprocalLengthUnit.InverseMil)] + [InlineData("en-US", "1/mil", ReciprocalLengthUnit.InverseMil)] + [InlineData("en-US", "mi⁻¹", ReciprocalLengthUnit.InverseMile)] + [InlineData("en-US", "1/mi", ReciprocalLengthUnit.InverseMile)] + [InlineData("en-US", "mm⁻¹", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("en-US", "1/mm", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("en-US", "ftUS⁻¹", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("en-US", "1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("en-US", "yd⁻¹", ReciprocalLengthUnit.InverseYard)] + [InlineData("en-US", "1/yd", ReciprocalLengthUnit.InverseYard)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ReciprocalLengthUnit expectedUnit) { ReciprocalLengthUnit parsedUnit = ReciprocalLength.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -613,9 +672,67 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Reciprocal [InlineData("1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] [InlineData("yd⁻¹", ReciprocalLengthUnit.InverseYard)] [InlineData("1/yd", ReciprocalLengthUnit.InverseYard)] - public void TryParseUnit(string abbreviation, ReciprocalLengthUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ReciprocalLengthUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ReciprocalLength.TryParseUnit(abbreviation, out ReciprocalLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm⁻¹", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("1/cm", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("ft⁻¹", ReciprocalLengthUnit.InverseFoot)] + [InlineData("1/ft", ReciprocalLengthUnit.InverseFoot)] + [InlineData("in⁻¹", ReciprocalLengthUnit.InverseInch)] + [InlineData("1/in", ReciprocalLengthUnit.InverseInch)] + [InlineData("m⁻¹", ReciprocalLengthUnit.InverseMeter)] + [InlineData("1/m", ReciprocalLengthUnit.InverseMeter)] + [InlineData("µin⁻¹", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("1/µin", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("mil⁻¹", ReciprocalLengthUnit.InverseMil)] + [InlineData("1/mil", ReciprocalLengthUnit.InverseMil)] + [InlineData("mi⁻¹", ReciprocalLengthUnit.InverseMile)] + [InlineData("1/mi", ReciprocalLengthUnit.InverseMile)] + [InlineData("mm⁻¹", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("1/mm", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("ftUS⁻¹", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("yd⁻¹", ReciprocalLengthUnit.InverseYard)] + [InlineData("1/yd", ReciprocalLengthUnit.InverseYard)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ReciprocalLengthUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ReciprocalLength.TryParseUnit(abbreviation, out ReciprocalLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm⁻¹", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("en-US", "1/cm", ReciprocalLengthUnit.InverseCentimeter)] + [InlineData("en-US", "ft⁻¹", ReciprocalLengthUnit.InverseFoot)] + [InlineData("en-US", "1/ft", ReciprocalLengthUnit.InverseFoot)] + [InlineData("en-US", "in⁻¹", ReciprocalLengthUnit.InverseInch)] + [InlineData("en-US", "1/in", ReciprocalLengthUnit.InverseInch)] + [InlineData("en-US", "m⁻¹", ReciprocalLengthUnit.InverseMeter)] + [InlineData("en-US", "1/m", ReciprocalLengthUnit.InverseMeter)] + [InlineData("en-US", "µin⁻¹", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("en-US", "1/µin", ReciprocalLengthUnit.InverseMicroinch)] + [InlineData("en-US", "mil⁻¹", ReciprocalLengthUnit.InverseMil)] + [InlineData("en-US", "1/mil", ReciprocalLengthUnit.InverseMil)] + [InlineData("en-US", "mi⁻¹", ReciprocalLengthUnit.InverseMile)] + [InlineData("en-US", "1/mi", ReciprocalLengthUnit.InverseMile)] + [InlineData("en-US", "mm⁻¹", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("en-US", "1/mm", ReciprocalLengthUnit.InverseMillimeter)] + [InlineData("en-US", "ftUS⁻¹", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("en-US", "1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] + [InlineData("en-US", "yd⁻¹", ReciprocalLengthUnit.InverseYard)] + [InlineData("en-US", "1/yd", ReciprocalLengthUnit.InverseYard)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ReciprocalLengthUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ReciprocalLength.TryParseUnit(abbreviation, out ReciprocalLengthUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -641,7 +758,7 @@ public void TryParseUnit(string abbreviation, ReciprocalLengthUnit expectedUnit) [InlineData("en-US", "1/ftUS", ReciprocalLengthUnit.InverseUsSurveyFoot)] [InlineData("en-US", "yd⁻¹", ReciprocalLengthUnit.InverseYard)] [InlineData("en-US", "1/yd", ReciprocalLengthUnit.InverseYard)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ReciprocalLengthUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ReciprocalLengthUnit expectedUnit) { Assert.True(ReciprocalLength.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ReciprocalLengthUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs index 84732905bc..ccf890ed31 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RelativeHumidityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("%RH", RelativeHumidityUnit.Percent)] - public void ParseUnit(string abbreviation, RelativeHumidityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RelativeHumidityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - RelativeHumidityUnit parsedUnit = RelativeHumidity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + RelativeHumidityUnit parsedUnit = RelativeHumidity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("%RH", RelativeHumidityUnit.Percent)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RelativeHumidityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + RelativeHumidityUnit parsedUnit = RelativeHumidity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "%RH", RelativeHumidityUnit.Percent)] - public void ParseUnitWithCulture(string culture, string abbreviation, RelativeHumidityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, RelativeHumidityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + RelativeHumidityUnit parsedUnit = RelativeHumidity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "%RH", RelativeHumidityUnit.Percent)] + public void ParseUnit_WithCulture(string culture, string abbreviation, RelativeHumidityUnit expectedUnit) { RelativeHumidityUnit parsedUnit = RelativeHumidity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, RelativeHu [Theory] [InlineData("%RH", RelativeHumidityUnit.Percent)] - public void TryParseUnit(string abbreviation, RelativeHumidityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RelativeHumidityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(RelativeHumidity.TryParseUnit(abbreviation, out RelativeHumidityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("%RH", RelativeHumidityUnit.Percent)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RelativeHumidityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(RelativeHumidity.TryParseUnit(abbreviation, out RelativeHumidityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "%RH", RelativeHumidityUnit.Percent)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, RelativeHumidityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(RelativeHumidity.TryParseUnit(abbreviation, out RelativeHumidityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "%RH", RelativeHumidityUnit.Percent)] - public void TryParseUnitWithCulture(string culture, string abbreviation, RelativeHumidityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, RelativeHumidityUnit expectedUnit) { Assert.True(RelativeHumidity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RelativeHumidityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs index be6348c482..7b6bbdc5df 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalAccelerationTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -288,10 +289,25 @@ public void TryParse() [InlineData("rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] [InlineData("rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] [InlineData("r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] - public void ParseUnit(string abbreviation, RotationalAccelerationUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RotationalAccelerationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - RotationalAccelerationUnit parsedUnit = RotationalAcceleration.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + RotationalAccelerationUnit parsedUnit = RotationalAcceleration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("°/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("deg/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] + [InlineData("rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] + [InlineData("r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RotationalAccelerationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + RotationalAccelerationUnit parsedUnit = RotationalAcceleration.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -301,7 +317,20 @@ public void ParseUnit(string abbreviation, RotationalAccelerationUnit expectedUn [InlineData("en-US", "rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] [InlineData("en-US", "rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] [InlineData("en-US", "r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] - public void ParseUnitWithCulture(string culture, string abbreviation, RotationalAccelerationUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, RotationalAccelerationUnit expectedUnit) + { + using var _ = new CultureScope(culture); + RotationalAccelerationUnit parsedUnit = RotationalAcceleration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "°/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("en-US", "deg/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("en-US", "rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] + [InlineData("en-US", "rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] + [InlineData("en-US", "r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] + public void ParseUnit_WithCulture(string culture, string abbreviation, RotationalAccelerationUnit expectedUnit) { RotationalAccelerationUnit parsedUnit = RotationalAcceleration.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -313,9 +342,37 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Rotational [InlineData("rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] [InlineData("rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] [InlineData("r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] - public void TryParseUnit(string abbreviation, RotationalAccelerationUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RotationalAccelerationUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(RotationalAcceleration.TryParseUnit(abbreviation, out RotationalAccelerationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("°/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("deg/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] + [InlineData("rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] + [InlineData("r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RotationalAccelerationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(RotationalAcceleration.TryParseUnit(abbreviation, out RotationalAccelerationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "°/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("en-US", "deg/s²", RotationalAccelerationUnit.DegreePerSecondSquared)] + [InlineData("en-US", "rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] + [InlineData("en-US", "rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] + [InlineData("en-US", "r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, RotationalAccelerationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(RotationalAcceleration.TryParseUnit(abbreviation, out RotationalAccelerationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -326,7 +383,7 @@ public void TryParseUnit(string abbreviation, RotationalAccelerationUnit expecte [InlineData("en-US", "rad/s²", RotationalAccelerationUnit.RadianPerSecondSquared)] [InlineData("en-US", "rpm/s", RotationalAccelerationUnit.RevolutionPerMinutePerSecond)] [InlineData("en-US", "r/s²", RotationalAccelerationUnit.RevolutionPerSecondSquared)] - public void TryParseUnitWithCulture(string culture, string abbreviation, RotationalAccelerationUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, RotationalAccelerationUnit expectedUnit) { Assert.True(RotationalAcceleration.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RotationalAccelerationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs index 398a81aead..9cabc4c153 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalSpeedTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -730,10 +731,39 @@ public void TryParse() [InlineData("rpm", RotationalSpeedUnit.RevolutionPerMinute)] [InlineData("r/min", RotationalSpeedUnit.RevolutionPerMinute)] [InlineData("r/s", RotationalSpeedUnit.RevolutionPerSecond)] - public void ParseUnit(string abbreviation, RotationalSpeedUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RotationalSpeedUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - RotationalSpeedUnit parsedUnit = RotationalSpeed.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + RotationalSpeedUnit parsedUnit = RotationalSpeed.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("crad/s", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("drad/s", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("°/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("deg/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("°/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("deg/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("µ°/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("µdeg/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("µrad/s", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("m°/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("mdeg/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("mrad/s", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("n°/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("ndeg/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("nrad/s", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("rad/s", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("rpm", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("r/min", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("r/s", RotationalSpeedUnit.RevolutionPerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RotationalSpeedUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + RotationalSpeedUnit parsedUnit = RotationalSpeed.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -769,7 +799,46 @@ public void ParseUnit(string abbreviation, RotationalSpeedUnit expectedUnit) [InlineData("ru-RU", "рад/с", RotationalSpeedUnit.RadianPerSecond)] [InlineData("ru-RU", "об/мин", RotationalSpeedUnit.RevolutionPerMinute)] [InlineData("ru-RU", "об/с", RotationalSpeedUnit.RevolutionPerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, RotationalSpeedUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, RotationalSpeedUnit expectedUnit) + { + using var _ = new CultureScope(culture); + RotationalSpeedUnit parsedUnit = RotationalSpeed.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "crad/s", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("en-US", "drad/s", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("en-US", "°/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("en-US", "deg/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("en-US", "°/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("en-US", "deg/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("en-US", "µ°/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("en-US", "µdeg/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("en-US", "µrad/s", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("en-US", "m°/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("en-US", "mdeg/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("en-US", "mrad/s", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("en-US", "n°/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("en-US", "ndeg/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("en-US", "nrad/s", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("en-US", "rad/s", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("en-US", "rpm", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("en-US", "r/min", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("en-US", "r/s", RotationalSpeedUnit.RevolutionPerSecond)] + [InlineData("ru-RU", "срад/с", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("ru-RU", "драд/с", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("ru-RU", "°/с", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("ru-RU", "мк°/с", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("ru-RU", "мкрад/с", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("ru-RU", "м°/с", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("ru-RU", "мрад/с", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("ru-RU", "н°/с", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("ru-RU", "нрад/с", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("ru-RU", "рад/с", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("ru-RU", "об/мин", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("ru-RU", "об/с", RotationalSpeedUnit.RevolutionPerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, RotationalSpeedUnit expectedUnit) { RotationalSpeedUnit parsedUnit = RotationalSpeed.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -795,9 +864,77 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Rotational [InlineData("rpm", RotationalSpeedUnit.RevolutionPerMinute)] [InlineData("r/min", RotationalSpeedUnit.RevolutionPerMinute)] [InlineData("r/s", RotationalSpeedUnit.RevolutionPerSecond)] - public void TryParseUnit(string abbreviation, RotationalSpeedUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RotationalSpeedUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(RotationalSpeed.TryParseUnit(abbreviation, out RotationalSpeedUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("crad/s", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("drad/s", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("°/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("deg/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("°/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("deg/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("µ°/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("µdeg/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("µrad/s", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("m°/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("mdeg/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("mrad/s", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("n°/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("ndeg/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("nrad/s", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("rad/s", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("rpm", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("r/min", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("r/s", RotationalSpeedUnit.RevolutionPerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RotationalSpeedUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(RotationalSpeed.TryParseUnit(abbreviation, out RotationalSpeedUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "crad/s", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("en-US", "drad/s", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("en-US", "°/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("en-US", "deg/min", RotationalSpeedUnit.DegreePerMinute)] + [InlineData("en-US", "°/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("en-US", "deg/s", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("en-US", "µ°/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("en-US", "µdeg/s", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("en-US", "µrad/s", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("en-US", "m°/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("en-US", "mdeg/s", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("en-US", "mrad/s", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("en-US", "n°/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("en-US", "ndeg/s", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("en-US", "nrad/s", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("en-US", "rad/s", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("en-US", "rpm", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("en-US", "r/min", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("en-US", "r/s", RotationalSpeedUnit.RevolutionPerSecond)] + [InlineData("ru-RU", "срад/с", RotationalSpeedUnit.CentiradianPerSecond)] + [InlineData("ru-RU", "драд/с", RotationalSpeedUnit.DeciradianPerSecond)] + [InlineData("ru-RU", "°/с", RotationalSpeedUnit.DegreePerSecond)] + [InlineData("ru-RU", "мк°/с", RotationalSpeedUnit.MicrodegreePerSecond)] + [InlineData("ru-RU", "мкрад/с", RotationalSpeedUnit.MicroradianPerSecond)] + [InlineData("ru-RU", "м°/с", RotationalSpeedUnit.MillidegreePerSecond)] + [InlineData("ru-RU", "мрад/с", RotationalSpeedUnit.MilliradianPerSecond)] + [InlineData("ru-RU", "н°/с", RotationalSpeedUnit.NanodegreePerSecond)] + [InlineData("ru-RU", "нрад/с", RotationalSpeedUnit.NanoradianPerSecond)] + [InlineData("ru-RU", "рад/с", RotationalSpeedUnit.RadianPerSecond)] + [InlineData("ru-RU", "об/мин", RotationalSpeedUnit.RevolutionPerMinute)] + [InlineData("ru-RU", "об/с", RotationalSpeedUnit.RevolutionPerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, RotationalSpeedUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(RotationalSpeed.TryParseUnit(abbreviation, out RotationalSpeedUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -834,7 +971,7 @@ public void TryParseUnit(string abbreviation, RotationalSpeedUnit expectedUnit) [InlineData("ru-RU", "рад/с", RotationalSpeedUnit.RadianPerSecond)] [InlineData("ru-RU", "об/мин", RotationalSpeedUnit.RevolutionPerMinute)] [InlineData("ru-RU", "об/с", RotationalSpeedUnit.RevolutionPerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, RotationalSpeedUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, RotationalSpeedUnit expectedUnit) { Assert.True(RotationalSpeed.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RotationalSpeedUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs index feb5b06327..cd534ed05d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessPerLengthTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -410,10 +411,33 @@ public void TryParse() [InlineData("N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] [InlineData("Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] [InlineData("lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] - public void ParseUnit(string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - RotationalStiffnessPerLengthUnit parsedUnit = RotationalStiffnessPerLength.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + RotationalStiffnessPerLengthUnit parsedUnit = RotationalStiffnessPerLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kN·m/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("kNm/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("kipf·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kip·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("k·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kipf·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kip·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("k·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("MN·m/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("MNm/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + RotationalStiffnessPerLengthUnit parsedUnit = RotationalStiffnessPerLength.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -431,7 +455,28 @@ public void ParseUnit(string abbreviation, RotationalStiffnessPerLengthUnit expe [InlineData("en-US", "N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] [InlineData("en-US", "Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] [InlineData("en-US", "lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] - public void ParseUnitWithCulture(string culture, string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + { + using var _ = new CultureScope(culture); + RotationalStiffnessPerLengthUnit parsedUnit = RotationalStiffnessPerLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kN·m/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "kNm/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "kipf·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kip·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "k·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kipf·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kip·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "k·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "MN·m/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "MNm/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] + public void ParseUnit_WithCulture(string culture, string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) { RotationalStiffnessPerLengthUnit parsedUnit = RotationalStiffnessPerLength.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -451,9 +496,53 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Rotational [InlineData("N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] [InlineData("Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] [InlineData("lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] - public void TryParseUnit(string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(RotationalStiffnessPerLength.TryParseUnit(abbreviation, out RotationalStiffnessPerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kN·m/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("kNm/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("kipf·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kip·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("k·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kipf·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("kip·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("k·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("MN·m/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("MNm/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(RotationalStiffnessPerLength.TryParseUnit(abbreviation, out RotationalStiffnessPerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kN·m/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "kNm/rad/m", RotationalStiffnessPerLengthUnit.KilonewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "kipf·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kip·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "k·ft/°/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kipf·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "kip·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "k·ft/deg/ft", RotationalStiffnessPerLengthUnit.KilopoundForceFootPerDegreesPerFoot)] + [InlineData("en-US", "MN·m/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "MNm/rad/m", RotationalStiffnessPerLengthUnit.MeganewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] + [InlineData("en-US", "lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(RotationalStiffnessPerLength.TryParseUnit(abbreviation, out RotationalStiffnessPerLengthUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -472,7 +561,7 @@ public void TryParseUnit(string abbreviation, RotationalStiffnessPerLengthUnit e [InlineData("en-US", "N·m/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] [InlineData("en-US", "Nm/rad/m", RotationalStiffnessPerLengthUnit.NewtonMeterPerRadianPerMeter)] [InlineData("en-US", "lbf·ft/deg/ft", RotationalStiffnessPerLengthUnit.PoundForceFootPerDegreesPerFoot)] - public void TryParseUnitWithCulture(string culture, string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, RotationalStiffnessPerLengthUnit expectedUnit) { Assert.True(RotationalStiffnessPerLength.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RotationalStiffnessPerLengthUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs index d111880091..c84dcc1795 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/RotationalStiffnessTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1844,10 +1845,124 @@ public void TryParse() [InlineData("Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] [InlineData("lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] [InlineData("lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] - public void ParseUnit(string abbreviation, RotationalStiffnessUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RotationalStiffnessUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - RotationalStiffnessUnit parsedUnit = RotationalStiffness.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + RotationalStiffnessUnit parsedUnit = RotationalStiffness.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cN·m/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cNm/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cN·m/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cNm/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cN·mm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cNmm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cN·mm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cNmm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cN·mm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("cNmm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("daN·m/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daNm/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daN·m/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daNm/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daN·mm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daNmm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daN·mm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daNmm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daN·mm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("daNmm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("dN·m/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dNm/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dN·m/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dNm/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dN·mm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dNmm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dN·mm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dNmm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dN·mm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("dNmm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("kN·m/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kNm/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kN·m/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kNm/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kN·m/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("kNm/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("kN·mm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kNmm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kN·mm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kNmm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kN·mm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("kNmm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("kipf·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kip·ft/°g", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("k·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kipf·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kip·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("k·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("MN·m/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MNm/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MN·m/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MNm/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MN·m/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("MNm/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("MN·mm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MNmm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MN·mm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MNmm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MN·mm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("MNmm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("µN·m/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µNm/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µN·m/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µNm/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µN·mm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µNmm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µN·mm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µNmm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µN·mm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("µNmm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("mN·m/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mNm/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mN·m/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mNm/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mN·mm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mNmm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mN·mm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mNmm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mN·mm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("mNmm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("nN·m/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nNm/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nN·m/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nNm/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nN·mm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nNmm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nN·mm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nNmm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nN·mm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("nNmm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("N·m/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("Nm/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("N·m/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("Nm/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("N·m/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("Nm/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("N·mm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("Nmm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("N·mm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("Nmm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("N·mm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] + [InlineData("lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RotationalStiffnessUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + RotationalStiffnessUnit parsedUnit = RotationalStiffness.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1956,7 +2071,119 @@ public void ParseUnit(string abbreviation, RotationalStiffnessUnit expectedUnit) [InlineData("en-US", "Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] [InlineData("en-US", "lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] [InlineData("en-US", "lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] - public void ParseUnitWithCulture(string culture, string abbreviation, RotationalStiffnessUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, RotationalStiffnessUnit expectedUnit) + { + using var _ = new CultureScope(culture); + RotationalStiffnessUnit parsedUnit = RotationalStiffness.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cN·m/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cNm/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cN·m/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cNm/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cN·mm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cNmm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cN·mm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cNmm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cN·mm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("en-US", "cNmm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("en-US", "daN·m/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daNm/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daN·m/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daNm/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daN·mm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daNmm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daN·mm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daNmm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daN·mm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("en-US", "daNmm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("en-US", "dN·m/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dNm/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dN·m/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dNm/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dN·mm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dNmm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dN·mm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dNmm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dN·mm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("en-US", "dNmm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("en-US", "kN·m/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kNm/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kN·m/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kNm/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kN·m/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("en-US", "kNm/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("en-US", "kN·mm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kNmm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kN·mm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kNmm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kN·mm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("en-US", "kNmm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("en-US", "kipf·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kip·ft/°g", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "k·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kipf·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kip·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "k·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "MN·m/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MNm/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MN·m/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MNm/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MN·m/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("en-US", "MNm/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("en-US", "MN·mm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MNmm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MN·mm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MNmm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MN·mm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("en-US", "MNmm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("en-US", "µN·m/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µNm/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µN·m/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µNm/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µN·mm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µNmm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µN·mm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µNmm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µN·mm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("en-US", "µNmm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("en-US", "mN·m/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mNm/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mN·m/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mNm/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mN·mm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mNmm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mN·mm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mNmm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mN·mm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("en-US", "mNmm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("en-US", "nN·m/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nNm/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nN·m/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nNm/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nN·mm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nNmm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nN·mm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nNmm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nN·mm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("en-US", "nNmm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("en-US", "N·m/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "Nm/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "N·m/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "Nm/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "N·m/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("en-US", "Nm/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("en-US", "N·mm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "Nmm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "N·mm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "Nmm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "N·mm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("en-US", "Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("en-US", "lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] + [InlineData("en-US", "lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] + public void ParseUnit_WithCulture(string culture, string abbreviation, RotationalStiffnessUnit expectedUnit) { RotationalStiffnessUnit parsedUnit = RotationalStiffness.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -2067,9 +2294,235 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Rotational [InlineData("Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] [InlineData("lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] [InlineData("lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] - public void TryParseUnit(string abbreviation, RotationalStiffnessUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, RotationalStiffnessUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(RotationalStiffness.TryParseUnit(abbreviation, out RotationalStiffnessUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cN·m/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cNm/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cN·m/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cNm/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("cN·mm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cNmm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cN·mm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cNmm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("cN·mm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("cNmm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("daN·m/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daNm/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daN·m/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daNm/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("daN·mm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daNmm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daN·mm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daNmm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("daN·mm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("daNmm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("dN·m/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dNm/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dN·m/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dNm/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("dN·mm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dNmm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dN·mm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dNmm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("dN·mm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("dNmm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("kN·m/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kNm/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kN·m/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kNm/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("kN·m/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("kNm/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("kN·mm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kNmm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kN·mm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kNmm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("kN·mm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("kNmm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("kipf·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kip·ft/°g", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("k·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kipf·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("kip·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("k·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("MN·m/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MNm/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MN·m/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MNm/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("MN·m/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("MNm/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("MN·mm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MNmm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MN·mm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MNmm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("MN·mm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("MNmm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("µN·m/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µNm/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µN·m/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µNm/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("µN·mm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µNmm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µN·mm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µNmm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("µN·mm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("µNmm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("mN·m/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mNm/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mN·m/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mNm/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("mN·mm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mNmm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mN·mm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mNmm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("mN·mm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("mNmm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("nN·m/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nNm/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nN·m/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nNm/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("nN·mm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nNmm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nN·mm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nNmm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("nN·mm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("nNmm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("N·m/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("Nm/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("N·m/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("Nm/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("N·m/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("Nm/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("N·mm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("Nmm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("N·mm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("Nmm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("N·mm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] + [InlineData("lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, RotationalStiffnessUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(RotationalStiffness.TryParseUnit(abbreviation, out RotationalStiffnessUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cN·m/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cNm/deg", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cN·m/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cNm/°", RotationalStiffnessUnit.CentinewtonMeterPerDegree)] + [InlineData("en-US", "cN·mm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cNmm/deg", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cN·mm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cNmm/°", RotationalStiffnessUnit.CentinewtonMillimeterPerDegree)] + [InlineData("en-US", "cN·mm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("en-US", "cNmm/rad", RotationalStiffnessUnit.CentinewtonMillimeterPerRadian)] + [InlineData("en-US", "daN·m/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daNm/deg", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daN·m/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daNm/°", RotationalStiffnessUnit.DecanewtonMeterPerDegree)] + [InlineData("en-US", "daN·mm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daNmm/deg", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daN·mm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daNmm/°", RotationalStiffnessUnit.DecanewtonMillimeterPerDegree)] + [InlineData("en-US", "daN·mm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("en-US", "daNmm/rad", RotationalStiffnessUnit.DecanewtonMillimeterPerRadian)] + [InlineData("en-US", "dN·m/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dNm/deg", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dN·m/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dNm/°", RotationalStiffnessUnit.DecinewtonMeterPerDegree)] + [InlineData("en-US", "dN·mm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dNmm/deg", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dN·mm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dNmm/°", RotationalStiffnessUnit.DecinewtonMillimeterPerDegree)] + [InlineData("en-US", "dN·mm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("en-US", "dNmm/rad", RotationalStiffnessUnit.DecinewtonMillimeterPerRadian)] + [InlineData("en-US", "kN·m/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kNm/deg", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kN·m/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kNm/°", RotationalStiffnessUnit.KilonewtonMeterPerDegree)] + [InlineData("en-US", "kN·m/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("en-US", "kNm/rad", RotationalStiffnessUnit.KilonewtonMeterPerRadian)] + [InlineData("en-US", "kN·mm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kNmm/deg", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kN·mm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kNmm/°", RotationalStiffnessUnit.KilonewtonMillimeterPerDegree)] + [InlineData("en-US", "kN·mm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("en-US", "kNmm/rad", RotationalStiffnessUnit.KilonewtonMillimeterPerRadian)] + [InlineData("en-US", "kipf·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kip·ft/°g", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "k·ft/°", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kipf·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "kip·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "k·ft/deg", RotationalStiffnessUnit.KilopoundForceFootPerDegrees)] + [InlineData("en-US", "MN·m/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MNm/deg", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MN·m/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MNm/°", RotationalStiffnessUnit.MeganewtonMeterPerDegree)] + [InlineData("en-US", "MN·m/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("en-US", "MNm/rad", RotationalStiffnessUnit.MeganewtonMeterPerRadian)] + [InlineData("en-US", "MN·mm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MNmm/deg", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MN·mm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MNmm/°", RotationalStiffnessUnit.MeganewtonMillimeterPerDegree)] + [InlineData("en-US", "MN·mm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("en-US", "MNmm/rad", RotationalStiffnessUnit.MeganewtonMillimeterPerRadian)] + [InlineData("en-US", "µN·m/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µNm/deg", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µN·m/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µNm/°", RotationalStiffnessUnit.MicronewtonMeterPerDegree)] + [InlineData("en-US", "µN·mm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µNmm/deg", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µN·mm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µNmm/°", RotationalStiffnessUnit.MicronewtonMillimeterPerDegree)] + [InlineData("en-US", "µN·mm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("en-US", "µNmm/rad", RotationalStiffnessUnit.MicronewtonMillimeterPerRadian)] + [InlineData("en-US", "mN·m/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mNm/deg", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mN·m/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mNm/°", RotationalStiffnessUnit.MillinewtonMeterPerDegree)] + [InlineData("en-US", "mN·mm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mNmm/deg", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mN·mm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mNmm/°", RotationalStiffnessUnit.MillinewtonMillimeterPerDegree)] + [InlineData("en-US", "mN·mm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("en-US", "mNmm/rad", RotationalStiffnessUnit.MillinewtonMillimeterPerRadian)] + [InlineData("en-US", "nN·m/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nNm/deg", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nN·m/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nNm/°", RotationalStiffnessUnit.NanonewtonMeterPerDegree)] + [InlineData("en-US", "nN·mm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nNmm/deg", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nN·mm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nNmm/°", RotationalStiffnessUnit.NanonewtonMillimeterPerDegree)] + [InlineData("en-US", "nN·mm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("en-US", "nNmm/rad", RotationalStiffnessUnit.NanonewtonMillimeterPerRadian)] + [InlineData("en-US", "N·m/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "Nm/deg", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "N·m/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "Nm/°", RotationalStiffnessUnit.NewtonMeterPerDegree)] + [InlineData("en-US", "N·m/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("en-US", "Nm/rad", RotationalStiffnessUnit.NewtonMeterPerRadian)] + [InlineData("en-US", "N·mm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "Nmm/deg", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "N·mm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "Nmm/°", RotationalStiffnessUnit.NewtonMillimeterPerDegree)] + [InlineData("en-US", "N·mm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("en-US", "Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] + [InlineData("en-US", "lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] + [InlineData("en-US", "lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, RotationalStiffnessUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(RotationalStiffness.TryParseUnit(abbreviation, out RotationalStiffnessUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -2179,7 +2632,7 @@ public void TryParseUnit(string abbreviation, RotationalStiffnessUnit expectedUn [InlineData("en-US", "Nmm/rad", RotationalStiffnessUnit.NewtonMillimeterPerRadian)] [InlineData("en-US", "lbf·ft/rad", RotationalStiffnessUnit.PoundForceFeetPerRadian)] [InlineData("en-US", "lbf·ft/deg", RotationalStiffnessUnit.PoundForceFootPerDegrees)] - public void TryParseUnitWithCulture(string culture, string abbreviation, RotationalStiffnessUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, RotationalStiffnessUnit expectedUnit) { Assert.True(RotationalStiffness.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out RotationalStiffnessUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs index b2161b1f66..549162a196 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ScalarTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("", ScalarUnit.Amount)] - public void ParseUnit(string abbreviation, ScalarUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ScalarUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ScalarUnit parsedUnit = Scalar.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ScalarUnit parsedUnit = Scalar.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("", ScalarUnit.Amount)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ScalarUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ScalarUnit parsedUnit = Scalar.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "", ScalarUnit.Amount)] - public void ParseUnitWithCulture(string culture, string abbreviation, ScalarUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ScalarUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ScalarUnit parsedUnit = Scalar.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "", ScalarUnit.Amount)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ScalarUnit expectedUnit) { ScalarUnit parsedUnit = Scalar.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ScalarUnit [Theory] [InlineData("", ScalarUnit.Amount)] - public void TryParseUnit(string abbreviation, ScalarUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ScalarUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Scalar.TryParseUnit(abbreviation, out ScalarUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("", ScalarUnit.Amount)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ScalarUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Scalar.TryParseUnit(abbreviation, out ScalarUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "", ScalarUnit.Amount)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ScalarUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Scalar.TryParseUnit(abbreviation, out ScalarUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "", ScalarUnit.Amount)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ScalarUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ScalarUnit expectedUnit) { Assert.True(Scalar.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ScalarUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs index e81b52c804..478a627d51 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SolidAngleTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("sr", SolidAngleUnit.Steradian)] - public void ParseUnit(string abbreviation, SolidAngleUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SolidAngleUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - SolidAngleUnit parsedUnit = SolidAngle.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + SolidAngleUnit parsedUnit = SolidAngle.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("sr", SolidAngleUnit.Steradian)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SolidAngleUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + SolidAngleUnit parsedUnit = SolidAngle.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "sr", SolidAngleUnit.Steradian)] - public void ParseUnitWithCulture(string culture, string abbreviation, SolidAngleUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, SolidAngleUnit expectedUnit) + { + using var _ = new CultureScope(culture); + SolidAngleUnit parsedUnit = SolidAngle.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "sr", SolidAngleUnit.Steradian)] + public void ParseUnit_WithCulture(string culture, string abbreviation, SolidAngleUnit expectedUnit) { SolidAngleUnit parsedUnit = SolidAngle.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, SolidAngle [Theory] [InlineData("sr", SolidAngleUnit.Steradian)] - public void TryParseUnit(string abbreviation, SolidAngleUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SolidAngleUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(SolidAngle.TryParseUnit(abbreviation, out SolidAngleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("sr", SolidAngleUnit.Steradian)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SolidAngleUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(SolidAngle.TryParseUnit(abbreviation, out SolidAngleUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "sr", SolidAngleUnit.Steradian)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, SolidAngleUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(SolidAngle.TryParseUnit(abbreviation, out SolidAngleUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "sr", SolidAngleUnit.Steradian)] - public void TryParseUnitWithCulture(string culture, string abbreviation, SolidAngleUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, SolidAngleUnit expectedUnit) { Assert.True(SolidAngle.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SolidAngleUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs index adca56a795..f4d5b39e93 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEnergyTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -898,10 +899,50 @@ public void TryParse() [InlineData("Wd/t", SpecificEnergyUnit.WattDayPerTonne)] [InlineData("Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] [InlineData("Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] - public void ParseUnit(string abbreviation, SpecificEnergyUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpecificEnergyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - SpecificEnergyUnit parsedUnit = SpecificEnergy.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + SpecificEnergyUnit parsedUnit = SpecificEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("btu/lb", SpecificEnergyUnit.BtuPerPound)] + [InlineData("cal/g", SpecificEnergyUnit.CaloriePerGram)] + [InlineData("GWd/kg", SpecificEnergyUnit.GigawattDayPerKilogram)] + [InlineData("GWd/ST", SpecificEnergyUnit.GigawattDayPerShortTon)] + [InlineData("GWd/t", SpecificEnergyUnit.GigawattDayPerTonne)] + [InlineData("GWh/kg", SpecificEnergyUnit.GigawattHourPerKilogram)] + [InlineData("GWh/lbs", SpecificEnergyUnit.GigawattHourPerPound)] + [InlineData("J/kg", SpecificEnergyUnit.JoulePerKilogram)] + [InlineData("kcal/g", SpecificEnergyUnit.KilocaloriePerGram)] + [InlineData("kJ/kg", SpecificEnergyUnit.KilojoulePerKilogram)] + [InlineData("kWd/kg", SpecificEnergyUnit.KilowattDayPerKilogram)] + [InlineData("kWd/ST", SpecificEnergyUnit.KilowattDayPerShortTon)] + [InlineData("kWd/t", SpecificEnergyUnit.KilowattDayPerTonne)] + [InlineData("kWh/kg", SpecificEnergyUnit.KilowattHourPerKilogram)] + [InlineData("kWh/lbs", SpecificEnergyUnit.KilowattHourPerPound)] + [InlineData("MJ/kg", SpecificEnergyUnit.MegajoulePerKilogram)] + [InlineData("MJ/t", SpecificEnergyUnit.MegaJoulePerTonne)] + [InlineData("MWd/kg", SpecificEnergyUnit.MegawattDayPerKilogram)] + [InlineData("MWd/ST", SpecificEnergyUnit.MegawattDayPerShortTon)] + [InlineData("MWd/t", SpecificEnergyUnit.MegawattDayPerTonne)] + [InlineData("MWh/kg", SpecificEnergyUnit.MegawattHourPerKilogram)] + [InlineData("MWh/lbs", SpecificEnergyUnit.MegawattHourPerPound)] + [InlineData("TWd/kg", SpecificEnergyUnit.TerawattDayPerKilogram)] + [InlineData("TWd/ST", SpecificEnergyUnit.TerawattDayPerShortTon)] + [InlineData("TWd/t", SpecificEnergyUnit.TerawattDayPerTonne)] + [InlineData("Wd/kg", SpecificEnergyUnit.WattDayPerKilogram)] + [InlineData("Wd/ST", SpecificEnergyUnit.WattDayPerShortTon)] + [InlineData("Wd/t", SpecificEnergyUnit.WattDayPerTonne)] + [InlineData("Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] + [InlineData("Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpecificEnergyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + SpecificEnergyUnit parsedUnit = SpecificEnergy.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -936,7 +977,45 @@ public void ParseUnit(string abbreviation, SpecificEnergyUnit expectedUnit) [InlineData("en-US", "Wd/t", SpecificEnergyUnit.WattDayPerTonne)] [InlineData("en-US", "Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] [InlineData("en-US", "Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] - public void ParseUnitWithCulture(string culture, string abbreviation, SpecificEnergyUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, SpecificEnergyUnit expectedUnit) + { + using var _ = new CultureScope(culture); + SpecificEnergyUnit parsedUnit = SpecificEnergy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "btu/lb", SpecificEnergyUnit.BtuPerPound)] + [InlineData("en-US", "cal/g", SpecificEnergyUnit.CaloriePerGram)] + [InlineData("en-US", "GWd/kg", SpecificEnergyUnit.GigawattDayPerKilogram)] + [InlineData("en-US", "GWd/ST", SpecificEnergyUnit.GigawattDayPerShortTon)] + [InlineData("en-US", "GWd/t", SpecificEnergyUnit.GigawattDayPerTonne)] + [InlineData("en-US", "GWh/kg", SpecificEnergyUnit.GigawattHourPerKilogram)] + [InlineData("en-US", "GWh/lbs", SpecificEnergyUnit.GigawattHourPerPound)] + [InlineData("en-US", "J/kg", SpecificEnergyUnit.JoulePerKilogram)] + [InlineData("en-US", "kcal/g", SpecificEnergyUnit.KilocaloriePerGram)] + [InlineData("en-US", "kJ/kg", SpecificEnergyUnit.KilojoulePerKilogram)] + [InlineData("en-US", "kWd/kg", SpecificEnergyUnit.KilowattDayPerKilogram)] + [InlineData("en-US", "kWd/ST", SpecificEnergyUnit.KilowattDayPerShortTon)] + [InlineData("en-US", "kWd/t", SpecificEnergyUnit.KilowattDayPerTonne)] + [InlineData("en-US", "kWh/kg", SpecificEnergyUnit.KilowattHourPerKilogram)] + [InlineData("en-US", "kWh/lbs", SpecificEnergyUnit.KilowattHourPerPound)] + [InlineData("en-US", "MJ/kg", SpecificEnergyUnit.MegajoulePerKilogram)] + [InlineData("en-US", "MJ/t", SpecificEnergyUnit.MegaJoulePerTonne)] + [InlineData("en-US", "MWd/kg", SpecificEnergyUnit.MegawattDayPerKilogram)] + [InlineData("en-US", "MWd/ST", SpecificEnergyUnit.MegawattDayPerShortTon)] + [InlineData("en-US", "MWd/t", SpecificEnergyUnit.MegawattDayPerTonne)] + [InlineData("en-US", "MWh/kg", SpecificEnergyUnit.MegawattHourPerKilogram)] + [InlineData("en-US", "MWh/lbs", SpecificEnergyUnit.MegawattHourPerPound)] + [InlineData("en-US", "TWd/kg", SpecificEnergyUnit.TerawattDayPerKilogram)] + [InlineData("en-US", "TWd/ST", SpecificEnergyUnit.TerawattDayPerShortTon)] + [InlineData("en-US", "TWd/t", SpecificEnergyUnit.TerawattDayPerTonne)] + [InlineData("en-US", "Wd/kg", SpecificEnergyUnit.WattDayPerKilogram)] + [InlineData("en-US", "Wd/ST", SpecificEnergyUnit.WattDayPerShortTon)] + [InlineData("en-US", "Wd/t", SpecificEnergyUnit.WattDayPerTonne)] + [InlineData("en-US", "Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] + [InlineData("en-US", "Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] + public void ParseUnit_WithCulture(string culture, string abbreviation, SpecificEnergyUnit expectedUnit) { SpecificEnergyUnit parsedUnit = SpecificEnergy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -973,9 +1052,87 @@ public void ParseUnitWithCulture(string culture, string abbreviation, SpecificEn [InlineData("Wd/t", SpecificEnergyUnit.WattDayPerTonne)] [InlineData("Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] [InlineData("Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] - public void TryParseUnit(string abbreviation, SpecificEnergyUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpecificEnergyUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(SpecificEnergy.TryParseUnit(abbreviation, out SpecificEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("btu/lb", SpecificEnergyUnit.BtuPerPound)] + [InlineData("cal/g", SpecificEnergyUnit.CaloriePerGram)] + [InlineData("GWd/kg", SpecificEnergyUnit.GigawattDayPerKilogram)] + [InlineData("GWd/ST", SpecificEnergyUnit.GigawattDayPerShortTon)] + [InlineData("GWd/t", SpecificEnergyUnit.GigawattDayPerTonne)] + [InlineData("GWh/kg", SpecificEnergyUnit.GigawattHourPerKilogram)] + [InlineData("GWh/lbs", SpecificEnergyUnit.GigawattHourPerPound)] + [InlineData("J/kg", SpecificEnergyUnit.JoulePerKilogram)] + [InlineData("kcal/g", SpecificEnergyUnit.KilocaloriePerGram)] + [InlineData("kJ/kg", SpecificEnergyUnit.KilojoulePerKilogram)] + [InlineData("kWd/kg", SpecificEnergyUnit.KilowattDayPerKilogram)] + [InlineData("kWd/ST", SpecificEnergyUnit.KilowattDayPerShortTon)] + [InlineData("kWd/t", SpecificEnergyUnit.KilowattDayPerTonne)] + [InlineData("kWh/kg", SpecificEnergyUnit.KilowattHourPerKilogram)] + [InlineData("kWh/lbs", SpecificEnergyUnit.KilowattHourPerPound)] + [InlineData("MJ/kg", SpecificEnergyUnit.MegajoulePerKilogram)] + [InlineData("MJ/t", SpecificEnergyUnit.MegaJoulePerTonne)] + [InlineData("MWd/kg", SpecificEnergyUnit.MegawattDayPerKilogram)] + [InlineData("MWd/ST", SpecificEnergyUnit.MegawattDayPerShortTon)] + [InlineData("MWd/t", SpecificEnergyUnit.MegawattDayPerTonne)] + [InlineData("MWh/kg", SpecificEnergyUnit.MegawattHourPerKilogram)] + [InlineData("MWh/lbs", SpecificEnergyUnit.MegawattHourPerPound)] + [InlineData("TWd/kg", SpecificEnergyUnit.TerawattDayPerKilogram)] + [InlineData("TWd/ST", SpecificEnergyUnit.TerawattDayPerShortTon)] + [InlineData("TWd/t", SpecificEnergyUnit.TerawattDayPerTonne)] + [InlineData("Wd/kg", SpecificEnergyUnit.WattDayPerKilogram)] + [InlineData("Wd/ST", SpecificEnergyUnit.WattDayPerShortTon)] + [InlineData("Wd/t", SpecificEnergyUnit.WattDayPerTonne)] + [InlineData("Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] + [InlineData("Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpecificEnergyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(SpecificEnergy.TryParseUnit(abbreviation, out SpecificEnergyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "btu/lb", SpecificEnergyUnit.BtuPerPound)] + [InlineData("en-US", "cal/g", SpecificEnergyUnit.CaloriePerGram)] + [InlineData("en-US", "GWd/kg", SpecificEnergyUnit.GigawattDayPerKilogram)] + [InlineData("en-US", "GWd/ST", SpecificEnergyUnit.GigawattDayPerShortTon)] + [InlineData("en-US", "GWd/t", SpecificEnergyUnit.GigawattDayPerTonne)] + [InlineData("en-US", "GWh/kg", SpecificEnergyUnit.GigawattHourPerKilogram)] + [InlineData("en-US", "GWh/lbs", SpecificEnergyUnit.GigawattHourPerPound)] + [InlineData("en-US", "J/kg", SpecificEnergyUnit.JoulePerKilogram)] + [InlineData("en-US", "kcal/g", SpecificEnergyUnit.KilocaloriePerGram)] + [InlineData("en-US", "kJ/kg", SpecificEnergyUnit.KilojoulePerKilogram)] + [InlineData("en-US", "kWd/kg", SpecificEnergyUnit.KilowattDayPerKilogram)] + [InlineData("en-US", "kWd/ST", SpecificEnergyUnit.KilowattDayPerShortTon)] + [InlineData("en-US", "kWd/t", SpecificEnergyUnit.KilowattDayPerTonne)] + [InlineData("en-US", "kWh/kg", SpecificEnergyUnit.KilowattHourPerKilogram)] + [InlineData("en-US", "kWh/lbs", SpecificEnergyUnit.KilowattHourPerPound)] + [InlineData("en-US", "MJ/kg", SpecificEnergyUnit.MegajoulePerKilogram)] + [InlineData("en-US", "MJ/t", SpecificEnergyUnit.MegaJoulePerTonne)] + [InlineData("en-US", "MWd/kg", SpecificEnergyUnit.MegawattDayPerKilogram)] + [InlineData("en-US", "MWd/ST", SpecificEnergyUnit.MegawattDayPerShortTon)] + [InlineData("en-US", "MWd/t", SpecificEnergyUnit.MegawattDayPerTonne)] + [InlineData("en-US", "MWh/kg", SpecificEnergyUnit.MegawattHourPerKilogram)] + [InlineData("en-US", "MWh/lbs", SpecificEnergyUnit.MegawattHourPerPound)] + [InlineData("en-US", "TWd/kg", SpecificEnergyUnit.TerawattDayPerKilogram)] + [InlineData("en-US", "TWd/ST", SpecificEnergyUnit.TerawattDayPerShortTon)] + [InlineData("en-US", "TWd/t", SpecificEnergyUnit.TerawattDayPerTonne)] + [InlineData("en-US", "Wd/kg", SpecificEnergyUnit.WattDayPerKilogram)] + [InlineData("en-US", "Wd/ST", SpecificEnergyUnit.WattDayPerShortTon)] + [InlineData("en-US", "Wd/t", SpecificEnergyUnit.WattDayPerTonne)] + [InlineData("en-US", "Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] + [InlineData("en-US", "Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, SpecificEnergyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(SpecificEnergy.TryParseUnit(abbreviation, out SpecificEnergyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1011,7 +1168,7 @@ public void TryParseUnit(string abbreviation, SpecificEnergyUnit expectedUnit) [InlineData("en-US", "Wd/t", SpecificEnergyUnit.WattDayPerTonne)] [InlineData("en-US", "Wh/kg", SpecificEnergyUnit.WattHourPerKilogram)] [InlineData("en-US", "Wh/lbs", SpecificEnergyUnit.WattHourPerPound)] - public void TryParseUnitWithCulture(string culture, string abbreviation, SpecificEnergyUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, SpecificEnergyUnit expectedUnit) { Assert.True(SpecificEnergy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpecificEnergyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs index 14d9560161..27ab2c6f3a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificEntropyTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -408,10 +409,30 @@ public void TryParse() [InlineData("kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] [InlineData("MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] [InlineData("MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] - public void ParseUnit(string abbreviation, SpecificEntropyUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpecificEntropyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - SpecificEntropyUnit parsedUnit = SpecificEntropy.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + SpecificEntropyUnit parsedUnit = SpecificEntropy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("BTU/(lb·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("BTU/(lbm·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("cal/g.K", SpecificEntropyUnit.CaloriePerGramKelvin)] + [InlineData("J/kg.C", SpecificEntropyUnit.JoulePerKilogramDegreeCelsius)] + [InlineData("J/kg.K", SpecificEntropyUnit.JoulePerKilogramKelvin)] + [InlineData("kcal/g.K", SpecificEntropyUnit.KilocaloriePerGramKelvin)] + [InlineData("kJ/kg.C", SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius)] + [InlineData("kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] + [InlineData("MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] + [InlineData("MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpecificEntropyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + SpecificEntropyUnit parsedUnit = SpecificEntropy.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -426,7 +447,25 @@ public void ParseUnit(string abbreviation, SpecificEntropyUnit expectedUnit) [InlineData("en-US", "kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] [InlineData("en-US", "MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] [InlineData("en-US", "MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] - public void ParseUnitWithCulture(string culture, string abbreviation, SpecificEntropyUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, SpecificEntropyUnit expectedUnit) + { + using var _ = new CultureScope(culture); + SpecificEntropyUnit parsedUnit = SpecificEntropy.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "BTU/(lb·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("en-US", "BTU/(lbm·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("en-US", "cal/g.K", SpecificEntropyUnit.CaloriePerGramKelvin)] + [InlineData("en-US", "J/kg.C", SpecificEntropyUnit.JoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "J/kg.K", SpecificEntropyUnit.JoulePerKilogramKelvin)] + [InlineData("en-US", "kcal/g.K", SpecificEntropyUnit.KilocaloriePerGramKelvin)] + [InlineData("en-US", "kJ/kg.C", SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] + [InlineData("en-US", "MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] + public void ParseUnit_WithCulture(string culture, string abbreviation, SpecificEntropyUnit expectedUnit) { SpecificEntropyUnit parsedUnit = SpecificEntropy.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -443,9 +482,47 @@ public void ParseUnitWithCulture(string culture, string abbreviation, SpecificEn [InlineData("kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] [InlineData("MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] [InlineData("MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] - public void TryParseUnit(string abbreviation, SpecificEntropyUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpecificEntropyUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(SpecificEntropy.TryParseUnit(abbreviation, out SpecificEntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("BTU/(lb·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("BTU/(lbm·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("cal/g.K", SpecificEntropyUnit.CaloriePerGramKelvin)] + [InlineData("J/kg.C", SpecificEntropyUnit.JoulePerKilogramDegreeCelsius)] + [InlineData("J/kg.K", SpecificEntropyUnit.JoulePerKilogramKelvin)] + [InlineData("kcal/g.K", SpecificEntropyUnit.KilocaloriePerGramKelvin)] + [InlineData("kJ/kg.C", SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius)] + [InlineData("kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] + [InlineData("MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] + [InlineData("MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpecificEntropyUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(SpecificEntropy.TryParseUnit(abbreviation, out SpecificEntropyUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "BTU/(lb·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("en-US", "BTU/(lbm·°F)", SpecificEntropyUnit.BtuPerPoundFahrenheit)] + [InlineData("en-US", "cal/g.K", SpecificEntropyUnit.CaloriePerGramKelvin)] + [InlineData("en-US", "J/kg.C", SpecificEntropyUnit.JoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "J/kg.K", SpecificEntropyUnit.JoulePerKilogramKelvin)] + [InlineData("en-US", "kcal/g.K", SpecificEntropyUnit.KilocaloriePerGramKelvin)] + [InlineData("en-US", "kJ/kg.C", SpecificEntropyUnit.KilojoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] + [InlineData("en-US", "MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] + [InlineData("en-US", "MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, SpecificEntropyUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(SpecificEntropy.TryParseUnit(abbreviation, out SpecificEntropyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -461,7 +538,7 @@ public void TryParseUnit(string abbreviation, SpecificEntropyUnit expectedUnit) [InlineData("en-US", "kJ/kg.K", SpecificEntropyUnit.KilojoulePerKilogramKelvin)] [InlineData("en-US", "MJ/kg.C", SpecificEntropyUnit.MegajoulePerKilogramDegreeCelsius)] [InlineData("en-US", "MJ/kg.K", SpecificEntropyUnit.MegajoulePerKilogramKelvin)] - public void TryParseUnitWithCulture(string culture, string abbreviation, SpecificEntropyUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, SpecificEntropyUnit expectedUnit) { Assert.True(SpecificEntropy.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpecificEntropyUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs index 43e90b7fd4..c6a492182c 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificFuelConsumptionTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -274,10 +275,24 @@ public void TryParse() [InlineData("kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] [InlineData("kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] [InlineData("lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] - public void ParseUnit(string abbreviation, SpecificFuelConsumptionUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpecificFuelConsumptionUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - SpecificFuelConsumptionUnit parsedUnit = SpecificFuelConsumption.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + SpecificFuelConsumptionUnit parsedUnit = SpecificFuelConsumption.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g/(kN�s)", SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond)] + [InlineData("kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] + [InlineData("kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] + [InlineData("lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpecificFuelConsumptionUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + SpecificFuelConsumptionUnit parsedUnit = SpecificFuelConsumption.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -286,7 +301,19 @@ public void ParseUnit(string abbreviation, SpecificFuelConsumptionUnit expectedU [InlineData("en-US", "kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] [InlineData("en-US", "kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] [InlineData("en-US", "lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] - public void ParseUnitWithCulture(string culture, string abbreviation, SpecificFuelConsumptionUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, SpecificFuelConsumptionUnit expectedUnit) + { + using var _ = new CultureScope(culture); + SpecificFuelConsumptionUnit parsedUnit = SpecificFuelConsumption.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g/(kN�s)", SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond)] + [InlineData("en-US", "kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] + [InlineData("en-US", "kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] + [InlineData("en-US", "lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] + public void ParseUnit_WithCulture(string culture, string abbreviation, SpecificFuelConsumptionUnit expectedUnit) { SpecificFuelConsumptionUnit parsedUnit = SpecificFuelConsumption.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -297,9 +324,35 @@ public void ParseUnitWithCulture(string culture, string abbreviation, SpecificFu [InlineData("kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] [InlineData("kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] [InlineData("lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] - public void TryParseUnit(string abbreviation, SpecificFuelConsumptionUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpecificFuelConsumptionUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(SpecificFuelConsumption.TryParseUnit(abbreviation, out SpecificFuelConsumptionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("g/(kN�s)", SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond)] + [InlineData("kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] + [InlineData("kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] + [InlineData("lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpecificFuelConsumptionUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(SpecificFuelConsumption.TryParseUnit(abbreviation, out SpecificFuelConsumptionUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "g/(kN�s)", SpecificFuelConsumptionUnit.GramPerKiloNewtonSecond)] + [InlineData("en-US", "kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] + [InlineData("en-US", "kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] + [InlineData("en-US", "lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, SpecificFuelConsumptionUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(SpecificFuelConsumption.TryParseUnit(abbreviation, out SpecificFuelConsumptionUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -309,7 +362,7 @@ public void TryParseUnit(string abbreviation, SpecificFuelConsumptionUnit expect [InlineData("en-US", "kg/(kgf�h)", SpecificFuelConsumptionUnit.KilogramPerKilogramForceHour)] [InlineData("en-US", "kg/(kN�s)", SpecificFuelConsumptionUnit.KilogramPerKiloNewtonSecond)] [InlineData("en-US", "lb/(lbf·h)", SpecificFuelConsumptionUnit.PoundMassPerPoundForceHour)] - public void TryParseUnitWithCulture(string culture, string abbreviation, SpecificFuelConsumptionUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, SpecificFuelConsumptionUnit expectedUnit) { Assert.True(SpecificFuelConsumption.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpecificFuelConsumptionUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs index 2a360fc1ee..a14a10265a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificVolumeTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -250,10 +251,23 @@ public void TryParse() [InlineData("ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] [InlineData("m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] [InlineData("mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] - public void ParseUnit(string abbreviation, SpecificVolumeUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpecificVolumeUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - SpecificVolumeUnit parsedUnit = SpecificVolume.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + SpecificVolumeUnit parsedUnit = SpecificVolume.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] + [InlineData("m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] + [InlineData("mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpecificVolumeUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + SpecificVolumeUnit parsedUnit = SpecificVolume.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -261,7 +275,18 @@ public void ParseUnit(string abbreviation, SpecificVolumeUnit expectedUnit) [InlineData("en-US", "ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] [InlineData("en-US", "m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] [InlineData("en-US", "mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] - public void ParseUnitWithCulture(string culture, string abbreviation, SpecificVolumeUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, SpecificVolumeUnit expectedUnit) + { + using var _ = new CultureScope(culture); + SpecificVolumeUnit parsedUnit = SpecificVolume.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] + [InlineData("en-US", "m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] + [InlineData("en-US", "mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] + public void ParseUnit_WithCulture(string culture, string abbreviation, SpecificVolumeUnit expectedUnit) { SpecificVolumeUnit parsedUnit = SpecificVolume.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -271,9 +296,33 @@ public void ParseUnitWithCulture(string culture, string abbreviation, SpecificVo [InlineData("ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] [InlineData("m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] [InlineData("mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] - public void TryParseUnit(string abbreviation, SpecificVolumeUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpecificVolumeUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(SpecificVolume.TryParseUnit(abbreviation, out SpecificVolumeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] + [InlineData("m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] + [InlineData("mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpecificVolumeUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(SpecificVolume.TryParseUnit(abbreviation, out SpecificVolumeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] + [InlineData("en-US", "m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] + [InlineData("en-US", "mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, SpecificVolumeUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(SpecificVolume.TryParseUnit(abbreviation, out SpecificVolumeUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -282,7 +331,7 @@ public void TryParseUnit(string abbreviation, SpecificVolumeUnit expectedUnit) [InlineData("en-US", "ft³/lb", SpecificVolumeUnit.CubicFootPerPound)] [InlineData("en-US", "m³/kg", SpecificVolumeUnit.CubicMeterPerKilogram)] [InlineData("en-US", "mm³/kg", SpecificVolumeUnit.MillicubicMeterPerKilogram)] - public void TryParseUnitWithCulture(string culture, string abbreviation, SpecificVolumeUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, SpecificVolumeUnit expectedUnit) { Assert.True(SpecificVolume.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpecificVolumeUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs index 09cccfe14c..26115ca31e 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpecificWeightTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -586,10 +587,37 @@ public void TryParse() [InlineData("tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] [InlineData("tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] [InlineData("tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] - public void ParseUnit(string abbreviation, SpecificWeightUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpecificWeightUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - SpecificWeightUnit parsedUnit = SpecificWeight.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + SpecificWeightUnit parsedUnit = SpecificWeight.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kgf/cm³", SpecificWeightUnit.KilogramForcePerCubicCentimeter)] + [InlineData("kgf/m³", SpecificWeightUnit.KilogramForcePerCubicMeter)] + [InlineData("kgf/mm³", SpecificWeightUnit.KilogramForcePerCubicMillimeter)] + [InlineData("kN/cm³", SpecificWeightUnit.KilonewtonPerCubicCentimeter)] + [InlineData("kN/m³", SpecificWeightUnit.KilonewtonPerCubicMeter)] + [InlineData("kN/mm³", SpecificWeightUnit.KilonewtonPerCubicMillimeter)] + [InlineData("kipf/ft³", SpecificWeightUnit.KilopoundForcePerCubicFoot)] + [InlineData("kipf/in³", SpecificWeightUnit.KilopoundForcePerCubicInch)] + [InlineData("MN/m³", SpecificWeightUnit.MeganewtonPerCubicMeter)] + [InlineData("N/cm³", SpecificWeightUnit.NewtonPerCubicCentimeter)] + [InlineData("N/m³", SpecificWeightUnit.NewtonPerCubicMeter)] + [InlineData("N/mm³", SpecificWeightUnit.NewtonPerCubicMillimeter)] + [InlineData("lbf/ft³", SpecificWeightUnit.PoundForcePerCubicFoot)] + [InlineData("lbf/in³", SpecificWeightUnit.PoundForcePerCubicInch)] + [InlineData("tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] + [InlineData("tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] + [InlineData("tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpecificWeightUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + SpecificWeightUnit parsedUnit = SpecificWeight.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -611,7 +639,32 @@ public void ParseUnit(string abbreviation, SpecificWeightUnit expectedUnit) [InlineData("en-US", "tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] [InlineData("en-US", "tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] [InlineData("en-US", "tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, SpecificWeightUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, SpecificWeightUnit expectedUnit) + { + using var _ = new CultureScope(culture); + SpecificWeightUnit parsedUnit = SpecificWeight.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kgf/cm³", SpecificWeightUnit.KilogramForcePerCubicCentimeter)] + [InlineData("en-US", "kgf/m³", SpecificWeightUnit.KilogramForcePerCubicMeter)] + [InlineData("en-US", "kgf/mm³", SpecificWeightUnit.KilogramForcePerCubicMillimeter)] + [InlineData("en-US", "kN/cm³", SpecificWeightUnit.KilonewtonPerCubicCentimeter)] + [InlineData("en-US", "kN/m³", SpecificWeightUnit.KilonewtonPerCubicMeter)] + [InlineData("en-US", "kN/mm³", SpecificWeightUnit.KilonewtonPerCubicMillimeter)] + [InlineData("en-US", "kipf/ft³", SpecificWeightUnit.KilopoundForcePerCubicFoot)] + [InlineData("en-US", "kipf/in³", SpecificWeightUnit.KilopoundForcePerCubicInch)] + [InlineData("en-US", "MN/m³", SpecificWeightUnit.MeganewtonPerCubicMeter)] + [InlineData("en-US", "N/cm³", SpecificWeightUnit.NewtonPerCubicCentimeter)] + [InlineData("en-US", "N/m³", SpecificWeightUnit.NewtonPerCubicMeter)] + [InlineData("en-US", "N/mm³", SpecificWeightUnit.NewtonPerCubicMillimeter)] + [InlineData("en-US", "lbf/ft³", SpecificWeightUnit.PoundForcePerCubicFoot)] + [InlineData("en-US", "lbf/in³", SpecificWeightUnit.PoundForcePerCubicInch)] + [InlineData("en-US", "tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] + [InlineData("en-US", "tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] + [InlineData("en-US", "tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, SpecificWeightUnit expectedUnit) { SpecificWeightUnit parsedUnit = SpecificWeight.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -635,9 +688,61 @@ public void ParseUnitWithCulture(string culture, string abbreviation, SpecificWe [InlineData("tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] [InlineData("tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] [InlineData("tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] - public void TryParseUnit(string abbreviation, SpecificWeightUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpecificWeightUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(SpecificWeight.TryParseUnit(abbreviation, out SpecificWeightUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("kgf/cm³", SpecificWeightUnit.KilogramForcePerCubicCentimeter)] + [InlineData("kgf/m³", SpecificWeightUnit.KilogramForcePerCubicMeter)] + [InlineData("kgf/mm³", SpecificWeightUnit.KilogramForcePerCubicMillimeter)] + [InlineData("kN/cm³", SpecificWeightUnit.KilonewtonPerCubicCentimeter)] + [InlineData("kN/m³", SpecificWeightUnit.KilonewtonPerCubicMeter)] + [InlineData("kN/mm³", SpecificWeightUnit.KilonewtonPerCubicMillimeter)] + [InlineData("kipf/ft³", SpecificWeightUnit.KilopoundForcePerCubicFoot)] + [InlineData("kipf/in³", SpecificWeightUnit.KilopoundForcePerCubicInch)] + [InlineData("MN/m³", SpecificWeightUnit.MeganewtonPerCubicMeter)] + [InlineData("N/cm³", SpecificWeightUnit.NewtonPerCubicCentimeter)] + [InlineData("N/m³", SpecificWeightUnit.NewtonPerCubicMeter)] + [InlineData("N/mm³", SpecificWeightUnit.NewtonPerCubicMillimeter)] + [InlineData("lbf/ft³", SpecificWeightUnit.PoundForcePerCubicFoot)] + [InlineData("lbf/in³", SpecificWeightUnit.PoundForcePerCubicInch)] + [InlineData("tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] + [InlineData("tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] + [InlineData("tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpecificWeightUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(SpecificWeight.TryParseUnit(abbreviation, out SpecificWeightUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "kgf/cm³", SpecificWeightUnit.KilogramForcePerCubicCentimeter)] + [InlineData("en-US", "kgf/m³", SpecificWeightUnit.KilogramForcePerCubicMeter)] + [InlineData("en-US", "kgf/mm³", SpecificWeightUnit.KilogramForcePerCubicMillimeter)] + [InlineData("en-US", "kN/cm³", SpecificWeightUnit.KilonewtonPerCubicCentimeter)] + [InlineData("en-US", "kN/m³", SpecificWeightUnit.KilonewtonPerCubicMeter)] + [InlineData("en-US", "kN/mm³", SpecificWeightUnit.KilonewtonPerCubicMillimeter)] + [InlineData("en-US", "kipf/ft³", SpecificWeightUnit.KilopoundForcePerCubicFoot)] + [InlineData("en-US", "kipf/in³", SpecificWeightUnit.KilopoundForcePerCubicInch)] + [InlineData("en-US", "MN/m³", SpecificWeightUnit.MeganewtonPerCubicMeter)] + [InlineData("en-US", "N/cm³", SpecificWeightUnit.NewtonPerCubicCentimeter)] + [InlineData("en-US", "N/m³", SpecificWeightUnit.NewtonPerCubicMeter)] + [InlineData("en-US", "N/mm³", SpecificWeightUnit.NewtonPerCubicMillimeter)] + [InlineData("en-US", "lbf/ft³", SpecificWeightUnit.PoundForcePerCubicFoot)] + [InlineData("en-US", "lbf/in³", SpecificWeightUnit.PoundForcePerCubicInch)] + [InlineData("en-US", "tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] + [InlineData("en-US", "tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] + [InlineData("en-US", "tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, SpecificWeightUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(SpecificWeight.TryParseUnit(abbreviation, out SpecificWeightUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -660,7 +765,7 @@ public void TryParseUnit(string abbreviation, SpecificWeightUnit expectedUnit) [InlineData("en-US", "tf/cm³", SpecificWeightUnit.TonneForcePerCubicCentimeter)] [InlineData("en-US", "tf/m³", SpecificWeightUnit.TonneForcePerCubicMeter)] [InlineData("en-US", "tf/mm³", SpecificWeightUnit.TonneForcePerCubicMillimeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, SpecificWeightUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, SpecificWeightUnit expectedUnit) { Assert.True(SpecificWeight.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpecificWeightUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs index 48603f84c3..159c3014f8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/SpeedTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -1366,10 +1367,59 @@ public void TryParse() [InlineData("yd/h", SpeedUnit.YardPerHour)] [InlineData("yd/min", SpeedUnit.YardPerMinute)] [InlineData("yd/s", SpeedUnit.YardPerSecond)] - public void ParseUnit(string abbreviation, SpeedUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpeedUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - SpeedUnit parsedUnit = Speed.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + SpeedUnit parsedUnit = Speed.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm/h", SpeedUnit.CentimeterPerHour)] + [InlineData("cm/min", SpeedUnit.CentimeterPerMinute)] + [InlineData("cm/s", SpeedUnit.CentimeterPerSecond)] + [InlineData("dm/min", SpeedUnit.DecimeterPerMinute)] + [InlineData("dm/s", SpeedUnit.DecimeterPerSecond)] + [InlineData("ft/h", SpeedUnit.FootPerHour)] + [InlineData("ft/min", SpeedUnit.FootPerMinute)] + [InlineData("ft/s", SpeedUnit.FootPerSecond)] + [InlineData("in/h", SpeedUnit.InchPerHour)] + [InlineData("in/min", SpeedUnit.InchPerMinute)] + [InlineData("in/s", SpeedUnit.InchPerSecond)] + [InlineData("km/h", SpeedUnit.KilometerPerHour)] + [InlineData("km/min", SpeedUnit.KilometerPerMinute)] + [InlineData("km/s", SpeedUnit.KilometerPerSecond)] + [InlineData("kn", SpeedUnit.Knot)] + [InlineData("kt", SpeedUnit.Knot)] + [InlineData("knot", SpeedUnit.Knot)] + [InlineData("knots", SpeedUnit.Knot)] + [InlineData("M", SpeedUnit.Mach)] + [InlineData("Ma", SpeedUnit.Mach)] + [InlineData("MN", SpeedUnit.Mach)] + [InlineData("MACH", SpeedUnit.Mach)] + [InlineData("m/h", SpeedUnit.MeterPerHour)] + [InlineData("m/min", SpeedUnit.MeterPerMinute)] + [InlineData("m/s", SpeedUnit.MeterPerSecond)] + [InlineData("µm/min", SpeedUnit.MicrometerPerMinute)] + [InlineData("µm/s", SpeedUnit.MicrometerPerSecond)] + [InlineData("mph", SpeedUnit.MilePerHour)] + [InlineData("mm/h", SpeedUnit.MillimeterPerHour)] + [InlineData("mm/min", SpeedUnit.MillimeterPerMinute)] + [InlineData("mm/s", SpeedUnit.MillimeterPerSecond)] + [InlineData("nm/min", SpeedUnit.NanometerPerMinute)] + [InlineData("nm/s", SpeedUnit.NanometerPerSecond)] + [InlineData("ftUS/h", SpeedUnit.UsSurveyFootPerHour)] + [InlineData("ftUS/min", SpeedUnit.UsSurveyFootPerMinute)] + [InlineData("ftUS/s", SpeedUnit.UsSurveyFootPerSecond)] + [InlineData("yd/h", SpeedUnit.YardPerHour)] + [InlineData("yd/min", SpeedUnit.YardPerMinute)] + [InlineData("yd/s", SpeedUnit.YardPerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpeedUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + SpeedUnit parsedUnit = Speed.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -1437,7 +1487,78 @@ public void ParseUnit(string abbreviation, SpeedUnit expectedUnit) [InlineData("ru-RU", "мм/с", SpeedUnit.MillimeterPerSecond)] [InlineData("ru-RU", "нм/мин", SpeedUnit.NanometerPerMinute)] [InlineData("ru-RU", "нм/с", SpeedUnit.NanometerPerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, SpeedUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, SpeedUnit expectedUnit) + { + using var _ = new CultureScope(culture); + SpeedUnit parsedUnit = Speed.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm/h", SpeedUnit.CentimeterPerHour)] + [InlineData("en-US", "cm/min", SpeedUnit.CentimeterPerMinute)] + [InlineData("en-US", "cm/s", SpeedUnit.CentimeterPerSecond)] + [InlineData("en-US", "dm/min", SpeedUnit.DecimeterPerMinute)] + [InlineData("en-US", "dm/s", SpeedUnit.DecimeterPerSecond)] + [InlineData("en-US", "ft/h", SpeedUnit.FootPerHour)] + [InlineData("en-US", "ft/min", SpeedUnit.FootPerMinute)] + [InlineData("en-US", "ft/s", SpeedUnit.FootPerSecond)] + [InlineData("en-US", "in/h", SpeedUnit.InchPerHour)] + [InlineData("en-US", "in/min", SpeedUnit.InchPerMinute)] + [InlineData("en-US", "in/s", SpeedUnit.InchPerSecond)] + [InlineData("en-US", "km/h", SpeedUnit.KilometerPerHour)] + [InlineData("en-US", "km/min", SpeedUnit.KilometerPerMinute)] + [InlineData("en-US", "km/s", SpeedUnit.KilometerPerSecond)] + [InlineData("en-US", "kn", SpeedUnit.Knot)] + [InlineData("en-US", "kt", SpeedUnit.Knot)] + [InlineData("en-US", "knot", SpeedUnit.Knot)] + [InlineData("en-US", "knots", SpeedUnit.Knot)] + [InlineData("en-US", "M", SpeedUnit.Mach)] + [InlineData("en-US", "Ma", SpeedUnit.Mach)] + [InlineData("en-US", "MN", SpeedUnit.Mach)] + [InlineData("en-US", "MACH", SpeedUnit.Mach)] + [InlineData("en-US", "m/h", SpeedUnit.MeterPerHour)] + [InlineData("en-US", "m/min", SpeedUnit.MeterPerMinute)] + [InlineData("en-US", "m/s", SpeedUnit.MeterPerSecond)] + [InlineData("en-US", "µm/min", SpeedUnit.MicrometerPerMinute)] + [InlineData("en-US", "µm/s", SpeedUnit.MicrometerPerSecond)] + [InlineData("en-US", "mph", SpeedUnit.MilePerHour)] + [InlineData("en-US", "mm/h", SpeedUnit.MillimeterPerHour)] + [InlineData("en-US", "mm/min", SpeedUnit.MillimeterPerMinute)] + [InlineData("en-US", "mm/s", SpeedUnit.MillimeterPerSecond)] + [InlineData("en-US", "nm/min", SpeedUnit.NanometerPerMinute)] + [InlineData("en-US", "nm/s", SpeedUnit.NanometerPerSecond)] + [InlineData("en-US", "ftUS/h", SpeedUnit.UsSurveyFootPerHour)] + [InlineData("en-US", "ftUS/min", SpeedUnit.UsSurveyFootPerMinute)] + [InlineData("en-US", "ftUS/s", SpeedUnit.UsSurveyFootPerSecond)] + [InlineData("en-US", "yd/h", SpeedUnit.YardPerHour)] + [InlineData("en-US", "yd/min", SpeedUnit.YardPerMinute)] + [InlineData("en-US", "yd/s", SpeedUnit.YardPerSecond)] + [InlineData("ru-RU", "см/ч", SpeedUnit.CentimeterPerHour)] + [InlineData("ru-RU", "см/мин", SpeedUnit.CentimeterPerMinute)] + [InlineData("ru-RU", "см/с", SpeedUnit.CentimeterPerSecond)] + [InlineData("ru-RU", "дм/мин", SpeedUnit.DecimeterPerMinute)] + [InlineData("ru-RU", "дм/с", SpeedUnit.DecimeterPerSecond)] + [InlineData("ru-RU", "фут/ч", SpeedUnit.FootPerHour)] + [InlineData("ru-RU", "фут/мин", SpeedUnit.FootPerMinute)] + [InlineData("ru-RU", "фут/с", SpeedUnit.FootPerSecond)] + [InlineData("ru-RU", "км/ч", SpeedUnit.KilometerPerHour)] + [InlineData("ru-RU", "км/мин", SpeedUnit.KilometerPerMinute)] + [InlineData("ru-RU", "км/с", SpeedUnit.KilometerPerSecond)] + [InlineData("ru-RU", "уз.", SpeedUnit.Knot)] + [InlineData("ru-RU", "мах", SpeedUnit.Mach)] + [InlineData("ru-RU", "м/ч", SpeedUnit.MeterPerHour)] + [InlineData("ru-RU", "м/мин", SpeedUnit.MeterPerMinute)] + [InlineData("ru-RU", "м/с", SpeedUnit.MeterPerSecond)] + [InlineData("ru-RU", "мкм/мин", SpeedUnit.MicrometerPerMinute)] + [InlineData("ru-RU", "мкм/с", SpeedUnit.MicrometerPerSecond)] + [InlineData("ru-RU", "миль/ч", SpeedUnit.MilePerHour)] + [InlineData("ru-RU", "мм/ч", SpeedUnit.MillimeterPerHour)] + [InlineData("ru-RU", "мм/мин", SpeedUnit.MillimeterPerMinute)] + [InlineData("ru-RU", "мм/с", SpeedUnit.MillimeterPerSecond)] + [InlineData("ru-RU", "нм/мин", SpeedUnit.NanometerPerMinute)] + [InlineData("ru-RU", "нм/с", SpeedUnit.NanometerPerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, SpeedUnit expectedUnit) { SpeedUnit parsedUnit = Speed.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -1483,9 +1604,129 @@ public void ParseUnitWithCulture(string culture, string abbreviation, SpeedUnit [InlineData("yd/h", SpeedUnit.YardPerHour)] [InlineData("yd/min", SpeedUnit.YardPerMinute)] [InlineData("yd/s", SpeedUnit.YardPerSecond)] - public void TryParseUnit(string abbreviation, SpeedUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, SpeedUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Speed.TryParseUnit(abbreviation, out SpeedUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm/h", SpeedUnit.CentimeterPerHour)] + [InlineData("cm/min", SpeedUnit.CentimeterPerMinute)] + [InlineData("cm/s", SpeedUnit.CentimeterPerSecond)] + [InlineData("dm/min", SpeedUnit.DecimeterPerMinute)] + [InlineData("dm/s", SpeedUnit.DecimeterPerSecond)] + [InlineData("ft/h", SpeedUnit.FootPerHour)] + [InlineData("ft/min", SpeedUnit.FootPerMinute)] + [InlineData("ft/s", SpeedUnit.FootPerSecond)] + [InlineData("in/h", SpeedUnit.InchPerHour)] + [InlineData("in/min", SpeedUnit.InchPerMinute)] + [InlineData("in/s", SpeedUnit.InchPerSecond)] + [InlineData("km/h", SpeedUnit.KilometerPerHour)] + [InlineData("km/min", SpeedUnit.KilometerPerMinute)] + [InlineData("km/s", SpeedUnit.KilometerPerSecond)] + [InlineData("kn", SpeedUnit.Knot)] + [InlineData("kt", SpeedUnit.Knot)] + [InlineData("knot", SpeedUnit.Knot)] + [InlineData("knots", SpeedUnit.Knot)] + [InlineData("M", SpeedUnit.Mach)] + [InlineData("Ma", SpeedUnit.Mach)] + [InlineData("MN", SpeedUnit.Mach)] + [InlineData("MACH", SpeedUnit.Mach)] + [InlineData("m/h", SpeedUnit.MeterPerHour)] + [InlineData("m/min", SpeedUnit.MeterPerMinute)] + [InlineData("m/s", SpeedUnit.MeterPerSecond)] + [InlineData("µm/min", SpeedUnit.MicrometerPerMinute)] + [InlineData("µm/s", SpeedUnit.MicrometerPerSecond)] + [InlineData("mph", SpeedUnit.MilePerHour)] + [InlineData("mm/h", SpeedUnit.MillimeterPerHour)] + [InlineData("mm/min", SpeedUnit.MillimeterPerMinute)] + [InlineData("mm/s", SpeedUnit.MillimeterPerSecond)] + [InlineData("nm/min", SpeedUnit.NanometerPerMinute)] + [InlineData("nm/s", SpeedUnit.NanometerPerSecond)] + [InlineData("ftUS/h", SpeedUnit.UsSurveyFootPerHour)] + [InlineData("ftUS/min", SpeedUnit.UsSurveyFootPerMinute)] + [InlineData("ftUS/s", SpeedUnit.UsSurveyFootPerSecond)] + [InlineData("yd/h", SpeedUnit.YardPerHour)] + [InlineData("yd/min", SpeedUnit.YardPerMinute)] + [InlineData("yd/s", SpeedUnit.YardPerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, SpeedUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Speed.TryParseUnit(abbreviation, out SpeedUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm/h", SpeedUnit.CentimeterPerHour)] + [InlineData("en-US", "cm/min", SpeedUnit.CentimeterPerMinute)] + [InlineData("en-US", "cm/s", SpeedUnit.CentimeterPerSecond)] + [InlineData("en-US", "dm/min", SpeedUnit.DecimeterPerMinute)] + [InlineData("en-US", "dm/s", SpeedUnit.DecimeterPerSecond)] + [InlineData("en-US", "ft/h", SpeedUnit.FootPerHour)] + [InlineData("en-US", "ft/min", SpeedUnit.FootPerMinute)] + [InlineData("en-US", "ft/s", SpeedUnit.FootPerSecond)] + [InlineData("en-US", "in/h", SpeedUnit.InchPerHour)] + [InlineData("en-US", "in/min", SpeedUnit.InchPerMinute)] + [InlineData("en-US", "in/s", SpeedUnit.InchPerSecond)] + [InlineData("en-US", "km/h", SpeedUnit.KilometerPerHour)] + [InlineData("en-US", "km/min", SpeedUnit.KilometerPerMinute)] + [InlineData("en-US", "km/s", SpeedUnit.KilometerPerSecond)] + [InlineData("en-US", "kn", SpeedUnit.Knot)] + [InlineData("en-US", "kt", SpeedUnit.Knot)] + [InlineData("en-US", "knot", SpeedUnit.Knot)] + [InlineData("en-US", "knots", SpeedUnit.Knot)] + [InlineData("en-US", "M", SpeedUnit.Mach)] + [InlineData("en-US", "Ma", SpeedUnit.Mach)] + [InlineData("en-US", "MN", SpeedUnit.Mach)] + [InlineData("en-US", "MACH", SpeedUnit.Mach)] + [InlineData("en-US", "m/h", SpeedUnit.MeterPerHour)] + [InlineData("en-US", "m/min", SpeedUnit.MeterPerMinute)] + [InlineData("en-US", "m/s", SpeedUnit.MeterPerSecond)] + [InlineData("en-US", "µm/min", SpeedUnit.MicrometerPerMinute)] + [InlineData("en-US", "µm/s", SpeedUnit.MicrometerPerSecond)] + [InlineData("en-US", "mph", SpeedUnit.MilePerHour)] + [InlineData("en-US", "mm/h", SpeedUnit.MillimeterPerHour)] + [InlineData("en-US", "mm/min", SpeedUnit.MillimeterPerMinute)] + [InlineData("en-US", "mm/s", SpeedUnit.MillimeterPerSecond)] + [InlineData("en-US", "nm/min", SpeedUnit.NanometerPerMinute)] + [InlineData("en-US", "nm/s", SpeedUnit.NanometerPerSecond)] + [InlineData("en-US", "ftUS/h", SpeedUnit.UsSurveyFootPerHour)] + [InlineData("en-US", "ftUS/min", SpeedUnit.UsSurveyFootPerMinute)] + [InlineData("en-US", "ftUS/s", SpeedUnit.UsSurveyFootPerSecond)] + [InlineData("en-US", "yd/h", SpeedUnit.YardPerHour)] + [InlineData("en-US", "yd/min", SpeedUnit.YardPerMinute)] + [InlineData("en-US", "yd/s", SpeedUnit.YardPerSecond)] + [InlineData("ru-RU", "см/ч", SpeedUnit.CentimeterPerHour)] + [InlineData("ru-RU", "см/мин", SpeedUnit.CentimeterPerMinute)] + [InlineData("ru-RU", "см/с", SpeedUnit.CentimeterPerSecond)] + [InlineData("ru-RU", "дм/мин", SpeedUnit.DecimeterPerMinute)] + [InlineData("ru-RU", "дм/с", SpeedUnit.DecimeterPerSecond)] + [InlineData("ru-RU", "фут/ч", SpeedUnit.FootPerHour)] + [InlineData("ru-RU", "фут/мин", SpeedUnit.FootPerMinute)] + [InlineData("ru-RU", "фут/с", SpeedUnit.FootPerSecond)] + [InlineData("ru-RU", "км/ч", SpeedUnit.KilometerPerHour)] + [InlineData("ru-RU", "км/мин", SpeedUnit.KilometerPerMinute)] + [InlineData("ru-RU", "км/с", SpeedUnit.KilometerPerSecond)] + [InlineData("ru-RU", "уз.", SpeedUnit.Knot)] + [InlineData("ru-RU", "мах", SpeedUnit.Mach)] + [InlineData("ru-RU", "м/ч", SpeedUnit.MeterPerHour)] + [InlineData("ru-RU", "м/мин", SpeedUnit.MeterPerMinute)] + [InlineData("ru-RU", "м/с", SpeedUnit.MeterPerSecond)] + [InlineData("ru-RU", "мкм/мин", SpeedUnit.MicrometerPerMinute)] + [InlineData("ru-RU", "мкм/с", SpeedUnit.MicrometerPerSecond)] + [InlineData("ru-RU", "миль/ч", SpeedUnit.MilePerHour)] + [InlineData("ru-RU", "мм/ч", SpeedUnit.MillimeterPerHour)] + [InlineData("ru-RU", "мм/мин", SpeedUnit.MillimeterPerMinute)] + [InlineData("ru-RU", "мм/с", SpeedUnit.MillimeterPerSecond)] + [InlineData("ru-RU", "нм/мин", SpeedUnit.NanometerPerMinute)] + [InlineData("ru-RU", "нм/с", SpeedUnit.NanometerPerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, SpeedUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Speed.TryParseUnit(abbreviation, out SpeedUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -1554,7 +1795,7 @@ public void TryParseUnit(string abbreviation, SpeedUnit expectedUnit) [InlineData("ru-RU", "мм/с", SpeedUnit.MillimeterPerSecond)] [InlineData("ru-RU", "нм/мин", SpeedUnit.NanometerPerMinute)] [InlineData("ru-RU", "нм/с", SpeedUnit.NanometerPerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, SpeedUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, SpeedUnit expectedUnit) { Assert.True(Speed.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out SpeedUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs index 00d4f5abd8..f2fe1a2ff4 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/StandardVolumeFlowTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -394,10 +395,29 @@ public void TryParse() [InlineData("Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] [InlineData("Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] [InlineData("slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] - public void ParseUnit(string abbreviation, StandardVolumeFlowUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, StandardVolumeFlowUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - StandardVolumeFlowUnit parsedUnit = StandardVolumeFlow.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + StandardVolumeFlowUnit parsedUnit = StandardVolumeFlow.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("sccm", StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute)] + [InlineData("scfh", StandardVolumeFlowUnit.StandardCubicFootPerHour)] + [InlineData("scfm", StandardVolumeFlowUnit.StandardCubicFootPerMinute)] + [InlineData("Sft³/s", StandardVolumeFlowUnit.StandardCubicFootPerSecond)] + [InlineData("Sm³/d", StandardVolumeFlowUnit.StandardCubicMeterPerDay)] + [InlineData("Sm³/h", StandardVolumeFlowUnit.StandardCubicMeterPerHour)] + [InlineData("Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] + [InlineData("Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] + [InlineData("slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, StandardVolumeFlowUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + StandardVolumeFlowUnit parsedUnit = StandardVolumeFlow.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -411,7 +431,24 @@ public void ParseUnit(string abbreviation, StandardVolumeFlowUnit expectedUnit) [InlineData("en-US", "Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] [InlineData("en-US", "Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] [InlineData("en-US", "slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] - public void ParseUnitWithCulture(string culture, string abbreviation, StandardVolumeFlowUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, StandardVolumeFlowUnit expectedUnit) + { + using var _ = new CultureScope(culture); + StandardVolumeFlowUnit parsedUnit = StandardVolumeFlow.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "sccm", StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute)] + [InlineData("en-US", "scfh", StandardVolumeFlowUnit.StandardCubicFootPerHour)] + [InlineData("en-US", "scfm", StandardVolumeFlowUnit.StandardCubicFootPerMinute)] + [InlineData("en-US", "Sft³/s", StandardVolumeFlowUnit.StandardCubicFootPerSecond)] + [InlineData("en-US", "Sm³/d", StandardVolumeFlowUnit.StandardCubicMeterPerDay)] + [InlineData("en-US", "Sm³/h", StandardVolumeFlowUnit.StandardCubicMeterPerHour)] + [InlineData("en-US", "Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] + [InlineData("en-US", "Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] + [InlineData("en-US", "slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] + public void ParseUnit_WithCulture(string culture, string abbreviation, StandardVolumeFlowUnit expectedUnit) { StandardVolumeFlowUnit parsedUnit = StandardVolumeFlow.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -427,9 +464,45 @@ public void ParseUnitWithCulture(string culture, string abbreviation, StandardVo [InlineData("Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] [InlineData("Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] [InlineData("slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] - public void TryParseUnit(string abbreviation, StandardVolumeFlowUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, StandardVolumeFlowUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(StandardVolumeFlow.TryParseUnit(abbreviation, out StandardVolumeFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("sccm", StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute)] + [InlineData("scfh", StandardVolumeFlowUnit.StandardCubicFootPerHour)] + [InlineData("scfm", StandardVolumeFlowUnit.StandardCubicFootPerMinute)] + [InlineData("Sft³/s", StandardVolumeFlowUnit.StandardCubicFootPerSecond)] + [InlineData("Sm³/d", StandardVolumeFlowUnit.StandardCubicMeterPerDay)] + [InlineData("Sm³/h", StandardVolumeFlowUnit.StandardCubicMeterPerHour)] + [InlineData("Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] + [InlineData("Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] + [InlineData("slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, StandardVolumeFlowUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(StandardVolumeFlow.TryParseUnit(abbreviation, out StandardVolumeFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "sccm", StandardVolumeFlowUnit.StandardCubicCentimeterPerMinute)] + [InlineData("en-US", "scfh", StandardVolumeFlowUnit.StandardCubicFootPerHour)] + [InlineData("en-US", "scfm", StandardVolumeFlowUnit.StandardCubicFootPerMinute)] + [InlineData("en-US", "Sft³/s", StandardVolumeFlowUnit.StandardCubicFootPerSecond)] + [InlineData("en-US", "Sm³/d", StandardVolumeFlowUnit.StandardCubicMeterPerDay)] + [InlineData("en-US", "Sm³/h", StandardVolumeFlowUnit.StandardCubicMeterPerHour)] + [InlineData("en-US", "Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] + [InlineData("en-US", "Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] + [InlineData("en-US", "slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, StandardVolumeFlowUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(StandardVolumeFlow.TryParseUnit(abbreviation, out StandardVolumeFlowUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -444,7 +517,7 @@ public void TryParseUnit(string abbreviation, StandardVolumeFlowUnit expectedUni [InlineData("en-US", "Sm³/min", StandardVolumeFlowUnit.StandardCubicMeterPerMinute)] [InlineData("en-US", "Sm³/s", StandardVolumeFlowUnit.StandardCubicMeterPerSecond)] [InlineData("en-US", "slm", StandardVolumeFlowUnit.StandardLiterPerMinute)] - public void TryParseUnitWithCulture(string culture, string abbreviation, StandardVolumeFlowUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, StandardVolumeFlowUnit expectedUnit) { Assert.True(StandardVolumeFlow.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out StandardVolumeFlowUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs index c5af1cb067..bcffff95ed 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureChangeRateTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -418,10 +419,30 @@ public void TryParse() [InlineData("µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] [InlineData("m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] [InlineData("n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] - public void ParseUnit(string abbreviation, TemperatureChangeRateUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TemperatureChangeRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - TemperatureChangeRateUnit parsedUnit = TemperatureChangeRate.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + TemperatureChangeRateUnit parsedUnit = TemperatureChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("c°C/s", TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond)] + [InlineData("da°C/s", TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond)] + [InlineData("d°C/s", TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond)] + [InlineData("°C/min", TemperatureChangeRateUnit.DegreeCelsiusPerMinute)] + [InlineData("°C/s", TemperatureChangeRateUnit.DegreeCelsiusPerSecond)] + [InlineData("h°C/s", TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond)] + [InlineData("k°C/s", TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond)] + [InlineData("µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] + [InlineData("m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] + [InlineData("n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TemperatureChangeRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + TemperatureChangeRateUnit parsedUnit = TemperatureChangeRate.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -436,7 +457,25 @@ public void ParseUnit(string abbreviation, TemperatureChangeRateUnit expectedUni [InlineData("en-US", "µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] [InlineData("en-US", "m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] [InlineData("en-US", "n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, TemperatureChangeRateUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, TemperatureChangeRateUnit expectedUnit) + { + using var _ = new CultureScope(culture); + TemperatureChangeRateUnit parsedUnit = TemperatureChangeRate.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "c°C/s", TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond)] + [InlineData("en-US", "da°C/s", TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond)] + [InlineData("en-US", "d°C/s", TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond)] + [InlineData("en-US", "°C/min", TemperatureChangeRateUnit.DegreeCelsiusPerMinute)] + [InlineData("en-US", "°C/s", TemperatureChangeRateUnit.DegreeCelsiusPerSecond)] + [InlineData("en-US", "h°C/s", TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond)] + [InlineData("en-US", "k°C/s", TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond)] + [InlineData("en-US", "µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] + [InlineData("en-US", "m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] + [InlineData("en-US", "n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, TemperatureChangeRateUnit expectedUnit) { TemperatureChangeRateUnit parsedUnit = TemperatureChangeRate.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -453,9 +492,47 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Temperatur [InlineData("µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] [InlineData("m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] [InlineData("n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] - public void TryParseUnit(string abbreviation, TemperatureChangeRateUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TemperatureChangeRateUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(TemperatureChangeRate.TryParseUnit(abbreviation, out TemperatureChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("c°C/s", TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond)] + [InlineData("da°C/s", TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond)] + [InlineData("d°C/s", TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond)] + [InlineData("°C/min", TemperatureChangeRateUnit.DegreeCelsiusPerMinute)] + [InlineData("°C/s", TemperatureChangeRateUnit.DegreeCelsiusPerSecond)] + [InlineData("h°C/s", TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond)] + [InlineData("k°C/s", TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond)] + [InlineData("µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] + [InlineData("m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] + [InlineData("n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TemperatureChangeRateUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(TemperatureChangeRate.TryParseUnit(abbreviation, out TemperatureChangeRateUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "c°C/s", TemperatureChangeRateUnit.CentidegreeCelsiusPerSecond)] + [InlineData("en-US", "da°C/s", TemperatureChangeRateUnit.DecadegreeCelsiusPerSecond)] + [InlineData("en-US", "d°C/s", TemperatureChangeRateUnit.DecidegreeCelsiusPerSecond)] + [InlineData("en-US", "°C/min", TemperatureChangeRateUnit.DegreeCelsiusPerMinute)] + [InlineData("en-US", "°C/s", TemperatureChangeRateUnit.DegreeCelsiusPerSecond)] + [InlineData("en-US", "h°C/s", TemperatureChangeRateUnit.HectodegreeCelsiusPerSecond)] + [InlineData("en-US", "k°C/s", TemperatureChangeRateUnit.KilodegreeCelsiusPerSecond)] + [InlineData("en-US", "µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] + [InlineData("en-US", "m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] + [InlineData("en-US", "n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, TemperatureChangeRateUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(TemperatureChangeRate.TryParseUnit(abbreviation, out TemperatureChangeRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -471,7 +548,7 @@ public void TryParseUnit(string abbreviation, TemperatureChangeRateUnit expected [InlineData("en-US", "µ°C/s", TemperatureChangeRateUnit.MicrodegreeCelsiusPerSecond)] [InlineData("en-US", "m°C/s", TemperatureChangeRateUnit.MillidegreeCelsiusPerSecond)] [InlineData("en-US", "n°C/s", TemperatureChangeRateUnit.NanodegreeCelsiusPerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, TemperatureChangeRateUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, TemperatureChangeRateUnit expectedUnit) { Assert.True(TemperatureChangeRate.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TemperatureChangeRateUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs index eb2137c59b..f16e9dc21a 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureDeltaTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -394,10 +395,29 @@ public void TryParse() [InlineData("∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] [InlineData("∆K", TemperatureDeltaUnit.Kelvin)] [InlineData("∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] - public void ParseUnit(string abbreviation, TemperatureDeltaUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TemperatureDeltaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - TemperatureDeltaUnit parsedUnit = TemperatureDelta.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + TemperatureDeltaUnit parsedUnit = TemperatureDelta.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("∆°C", TemperatureDeltaUnit.DegreeCelsius)] + [InlineData("∆°De", TemperatureDeltaUnit.DegreeDelisle)] + [InlineData("∆°F", TemperatureDeltaUnit.DegreeFahrenheit)] + [InlineData("∆°N", TemperatureDeltaUnit.DegreeNewton)] + [InlineData("∆°R", TemperatureDeltaUnit.DegreeRankine)] + [InlineData("∆°Ré", TemperatureDeltaUnit.DegreeReaumur)] + [InlineData("∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] + [InlineData("∆K", TemperatureDeltaUnit.Kelvin)] + [InlineData("∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TemperatureDeltaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + TemperatureDeltaUnit parsedUnit = TemperatureDelta.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -411,7 +431,24 @@ public void ParseUnit(string abbreviation, TemperatureDeltaUnit expectedUnit) [InlineData("en-US", "∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] [InlineData("en-US", "∆K", TemperatureDeltaUnit.Kelvin)] [InlineData("en-US", "∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] - public void ParseUnitWithCulture(string culture, string abbreviation, TemperatureDeltaUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, TemperatureDeltaUnit expectedUnit) + { + using var _ = new CultureScope(culture); + TemperatureDeltaUnit parsedUnit = TemperatureDelta.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "∆°C", TemperatureDeltaUnit.DegreeCelsius)] + [InlineData("en-US", "∆°De", TemperatureDeltaUnit.DegreeDelisle)] + [InlineData("en-US", "∆°F", TemperatureDeltaUnit.DegreeFahrenheit)] + [InlineData("en-US", "∆°N", TemperatureDeltaUnit.DegreeNewton)] + [InlineData("en-US", "∆°R", TemperatureDeltaUnit.DegreeRankine)] + [InlineData("en-US", "∆°Ré", TemperatureDeltaUnit.DegreeReaumur)] + [InlineData("en-US", "∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] + [InlineData("en-US", "∆K", TemperatureDeltaUnit.Kelvin)] + [InlineData("en-US", "∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] + public void ParseUnit_WithCulture(string culture, string abbreviation, TemperatureDeltaUnit expectedUnit) { TemperatureDeltaUnit parsedUnit = TemperatureDelta.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -427,9 +464,45 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Temperatur [InlineData("∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] [InlineData("∆K", TemperatureDeltaUnit.Kelvin)] [InlineData("∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] - public void TryParseUnit(string abbreviation, TemperatureDeltaUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TemperatureDeltaUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(TemperatureDelta.TryParseUnit(abbreviation, out TemperatureDeltaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("∆°C", TemperatureDeltaUnit.DegreeCelsius)] + [InlineData("∆°De", TemperatureDeltaUnit.DegreeDelisle)] + [InlineData("∆°F", TemperatureDeltaUnit.DegreeFahrenheit)] + [InlineData("∆°N", TemperatureDeltaUnit.DegreeNewton)] + [InlineData("∆°R", TemperatureDeltaUnit.DegreeRankine)] + [InlineData("∆°Ré", TemperatureDeltaUnit.DegreeReaumur)] + [InlineData("∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] + [InlineData("∆K", TemperatureDeltaUnit.Kelvin)] + [InlineData("∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TemperatureDeltaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(TemperatureDelta.TryParseUnit(abbreviation, out TemperatureDeltaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "∆°C", TemperatureDeltaUnit.DegreeCelsius)] + [InlineData("en-US", "∆°De", TemperatureDeltaUnit.DegreeDelisle)] + [InlineData("en-US", "∆°F", TemperatureDeltaUnit.DegreeFahrenheit)] + [InlineData("en-US", "∆°N", TemperatureDeltaUnit.DegreeNewton)] + [InlineData("en-US", "∆°R", TemperatureDeltaUnit.DegreeRankine)] + [InlineData("en-US", "∆°Ré", TemperatureDeltaUnit.DegreeReaumur)] + [InlineData("en-US", "∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] + [InlineData("en-US", "∆K", TemperatureDeltaUnit.Kelvin)] + [InlineData("en-US", "∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, TemperatureDeltaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(TemperatureDelta.TryParseUnit(abbreviation, out TemperatureDeltaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -444,7 +517,7 @@ public void TryParseUnit(string abbreviation, TemperatureDeltaUnit expectedUnit) [InlineData("en-US", "∆°Rø", TemperatureDeltaUnit.DegreeRoemer)] [InlineData("en-US", "∆K", TemperatureDeltaUnit.Kelvin)] [InlineData("en-US", "∆m°C", TemperatureDeltaUnit.MillidegreeCelsius)] - public void TryParseUnitWithCulture(string culture, string abbreviation, TemperatureDeltaUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, TemperatureDeltaUnit expectedUnit) { Assert.True(TemperatureDelta.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TemperatureDeltaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs index 824ff09341..6abb896a72 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureGradientTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -274,10 +275,24 @@ public void TryParse() [InlineData("∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] [InlineData("∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] [InlineData("∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] - public void ParseUnit(string abbreviation, TemperatureGradientUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TemperatureGradientUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - TemperatureGradientUnit parsedUnit = TemperatureGradient.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + TemperatureGradientUnit parsedUnit = TemperatureGradient.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("∆°C/km", TemperatureGradientUnit.DegreeCelsiusPerKilometer)] + [InlineData("∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] + [InlineData("∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] + [InlineData("∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TemperatureGradientUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + TemperatureGradientUnit parsedUnit = TemperatureGradient.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -286,7 +301,19 @@ public void ParseUnit(string abbreviation, TemperatureGradientUnit expectedUnit) [InlineData("en-US", "∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] [InlineData("en-US", "∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] [InlineData("en-US", "∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, TemperatureGradientUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, TemperatureGradientUnit expectedUnit) + { + using var _ = new CultureScope(culture); + TemperatureGradientUnit parsedUnit = TemperatureGradient.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "∆°C/km", TemperatureGradientUnit.DegreeCelsiusPerKilometer)] + [InlineData("en-US", "∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] + [InlineData("en-US", "∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] + [InlineData("en-US", "∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, TemperatureGradientUnit expectedUnit) { TemperatureGradientUnit parsedUnit = TemperatureGradient.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -297,9 +324,35 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Temperatur [InlineData("∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] [InlineData("∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] [InlineData("∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] - public void TryParseUnit(string abbreviation, TemperatureGradientUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TemperatureGradientUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(TemperatureGradient.TryParseUnit(abbreviation, out TemperatureGradientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("∆°C/km", TemperatureGradientUnit.DegreeCelsiusPerKilometer)] + [InlineData("∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] + [InlineData("∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] + [InlineData("∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TemperatureGradientUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(TemperatureGradient.TryParseUnit(abbreviation, out TemperatureGradientUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "∆°C/km", TemperatureGradientUnit.DegreeCelsiusPerKilometer)] + [InlineData("en-US", "∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] + [InlineData("en-US", "∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] + [InlineData("en-US", "∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, TemperatureGradientUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(TemperatureGradient.TryParseUnit(abbreviation, out TemperatureGradientUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -309,7 +362,7 @@ public void TryParseUnit(string abbreviation, TemperatureGradientUnit expectedUn [InlineData("en-US", "∆°C/m", TemperatureGradientUnit.DegreeCelsiusPerMeter)] [InlineData("en-US", "∆°F/ft", TemperatureGradientUnit.DegreeFahrenheitPerFoot)] [InlineData("en-US", "∆°K/m", TemperatureGradientUnit.KelvinPerMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, TemperatureGradientUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, TemperatureGradientUnit expectedUnit) { Assert.True(TemperatureGradient.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TemperatureGradientUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs index b97698e0fa..65d2a242f2 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TemperatureTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -418,10 +419,30 @@ public void TryParse() [InlineData("K", TemperatureUnit.Kelvin)] [InlineData("m°C", TemperatureUnit.MillidegreeCelsius)] [InlineData("T⊙", TemperatureUnit.SolarTemperature)] - public void ParseUnit(string abbreviation, TemperatureUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TemperatureUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - TemperatureUnit parsedUnit = Temperature.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + TemperatureUnit parsedUnit = Temperature.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("°C", TemperatureUnit.DegreeCelsius)] + [InlineData("°De", TemperatureUnit.DegreeDelisle)] + [InlineData("°F", TemperatureUnit.DegreeFahrenheit)] + [InlineData("°N", TemperatureUnit.DegreeNewton)] + [InlineData("°R", TemperatureUnit.DegreeRankine)] + [InlineData("°Ré", TemperatureUnit.DegreeReaumur)] + [InlineData("°Rø", TemperatureUnit.DegreeRoemer)] + [InlineData("K", TemperatureUnit.Kelvin)] + [InlineData("m°C", TemperatureUnit.MillidegreeCelsius)] + [InlineData("T⊙", TemperatureUnit.SolarTemperature)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TemperatureUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + TemperatureUnit parsedUnit = Temperature.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -436,7 +457,25 @@ public void ParseUnit(string abbreviation, TemperatureUnit expectedUnit) [InlineData("en-US", "K", TemperatureUnit.Kelvin)] [InlineData("en-US", "m°C", TemperatureUnit.MillidegreeCelsius)] [InlineData("en-US", "T⊙", TemperatureUnit.SolarTemperature)] - public void ParseUnitWithCulture(string culture, string abbreviation, TemperatureUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, TemperatureUnit expectedUnit) + { + using var _ = new CultureScope(culture); + TemperatureUnit parsedUnit = Temperature.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "°C", TemperatureUnit.DegreeCelsius)] + [InlineData("en-US", "°De", TemperatureUnit.DegreeDelisle)] + [InlineData("en-US", "°F", TemperatureUnit.DegreeFahrenheit)] + [InlineData("en-US", "°N", TemperatureUnit.DegreeNewton)] + [InlineData("en-US", "°R", TemperatureUnit.DegreeRankine)] + [InlineData("en-US", "°Ré", TemperatureUnit.DegreeReaumur)] + [InlineData("en-US", "°Rø", TemperatureUnit.DegreeRoemer)] + [InlineData("en-US", "K", TemperatureUnit.Kelvin)] + [InlineData("en-US", "m°C", TemperatureUnit.MillidegreeCelsius)] + [InlineData("en-US", "T⊙", TemperatureUnit.SolarTemperature)] + public void ParseUnit_WithCulture(string culture, string abbreviation, TemperatureUnit expectedUnit) { TemperatureUnit parsedUnit = Temperature.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -453,9 +492,47 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Temperatur [InlineData("K", TemperatureUnit.Kelvin)] [InlineData("m°C", TemperatureUnit.MillidegreeCelsius)] [InlineData("T⊙", TemperatureUnit.SolarTemperature)] - public void TryParseUnit(string abbreviation, TemperatureUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TemperatureUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Temperature.TryParseUnit(abbreviation, out TemperatureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("°C", TemperatureUnit.DegreeCelsius)] + [InlineData("°De", TemperatureUnit.DegreeDelisle)] + [InlineData("°F", TemperatureUnit.DegreeFahrenheit)] + [InlineData("°N", TemperatureUnit.DegreeNewton)] + [InlineData("°R", TemperatureUnit.DegreeRankine)] + [InlineData("°Ré", TemperatureUnit.DegreeReaumur)] + [InlineData("°Rø", TemperatureUnit.DegreeRoemer)] + [InlineData("K", TemperatureUnit.Kelvin)] + [InlineData("m°C", TemperatureUnit.MillidegreeCelsius)] + [InlineData("T⊙", TemperatureUnit.SolarTemperature)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TemperatureUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Temperature.TryParseUnit(abbreviation, out TemperatureUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "°C", TemperatureUnit.DegreeCelsius)] + [InlineData("en-US", "°De", TemperatureUnit.DegreeDelisle)] + [InlineData("en-US", "°F", TemperatureUnit.DegreeFahrenheit)] + [InlineData("en-US", "°N", TemperatureUnit.DegreeNewton)] + [InlineData("en-US", "°R", TemperatureUnit.DegreeRankine)] + [InlineData("en-US", "°Ré", TemperatureUnit.DegreeReaumur)] + [InlineData("en-US", "°Rø", TemperatureUnit.DegreeRoemer)] + [InlineData("en-US", "K", TemperatureUnit.Kelvin)] + [InlineData("en-US", "m°C", TemperatureUnit.MillidegreeCelsius)] + [InlineData("en-US", "T⊙", TemperatureUnit.SolarTemperature)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, TemperatureUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Temperature.TryParseUnit(abbreviation, out TemperatureUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -471,7 +548,7 @@ public void TryParseUnit(string abbreviation, TemperatureUnit expectedUnit) [InlineData("en-US", "K", TemperatureUnit.Kelvin)] [InlineData("en-US", "m°C", TemperatureUnit.MillidegreeCelsius)] [InlineData("en-US", "T⊙", TemperatureUnit.SolarTemperature)] - public void TryParseUnitWithCulture(string culture, string abbreviation, TemperatureUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, TemperatureUnit expectedUnit) { Assert.True(Temperature.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TemperatureUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs index 35ce56e9c0..27a06a7397 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalConductivityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -226,17 +227,39 @@ public void TryParse() [Theory] [InlineData("BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] [InlineData("W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] - public void ParseUnit(string abbreviation, ThermalConductivityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ThermalConductivityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ThermalConductivityUnit parsedUnit = ThermalConductivity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ThermalConductivityUnit parsedUnit = ThermalConductivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] + [InlineData("W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ThermalConductivityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ThermalConductivityUnit parsedUnit = ThermalConductivity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] [InlineData("en-US", "W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] - public void ParseUnitWithCulture(string culture, string abbreviation, ThermalConductivityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ThermalConductivityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ThermalConductivityUnit parsedUnit = ThermalConductivity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] + [InlineData("en-US", "W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ThermalConductivityUnit expectedUnit) { ThermalConductivityUnit parsedUnit = ThermalConductivity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -245,9 +268,31 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ThermalCon [Theory] [InlineData("BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] [InlineData("W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] - public void TryParseUnit(string abbreviation, ThermalConductivityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ThermalConductivityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ThermalConductivity.TryParseUnit(abbreviation, out ThermalConductivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] + [InlineData("W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ThermalConductivityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ThermalConductivity.TryParseUnit(abbreviation, out ThermalConductivityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] + [InlineData("en-US", "W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ThermalConductivityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ThermalConductivity.TryParseUnit(abbreviation, out ThermalConductivityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -255,7 +300,7 @@ public void TryParseUnit(string abbreviation, ThermalConductivityUnit expectedUn [Theory] [InlineData("en-US", "BTU/(h·ft·°F)", ThermalConductivityUnit.BtuPerHourFootFahrenheit)] [InlineData("en-US", "W/(m·K)", ThermalConductivityUnit.WattPerMeterKelvin)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ThermalConductivityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ThermalConductivityUnit expectedUnit) { Assert.True(ThermalConductivity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ThermalConductivityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs index e8892b405e..ef029f7067 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/ThermalInsulanceTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -322,10 +323,26 @@ public void TryParse() [InlineData("m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] [InlineData("m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] [InlineData("m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] - public void ParseUnit(string abbreviation, ThermalInsulanceUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ThermalInsulanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - ThermalInsulanceUnit parsedUnit = ThermalInsulance.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + ThermalInsulanceUnit parsedUnit = ThermalInsulance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Hrft²°F/Btu", ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu)] + [InlineData("cm²Hr°C/kcal", ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie)] + [InlineData("cm²K/W", ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt)] + [InlineData("m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] + [InlineData("m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] + [InlineData("m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ThermalInsulanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + ThermalInsulanceUnit parsedUnit = ThermalInsulance.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -336,7 +353,21 @@ public void ParseUnit(string abbreviation, ThermalInsulanceUnit expectedUnit) [InlineData("en-US", "m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] [InlineData("en-US", "m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] [InlineData("en-US", "m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] - public void ParseUnitWithCulture(string culture, string abbreviation, ThermalInsulanceUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, ThermalInsulanceUnit expectedUnit) + { + using var _ = new CultureScope(culture); + ThermalInsulanceUnit parsedUnit = ThermalInsulance.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Hrft²°F/Btu", ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu)] + [InlineData("en-US", "cm²Hr°C/kcal", ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie)] + [InlineData("en-US", "cm²K/W", ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt)] + [InlineData("en-US", "m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] + [InlineData("en-US", "m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] + [InlineData("en-US", "m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] + public void ParseUnit_WithCulture(string culture, string abbreviation, ThermalInsulanceUnit expectedUnit) { ThermalInsulanceUnit parsedUnit = ThermalInsulance.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -349,9 +380,39 @@ public void ParseUnitWithCulture(string culture, string abbreviation, ThermalIns [InlineData("m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] [InlineData("m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] [InlineData("m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] - public void TryParseUnit(string abbreviation, ThermalInsulanceUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, ThermalInsulanceUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(ThermalInsulance.TryParseUnit(abbreviation, out ThermalInsulanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("Hrft²°F/Btu", ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu)] + [InlineData("cm²Hr°C/kcal", ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie)] + [InlineData("cm²K/W", ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt)] + [InlineData("m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] + [InlineData("m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] + [InlineData("m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, ThermalInsulanceUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(ThermalInsulance.TryParseUnit(abbreviation, out ThermalInsulanceUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "Hrft²°F/Btu", ThermalInsulanceUnit.HourSquareFeetDegreeFahrenheitPerBtu)] + [InlineData("en-US", "cm²Hr°C/kcal", ThermalInsulanceUnit.SquareCentimeterHourDegreeCelsiusPerKilocalorie)] + [InlineData("en-US", "cm²K/W", ThermalInsulanceUnit.SquareCentimeterKelvinPerWatt)] + [InlineData("en-US", "m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] + [InlineData("en-US", "m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] + [InlineData("en-US", "m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, ThermalInsulanceUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(ThermalInsulance.TryParseUnit(abbreviation, out ThermalInsulanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -363,7 +424,7 @@ public void TryParseUnit(string abbreviation, ThermalInsulanceUnit expectedUnit) [InlineData("en-US", "m²°C/W", ThermalInsulanceUnit.SquareMeterDegreeCelsiusPerWatt)] [InlineData("en-US", "m²K/kW", ThermalInsulanceUnit.SquareMeterKelvinPerKilowatt)] [InlineData("en-US", "m²K/W", ThermalInsulanceUnit.SquareMeterKelvinPerWatt)] - public void TryParseUnitWithCulture(string culture, string abbreviation, ThermalInsulanceUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, ThermalInsulanceUnit expectedUnit) { Assert.True(ThermalInsulance.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out ThermalInsulanceUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs index 866544f56e..0320185601 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TorqueTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -817,10 +818,81 @@ public void TryParse() [InlineData("tf·cm", TorqueUnit.TonneForceCentimeter)] [InlineData("tf·m", TorqueUnit.TonneForceMeter)] [InlineData("tf·mm", TorqueUnit.TonneForceMillimeter)] - public void ParseUnit(string abbreviation, TorqueUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TorqueUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - TorqueUnit parsedUnit = Torque.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + TorqueUnit parsedUnit = Torque.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("gf·cm", TorqueUnit.GramForceCentimeter)] + [InlineData("gf·m", TorqueUnit.GramForceMeter)] + [InlineData("gf·mm", TorqueUnit.GramForceMillimeter)] + [InlineData("kgf·cm", TorqueUnit.KilogramForceCentimeter)] + [InlineData("kgf·m", TorqueUnit.KilogramForceMeter)] + [InlineData("kgf·mm", TorqueUnit.KilogramForceMillimeter)] + [InlineData("kN·cm", TorqueUnit.KilonewtonCentimeter)] + [InlineData("kN·m", TorqueUnit.KilonewtonMeter)] + [InlineData("kN·mm", TorqueUnit.KilonewtonMillimeter)] + [InlineData("kipf·ft", TorqueUnit.KilopoundForceFoot)] + [InlineData("kipf·in", TorqueUnit.KilopoundForceInch)] + [InlineData("MN·cm", TorqueUnit.MeganewtonCentimeter)] + [InlineData("MN·m", TorqueUnit.MeganewtonMeter)] + [InlineData("MN·mm", TorqueUnit.MeganewtonMillimeter)] + [InlineData("Mlbf·ft", TorqueUnit.MegapoundForceFoot)] + [InlineData("Mlbf·in", TorqueUnit.MegapoundForceInch)] + [InlineData("N·cm", TorqueUnit.NewtonCentimeter)] + [InlineData("N·m", TorqueUnit.NewtonMeter)] + [InlineData("N·mm", TorqueUnit.NewtonMillimeter)] + [InlineData("pdl·ft", TorqueUnit.PoundalFoot)] + [InlineData("lbf·ft", TorqueUnit.PoundForceFoot)] + [InlineData("lbf·in", TorqueUnit.PoundForceInch)] + [InlineData("tf·cm", TorqueUnit.TonneForceCentimeter)] + [InlineData("tf·m", TorqueUnit.TonneForceMeter)] + [InlineData("tf·mm", TorqueUnit.TonneForceMillimeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TorqueUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + TorqueUnit parsedUnit = Torque.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "gf·cm", TorqueUnit.GramForceCentimeter)] + [InlineData("en-US", "gf·m", TorqueUnit.GramForceMeter)] + [InlineData("en-US", "gf·mm", TorqueUnit.GramForceMillimeter)] + [InlineData("en-US", "kgf·cm", TorqueUnit.KilogramForceCentimeter)] + [InlineData("en-US", "kgf·m", TorqueUnit.KilogramForceMeter)] + [InlineData("en-US", "kgf·mm", TorqueUnit.KilogramForceMillimeter)] + [InlineData("en-US", "kN·cm", TorqueUnit.KilonewtonCentimeter)] + [InlineData("en-US", "kN·m", TorqueUnit.KilonewtonMeter)] + [InlineData("en-US", "kN·mm", TorqueUnit.KilonewtonMillimeter)] + [InlineData("en-US", "kipf·ft", TorqueUnit.KilopoundForceFoot)] + [InlineData("en-US", "kipf·in", TorqueUnit.KilopoundForceInch)] + [InlineData("en-US", "MN·cm", TorqueUnit.MeganewtonCentimeter)] + [InlineData("en-US", "MN·m", TorqueUnit.MeganewtonMeter)] + [InlineData("en-US", "MN·mm", TorqueUnit.MeganewtonMillimeter)] + [InlineData("en-US", "Mlbf·ft", TorqueUnit.MegapoundForceFoot)] + [InlineData("en-US", "Mlbf·in", TorqueUnit.MegapoundForceInch)] + [InlineData("en-US", "N·cm", TorqueUnit.NewtonCentimeter)] + [InlineData("en-US", "N·m", TorqueUnit.NewtonMeter)] + [InlineData("en-US", "N·mm", TorqueUnit.NewtonMillimeter)] + [InlineData("en-US", "pdl·ft", TorqueUnit.PoundalFoot)] + [InlineData("en-US", "lbf·ft", TorqueUnit.PoundForceFoot)] + [InlineData("en-US", "lbf·in", TorqueUnit.PoundForceInch)] + [InlineData("en-US", "tf·cm", TorqueUnit.TonneForceCentimeter)] + [InlineData("en-US", "tf·m", TorqueUnit.TonneForceMeter)] + [InlineData("en-US", "tf·mm", TorqueUnit.TonneForceMillimeter)] + [InlineData("ru-RU", "кН·м", TorqueUnit.KilonewtonMeter)] + [InlineData("ru-RU", "МН·м", TorqueUnit.MeganewtonMeter)] + [InlineData("ru-RU", "Н·м", TorqueUnit.NewtonMeter)] + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, TorqueUnit expectedUnit) + { + using var _ = new CultureScope(culture); + TorqueUnit parsedUnit = Torque.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -853,7 +925,7 @@ public void ParseUnit(string abbreviation, TorqueUnit expectedUnit) [InlineData("ru-RU", "кН·м", TorqueUnit.KilonewtonMeter)] [InlineData("ru-RU", "МН·м", TorqueUnit.MeganewtonMeter)] [InlineData("ru-RU", "Н·м", TorqueUnit.NewtonMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, TorqueUnit expectedUnit) + public void ParseUnit_WithCulture(string culture, string abbreviation, TorqueUnit expectedUnit) { TorqueUnit parsedUnit = Torque.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -885,9 +957,80 @@ public void ParseUnitWithCulture(string culture, string abbreviation, TorqueUnit [InlineData("tf·cm", TorqueUnit.TonneForceCentimeter)] [InlineData("tf·m", TorqueUnit.TonneForceMeter)] [InlineData("tf·mm", TorqueUnit.TonneForceMillimeter)] - public void TryParseUnit(string abbreviation, TorqueUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TorqueUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Torque.TryParseUnit(abbreviation, out TorqueUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("gf·cm", TorqueUnit.GramForceCentimeter)] + [InlineData("gf·m", TorqueUnit.GramForceMeter)] + [InlineData("gf·mm", TorqueUnit.GramForceMillimeter)] + [InlineData("kgf·cm", TorqueUnit.KilogramForceCentimeter)] + [InlineData("kgf·m", TorqueUnit.KilogramForceMeter)] + [InlineData("kgf·mm", TorqueUnit.KilogramForceMillimeter)] + [InlineData("kN·cm", TorqueUnit.KilonewtonCentimeter)] + [InlineData("kN·m", TorqueUnit.KilonewtonMeter)] + [InlineData("kN·mm", TorqueUnit.KilonewtonMillimeter)] + [InlineData("kipf·ft", TorqueUnit.KilopoundForceFoot)] + [InlineData("kipf·in", TorqueUnit.KilopoundForceInch)] + [InlineData("MN·cm", TorqueUnit.MeganewtonCentimeter)] + [InlineData("MN·m", TorqueUnit.MeganewtonMeter)] + [InlineData("MN·mm", TorqueUnit.MeganewtonMillimeter)] + [InlineData("Mlbf·ft", TorqueUnit.MegapoundForceFoot)] + [InlineData("Mlbf·in", TorqueUnit.MegapoundForceInch)] + [InlineData("N·cm", TorqueUnit.NewtonCentimeter)] + [InlineData("N·m", TorqueUnit.NewtonMeter)] + [InlineData("N·mm", TorqueUnit.NewtonMillimeter)] + [InlineData("pdl·ft", TorqueUnit.PoundalFoot)] + [InlineData("lbf·ft", TorqueUnit.PoundForceFoot)] + [InlineData("lbf·in", TorqueUnit.PoundForceInch)] + [InlineData("tf·cm", TorqueUnit.TonneForceCentimeter)] + [InlineData("tf·m", TorqueUnit.TonneForceMeter)] + [InlineData("tf·mm", TorqueUnit.TonneForceMillimeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TorqueUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Torque.TryParseUnit(abbreviation, out TorqueUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "gf·cm", TorqueUnit.GramForceCentimeter)] + [InlineData("en-US", "gf·m", TorqueUnit.GramForceMeter)] + [InlineData("en-US", "gf·mm", TorqueUnit.GramForceMillimeter)] + [InlineData("en-US", "kgf·cm", TorqueUnit.KilogramForceCentimeter)] + [InlineData("en-US", "kgf·m", TorqueUnit.KilogramForceMeter)] + [InlineData("en-US", "kgf·mm", TorqueUnit.KilogramForceMillimeter)] + [InlineData("en-US", "kN·cm", TorqueUnit.KilonewtonCentimeter)] + [InlineData("en-US", "kN·m", TorqueUnit.KilonewtonMeter)] + [InlineData("en-US", "kN·mm", TorqueUnit.KilonewtonMillimeter)] + [InlineData("en-US", "kipf·ft", TorqueUnit.KilopoundForceFoot)] + [InlineData("en-US", "kipf·in", TorqueUnit.KilopoundForceInch)] + [InlineData("en-US", "MN·cm", TorqueUnit.MeganewtonCentimeter)] + [InlineData("en-US", "MN·m", TorqueUnit.MeganewtonMeter)] + [InlineData("en-US", "MN·mm", TorqueUnit.MeganewtonMillimeter)] + [InlineData("en-US", "Mlbf·ft", TorqueUnit.MegapoundForceFoot)] + [InlineData("en-US", "Mlbf·in", TorqueUnit.MegapoundForceInch)] + [InlineData("en-US", "N·cm", TorqueUnit.NewtonCentimeter)] + [InlineData("en-US", "N·m", TorqueUnit.NewtonMeter)] + [InlineData("en-US", "N·mm", TorqueUnit.NewtonMillimeter)] + [InlineData("en-US", "pdl·ft", TorqueUnit.PoundalFoot)] + [InlineData("en-US", "lbf·ft", TorqueUnit.PoundForceFoot)] + [InlineData("en-US", "lbf·in", TorqueUnit.PoundForceInch)] + [InlineData("en-US", "tf·cm", TorqueUnit.TonneForceCentimeter)] + [InlineData("en-US", "tf·m", TorqueUnit.TonneForceMeter)] + [InlineData("en-US", "tf·mm", TorqueUnit.TonneForceMillimeter)] + [InlineData("ru-RU", "кН·м", TorqueUnit.KilonewtonMeter)] + [InlineData("ru-RU", "МН·м", TorqueUnit.MeganewtonMeter)] + [InlineData("ru-RU", "Н·м", TorqueUnit.NewtonMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, TorqueUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Torque.TryParseUnit(abbreviation, out TorqueUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -921,7 +1064,7 @@ public void TryParseUnit(string abbreviation, TorqueUnit expectedUnit) [InlineData("ru-RU", "кН·м", TorqueUnit.KilonewtonMeter)] [InlineData("ru-RU", "МН·м", TorqueUnit.MeganewtonMeter)] [InlineData("ru-RU", "Н·м", TorqueUnit.NewtonMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, TorqueUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, TorqueUnit expectedUnit) { Assert.True(Torque.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TorqueUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs index af7eaa3075..5e2d6e9319 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/TurbidityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("NTU", TurbidityUnit.NTU)] - public void ParseUnit(string abbreviation, TurbidityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TurbidityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - TurbidityUnit parsedUnit = Turbidity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + TurbidityUnit parsedUnit = Turbidity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("NTU", TurbidityUnit.NTU)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TurbidityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + TurbidityUnit parsedUnit = Turbidity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "NTU", TurbidityUnit.NTU)] - public void ParseUnitWithCulture(string culture, string abbreviation, TurbidityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, TurbidityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + TurbidityUnit parsedUnit = Turbidity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "NTU", TurbidityUnit.NTU)] + public void ParseUnit_WithCulture(string culture, string abbreviation, TurbidityUnit expectedUnit) { TurbidityUnit parsedUnit = Turbidity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, TurbidityU [Theory] [InlineData("NTU", TurbidityUnit.NTU)] - public void TryParseUnit(string abbreviation, TurbidityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, TurbidityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Turbidity.TryParseUnit(abbreviation, out TurbidityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("NTU", TurbidityUnit.NTU)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, TurbidityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(Turbidity.TryParseUnit(abbreviation, out TurbidityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "NTU", TurbidityUnit.NTU)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, TurbidityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Turbidity.TryParseUnit(abbreviation, out TurbidityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "NTU", TurbidityUnit.NTU)] - public void TryParseUnitWithCulture(string culture, string abbreviation, TurbidityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, TurbidityUnit expectedUnit) { Assert.True(Turbidity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out TurbidityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs index 21051c7b88..5cbd0c931d 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VitaminATestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -202,16 +203,36 @@ public void TryParse() [Theory] [InlineData("IU", VitaminAUnit.InternationalUnit)] - public void ParseUnit(string abbreviation, VitaminAUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VitaminAUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - VitaminAUnit parsedUnit = VitaminA.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + VitaminAUnit parsedUnit = VitaminA.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("IU", VitaminAUnit.InternationalUnit)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VitaminAUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + VitaminAUnit parsedUnit = VitaminA.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "IU", VitaminAUnit.InternationalUnit)] - public void ParseUnitWithCulture(string culture, string abbreviation, VitaminAUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, VitaminAUnit expectedUnit) + { + using var _ = new CultureScope(culture); + VitaminAUnit parsedUnit = VitaminA.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "IU", VitaminAUnit.InternationalUnit)] + public void ParseUnit_WithCulture(string culture, string abbreviation, VitaminAUnit expectedUnit) { VitaminAUnit parsedUnit = VitaminA.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -219,16 +240,36 @@ public void ParseUnitWithCulture(string culture, string abbreviation, VitaminAUn [Theory] [InlineData("IU", VitaminAUnit.InternationalUnit)] - public void TryParseUnit(string abbreviation, VitaminAUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VitaminAUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(VitaminA.TryParseUnit(abbreviation, out VitaminAUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("IU", VitaminAUnit.InternationalUnit)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VitaminAUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(VitaminA.TryParseUnit(abbreviation, out VitaminAUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "IU", VitaminAUnit.InternationalUnit)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, VitaminAUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(VitaminA.TryParseUnit(abbreviation, out VitaminAUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "IU", VitaminAUnit.InternationalUnit)] - public void TryParseUnitWithCulture(string culture, string abbreviation, VitaminAUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, VitaminAUnit expectedUnit) { Assert.True(VitaminA.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VitaminAUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs index 3c1afc54fa..2f303269c8 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeConcentrationTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -672,10 +673,41 @@ public void TryParse() [InlineData("% (v/v)", VolumeConcentrationUnit.Percent)] [InlineData("pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] [InlineData("pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] - public void ParseUnit(string abbreviation, VolumeConcentrationUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeConcentrationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - VolumeConcentrationUnit parsedUnit = VolumeConcentration.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + VolumeConcentrationUnit parsedUnit = VolumeConcentration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cl/l", VolumeConcentrationUnit.CentilitersPerLiter)] + [InlineData("cl/ml", VolumeConcentrationUnit.CentilitersPerMililiter)] + [InlineData("dl/l", VolumeConcentrationUnit.DecilitersPerLiter)] + [InlineData("dl/ml", VolumeConcentrationUnit.DecilitersPerMililiter)] + [InlineData("", VolumeConcentrationUnit.DecimalFraction)] + [InlineData("l/l", VolumeConcentrationUnit.LitersPerLiter)] + [InlineData("l/ml", VolumeConcentrationUnit.LitersPerMililiter)] + [InlineData("µl/l", VolumeConcentrationUnit.MicrolitersPerLiter)] + [InlineData("µl/ml", VolumeConcentrationUnit.MicrolitersPerMililiter)] + [InlineData("ml/l", VolumeConcentrationUnit.MillilitersPerLiter)] + [InlineData("ml/ml", VolumeConcentrationUnit.MillilitersPerMililiter)] + [InlineData("nl/l", VolumeConcentrationUnit.NanolitersPerLiter)] + [InlineData("nl/ml", VolumeConcentrationUnit.NanolitersPerMililiter)] + [InlineData("ppb", VolumeConcentrationUnit.PartPerBillion)] + [InlineData("ppm", VolumeConcentrationUnit.PartPerMillion)] + [InlineData("‰", VolumeConcentrationUnit.PartPerThousand)] + [InlineData("ppt", VolumeConcentrationUnit.PartPerTrillion)] + [InlineData("%", VolumeConcentrationUnit.Percent)] + [InlineData("% (v/v)", VolumeConcentrationUnit.Percent)] + [InlineData("pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] + [InlineData("pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumeConcentrationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + VolumeConcentrationUnit parsedUnit = VolumeConcentration.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -701,7 +733,36 @@ public void ParseUnit(string abbreviation, VolumeConcentrationUnit expectedUnit) [InlineData("en-US", "% (v/v)", VolumeConcentrationUnit.Percent)] [InlineData("en-US", "pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] [InlineData("en-US", "pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] - public void ParseUnitWithCulture(string culture, string abbreviation, VolumeConcentrationUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumeConcentrationUnit expectedUnit) + { + using var _ = new CultureScope(culture); + VolumeConcentrationUnit parsedUnit = VolumeConcentration.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cl/l", VolumeConcentrationUnit.CentilitersPerLiter)] + [InlineData("en-US", "cl/ml", VolumeConcentrationUnit.CentilitersPerMililiter)] + [InlineData("en-US", "dl/l", VolumeConcentrationUnit.DecilitersPerLiter)] + [InlineData("en-US", "dl/ml", VolumeConcentrationUnit.DecilitersPerMililiter)] + [InlineData("en-US", "", VolumeConcentrationUnit.DecimalFraction)] + [InlineData("en-US", "l/l", VolumeConcentrationUnit.LitersPerLiter)] + [InlineData("en-US", "l/ml", VolumeConcentrationUnit.LitersPerMililiter)] + [InlineData("en-US", "µl/l", VolumeConcentrationUnit.MicrolitersPerLiter)] + [InlineData("en-US", "µl/ml", VolumeConcentrationUnit.MicrolitersPerMililiter)] + [InlineData("en-US", "ml/l", VolumeConcentrationUnit.MillilitersPerLiter)] + [InlineData("en-US", "ml/ml", VolumeConcentrationUnit.MillilitersPerMililiter)] + [InlineData("en-US", "nl/l", VolumeConcentrationUnit.NanolitersPerLiter)] + [InlineData("en-US", "nl/ml", VolumeConcentrationUnit.NanolitersPerMililiter)] + [InlineData("en-US", "ppb", VolumeConcentrationUnit.PartPerBillion)] + [InlineData("en-US", "ppm", VolumeConcentrationUnit.PartPerMillion)] + [InlineData("en-US", "‰", VolumeConcentrationUnit.PartPerThousand)] + [InlineData("en-US", "ppt", VolumeConcentrationUnit.PartPerTrillion)] + [InlineData("en-US", "%", VolumeConcentrationUnit.Percent)] + [InlineData("en-US", "% (v/v)", VolumeConcentrationUnit.Percent)] + [InlineData("en-US", "pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] + [InlineData("en-US", "pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, VolumeConcentrationUnit expectedUnit) { VolumeConcentrationUnit parsedUnit = VolumeConcentration.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -729,9 +790,69 @@ public void ParseUnitWithCulture(string culture, string abbreviation, VolumeConc [InlineData("% (v/v)", VolumeConcentrationUnit.Percent)] [InlineData("pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] [InlineData("pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] - public void TryParseUnit(string abbreviation, VolumeConcentrationUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeConcentrationUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(VolumeConcentration.TryParseUnit(abbreviation, out VolumeConcentrationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cl/l", VolumeConcentrationUnit.CentilitersPerLiter)] + [InlineData("cl/ml", VolumeConcentrationUnit.CentilitersPerMililiter)] + [InlineData("dl/l", VolumeConcentrationUnit.DecilitersPerLiter)] + [InlineData("dl/ml", VolumeConcentrationUnit.DecilitersPerMililiter)] + [InlineData("", VolumeConcentrationUnit.DecimalFraction)] + [InlineData("l/l", VolumeConcentrationUnit.LitersPerLiter)] + [InlineData("l/ml", VolumeConcentrationUnit.LitersPerMililiter)] + [InlineData("µl/l", VolumeConcentrationUnit.MicrolitersPerLiter)] + [InlineData("µl/ml", VolumeConcentrationUnit.MicrolitersPerMililiter)] + [InlineData("ml/l", VolumeConcentrationUnit.MillilitersPerLiter)] + [InlineData("ml/ml", VolumeConcentrationUnit.MillilitersPerMililiter)] + [InlineData("nl/l", VolumeConcentrationUnit.NanolitersPerLiter)] + [InlineData("nl/ml", VolumeConcentrationUnit.NanolitersPerMililiter)] + [InlineData("ppb", VolumeConcentrationUnit.PartPerBillion)] + [InlineData("ppm", VolumeConcentrationUnit.PartPerMillion)] + [InlineData("‰", VolumeConcentrationUnit.PartPerThousand)] + [InlineData("ppt", VolumeConcentrationUnit.PartPerTrillion)] + [InlineData("%", VolumeConcentrationUnit.Percent)] + [InlineData("% (v/v)", VolumeConcentrationUnit.Percent)] + [InlineData("pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] + [InlineData("pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumeConcentrationUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(VolumeConcentration.TryParseUnit(abbreviation, out VolumeConcentrationUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cl/l", VolumeConcentrationUnit.CentilitersPerLiter)] + [InlineData("en-US", "cl/ml", VolumeConcentrationUnit.CentilitersPerMililiter)] + [InlineData("en-US", "dl/l", VolumeConcentrationUnit.DecilitersPerLiter)] + [InlineData("en-US", "dl/ml", VolumeConcentrationUnit.DecilitersPerMililiter)] + [InlineData("en-US", "", VolumeConcentrationUnit.DecimalFraction)] + [InlineData("en-US", "l/l", VolumeConcentrationUnit.LitersPerLiter)] + [InlineData("en-US", "l/ml", VolumeConcentrationUnit.LitersPerMililiter)] + [InlineData("en-US", "µl/l", VolumeConcentrationUnit.MicrolitersPerLiter)] + [InlineData("en-US", "µl/ml", VolumeConcentrationUnit.MicrolitersPerMililiter)] + [InlineData("en-US", "ml/l", VolumeConcentrationUnit.MillilitersPerLiter)] + [InlineData("en-US", "ml/ml", VolumeConcentrationUnit.MillilitersPerMililiter)] + [InlineData("en-US", "nl/l", VolumeConcentrationUnit.NanolitersPerLiter)] + [InlineData("en-US", "nl/ml", VolumeConcentrationUnit.NanolitersPerMililiter)] + [InlineData("en-US", "ppb", VolumeConcentrationUnit.PartPerBillion)] + [InlineData("en-US", "ppm", VolumeConcentrationUnit.PartPerMillion)] + [InlineData("en-US", "‰", VolumeConcentrationUnit.PartPerThousand)] + [InlineData("en-US", "ppt", VolumeConcentrationUnit.PartPerTrillion)] + [InlineData("en-US", "%", VolumeConcentrationUnit.Percent)] + [InlineData("en-US", "% (v/v)", VolumeConcentrationUnit.Percent)] + [InlineData("en-US", "pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] + [InlineData("en-US", "pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumeConcentrationUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(VolumeConcentration.TryParseUnit(abbreviation, out VolumeConcentrationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -758,7 +879,7 @@ public void TryParseUnit(string abbreviation, VolumeConcentrationUnit expectedUn [InlineData("en-US", "% (v/v)", VolumeConcentrationUnit.Percent)] [InlineData("en-US", "pl/l", VolumeConcentrationUnit.PicolitersPerLiter)] [InlineData("en-US", "pl/ml", VolumeConcentrationUnit.PicolitersPerMililiter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, VolumeConcentrationUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, VolumeConcentrationUnit expectedUnit) { Assert.True(VolumeConcentration.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumeConcentrationUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs index 988677a08b..fc351125a6 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowPerAreaTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -226,17 +227,39 @@ public void TryParse() [Theory] [InlineData("CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] [InlineData("m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] - public void ParseUnit(string abbreviation, VolumeFlowPerAreaUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeFlowPerAreaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - VolumeFlowPerAreaUnit parsedUnit = VolumeFlowPerArea.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + VolumeFlowPerAreaUnit parsedUnit = VolumeFlowPerArea.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] + [InlineData("m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumeFlowPerAreaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + VolumeFlowPerAreaUnit parsedUnit = VolumeFlowPerArea.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] [InlineData("en-US", "CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] [InlineData("en-US", "m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] - public void ParseUnitWithCulture(string culture, string abbreviation, VolumeFlowPerAreaUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumeFlowPerAreaUnit expectedUnit) + { + using var _ = new CultureScope(culture); + VolumeFlowPerAreaUnit parsedUnit = VolumeFlowPerArea.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] + [InlineData("en-US", "m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] + public void ParseUnit_WithCulture(string culture, string abbreviation, VolumeFlowPerAreaUnit expectedUnit) { VolumeFlowPerAreaUnit parsedUnit = VolumeFlowPerArea.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -245,9 +268,31 @@ public void ParseUnitWithCulture(string culture, string abbreviation, VolumeFlow [Theory] [InlineData("CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] [InlineData("m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] - public void TryParseUnit(string abbreviation, VolumeFlowPerAreaUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeFlowPerAreaUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(VolumeFlowPerArea.TryParseUnit(abbreviation, out VolumeFlowPerAreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] + [InlineData("m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumeFlowPerAreaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(VolumeFlowPerArea.TryParseUnit(abbreviation, out VolumeFlowPerAreaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] + [InlineData("en-US", "m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumeFlowPerAreaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(VolumeFlowPerArea.TryParseUnit(abbreviation, out VolumeFlowPerAreaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -255,7 +300,7 @@ public void TryParseUnit(string abbreviation, VolumeFlowPerAreaUnit expectedUnit [Theory] [InlineData("en-US", "CFM/ft²", VolumeFlowPerAreaUnit.CubicFootPerMinutePerSquareFoot)] [InlineData("en-US", "m³/(s·m²)", VolumeFlowPerAreaUnit.CubicMeterPerSecondPerSquareMeter)] - public void TryParseUnitWithCulture(string culture, string abbreviation, VolumeFlowPerAreaUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, VolumeFlowPerAreaUnit expectedUnit) { Assert.True(VolumeFlowPerArea.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumeFlowPerAreaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs index 659c56203f..fe428b7829 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeFlowTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -3128,10 +3129,154 @@ public void TryParse() [InlineData("gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute)] [InlineData("GPM", VolumeFlowUnit.UsGallonPerMinute)] [InlineData("gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond)] - public void ParseUnit(string abbreviation, VolumeFlowUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeFlowUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - VolumeFlowUnit parsedUnit = VolumeFlow.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + VolumeFlowUnit parsedUnit = VolumeFlow.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("af/d", VolumeFlowUnit.AcreFootPerDay)] + [InlineData("af/h", VolumeFlowUnit.AcreFootPerHour)] + [InlineData("af/m", VolumeFlowUnit.AcreFootPerMinute)] + [InlineData("af/s", VolumeFlowUnit.AcreFootPerSecond)] + [InlineData("cl/day", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cl/d", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cLPD", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cl/h", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("cLPH", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("cl/min", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("cLPM", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("cl/s", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("cLPS", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("ft³/h", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("cf/hr", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("ft³/min", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("CFM", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("ft³/s", VolumeFlowUnit.CubicFootPerSecond)] + [InlineData("m³/d", VolumeFlowUnit.CubicMeterPerDay)] + [InlineData("m³/h", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("m³/min", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("m³/s", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("cy/day", VolumeFlowUnit.CubicYardPerDay)] + [InlineData("yd³/h", VolumeFlowUnit.CubicYardPerHour)] + [InlineData("yd³/min", VolumeFlowUnit.CubicYardPerMinute)] + [InlineData("yd³/s", VolumeFlowUnit.CubicYardPerSecond)] + [InlineData("dal/day", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("dal/d", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("daLPD", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("dal/h", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("daLPH", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("dal/min", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("daLPM", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("dal/s", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("daLPS", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("dl/day", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dl/d", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dLPD", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dl/h", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("dLPH", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("dl/min", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("dLPM", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("dl/s", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("dLPS", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("hl/day", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hl/d", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hLPD", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hl/h", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("hLPH", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("hl/min", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("hLPM", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("hl/s", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("hLPS", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("kl/day", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kl/d", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kLPD", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kl/h", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("kLPH", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("kl/min", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("kLPM", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("kl/s", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("kLPS", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("KGPM", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("l/day", VolumeFlowUnit.LiterPerDay)] + [InlineData("l/d", VolumeFlowUnit.LiterPerDay)] + [InlineData("LPD", VolumeFlowUnit.LiterPerDay)] + [InlineData("l/h", VolumeFlowUnit.LiterPerHour)] + [InlineData("LPH", VolumeFlowUnit.LiterPerHour)] + [InlineData("l/min", VolumeFlowUnit.LiterPerMinute)] + [InlineData("LPM", VolumeFlowUnit.LiterPerMinute)] + [InlineData("l/s", VolumeFlowUnit.LiterPerSecond)] + [InlineData("LPS", VolumeFlowUnit.LiterPerSecond)] + [InlineData("Ml/day", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("Ml/d", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("MLPD", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("Ml/h", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("MLPH", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("Ml/min", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("MLPM", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("Ml/s", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("MLPS", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay)] + [InlineData("Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond)] + [InlineData("Mgpd", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("Mgal/d", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("µl/day", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µl/d", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µLPD", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µl/h", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("µLPH", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("µl/min", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("µLPM", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("µl/s", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("µLPS", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("ml/day", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("ml/d", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("mLPD", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("ml/h", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("mLPH", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("ml/min", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("mLPM", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("ml/s", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("mLPS", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("MGD", VolumeFlowUnit.MillionUsGallonPerDay)] + [InlineData("nl/day", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nl/d", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nLPD", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nl/h", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("nLPH", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("nl/min", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("nLPM", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("nl/s", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("nLPS", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("bbl/d", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("BOPD", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("bbl/hr", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("bph", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("bbl/min", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("bpm", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("bbl/s", VolumeFlowUnit.OilBarrelPerSecond)] + [InlineData("gal (U. K.)/d", VolumeFlowUnit.UkGallonPerDay)] + [InlineData("gal (imp.)/h", VolumeFlowUnit.UkGallonPerHour)] + [InlineData("gal (imp.)/min", VolumeFlowUnit.UkGallonPerMinute)] + [InlineData("gal (imp.)/s", VolumeFlowUnit.UkGallonPerSecond)] + [InlineData("gpd", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("gal/d", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("gal (U.S.)/h", VolumeFlowUnit.UsGallonPerHour)] + [InlineData("gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("GPM", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumeFlowUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + VolumeFlowUnit parsedUnit = VolumeFlow.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -3306,129 +3451,450 @@ public void ParseUnit(string abbreviation, VolumeFlowUnit expectedUnit) [InlineData("ru-RU", "нл/ч", VolumeFlowUnit.NanoliterPerHour)] [InlineData("ru-RU", "нл/мин", VolumeFlowUnit.NanoliterPerMinute)] [InlineData("ru-RU", "нл/c", VolumeFlowUnit.NanoliterPerSecond)] - public void ParseUnitWithCulture(string culture, string abbreviation, VolumeFlowUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumeFlowUnit expectedUnit) { - VolumeFlowUnit parsedUnit = VolumeFlow.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + using var _ = new CultureScope(culture); + VolumeFlowUnit parsedUnit = VolumeFlow.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } [Theory] - [InlineData("af/d", VolumeFlowUnit.AcreFootPerDay)] - [InlineData("af/h", VolumeFlowUnit.AcreFootPerHour)] - [InlineData("af/m", VolumeFlowUnit.AcreFootPerMinute)] - [InlineData("af/s", VolumeFlowUnit.AcreFootPerSecond)] - [InlineData("cl/day", VolumeFlowUnit.CentiliterPerDay)] - [InlineData("cl/d", VolumeFlowUnit.CentiliterPerDay)] - [InlineData("cLPD", VolumeFlowUnit.CentiliterPerDay)] - [InlineData("cl/h", VolumeFlowUnit.CentiliterPerHour)] - [InlineData("cLPH", VolumeFlowUnit.CentiliterPerHour)] - [InlineData("cl/min", VolumeFlowUnit.CentiliterPerMinute)] - [InlineData("cLPM", VolumeFlowUnit.CentiliterPerMinute)] - [InlineData("cl/s", VolumeFlowUnit.CentiliterPerSecond)] - [InlineData("cLPS", VolumeFlowUnit.CentiliterPerSecond)] - [InlineData("cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute)] - [InlineData("dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute)] - [InlineData("ft³/h", VolumeFlowUnit.CubicFootPerHour)] - [InlineData("cf/hr", VolumeFlowUnit.CubicFootPerHour)] - [InlineData("ft³/min", VolumeFlowUnit.CubicFootPerMinute)] - [InlineData("CFM", VolumeFlowUnit.CubicFootPerMinute)] - [InlineData("ft³/s", VolumeFlowUnit.CubicFootPerSecond)] - [InlineData("m³/d", VolumeFlowUnit.CubicMeterPerDay)] - [InlineData("m³/h", VolumeFlowUnit.CubicMeterPerHour)] - [InlineData("m³/min", VolumeFlowUnit.CubicMeterPerMinute)] - [InlineData("m³/s", VolumeFlowUnit.CubicMeterPerSecond)] - [InlineData("mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond)] - [InlineData("cy/day", VolumeFlowUnit.CubicYardPerDay)] - [InlineData("yd³/h", VolumeFlowUnit.CubicYardPerHour)] - [InlineData("yd³/min", VolumeFlowUnit.CubicYardPerMinute)] - [InlineData("yd³/s", VolumeFlowUnit.CubicYardPerSecond)] - [InlineData("dal/day", VolumeFlowUnit.DecaliterPerDay)] - [InlineData("dal/d", VolumeFlowUnit.DecaliterPerDay)] - [InlineData("daLPD", VolumeFlowUnit.DecaliterPerDay)] - [InlineData("dal/h", VolumeFlowUnit.DecaliterPerHour)] - [InlineData("daLPH", VolumeFlowUnit.DecaliterPerHour)] - [InlineData("dal/min", VolumeFlowUnit.DecaliterPerMinute)] - [InlineData("daLPM", VolumeFlowUnit.DecaliterPerMinute)] - [InlineData("dal/s", VolumeFlowUnit.DecaliterPerSecond)] - [InlineData("daLPS", VolumeFlowUnit.DecaliterPerSecond)] - [InlineData("dl/day", VolumeFlowUnit.DeciliterPerDay)] - [InlineData("dl/d", VolumeFlowUnit.DeciliterPerDay)] - [InlineData("dLPD", VolumeFlowUnit.DeciliterPerDay)] - [InlineData("dl/h", VolumeFlowUnit.DeciliterPerHour)] - [InlineData("dLPH", VolumeFlowUnit.DeciliterPerHour)] - [InlineData("dl/min", VolumeFlowUnit.DeciliterPerMinute)] - [InlineData("dLPM", VolumeFlowUnit.DeciliterPerMinute)] - [InlineData("dl/s", VolumeFlowUnit.DeciliterPerSecond)] - [InlineData("dLPS", VolumeFlowUnit.DeciliterPerSecond)] - [InlineData("hl/day", VolumeFlowUnit.HectoliterPerDay)] - [InlineData("hl/d", VolumeFlowUnit.HectoliterPerDay)] - [InlineData("hLPD", VolumeFlowUnit.HectoliterPerDay)] - [InlineData("hl/h", VolumeFlowUnit.HectoliterPerHour)] - [InlineData("hLPH", VolumeFlowUnit.HectoliterPerHour)] - [InlineData("hl/min", VolumeFlowUnit.HectoliterPerMinute)] - [InlineData("hLPM", VolumeFlowUnit.HectoliterPerMinute)] - [InlineData("hl/s", VolumeFlowUnit.HectoliterPerSecond)] - [InlineData("hLPS", VolumeFlowUnit.HectoliterPerSecond)] - [InlineData("kl/day", VolumeFlowUnit.KiloliterPerDay)] - [InlineData("kl/d", VolumeFlowUnit.KiloliterPerDay)] - [InlineData("kLPD", VolumeFlowUnit.KiloliterPerDay)] - [InlineData("kl/h", VolumeFlowUnit.KiloliterPerHour)] - [InlineData("kLPH", VolumeFlowUnit.KiloliterPerHour)] - [InlineData("kl/min", VolumeFlowUnit.KiloliterPerMinute)] - [InlineData("kLPM", VolumeFlowUnit.KiloliterPerMinute)] - [InlineData("kl/s", VolumeFlowUnit.KiloliterPerSecond)] - [InlineData("kLPS", VolumeFlowUnit.KiloliterPerSecond)] - [InlineData("kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute)] - [InlineData("KGPM", VolumeFlowUnit.KilousGallonPerMinute)] - [InlineData("l/day", VolumeFlowUnit.LiterPerDay)] - [InlineData("l/d", VolumeFlowUnit.LiterPerDay)] - [InlineData("LPD", VolumeFlowUnit.LiterPerDay)] - [InlineData("l/h", VolumeFlowUnit.LiterPerHour)] - [InlineData("LPH", VolumeFlowUnit.LiterPerHour)] - [InlineData("l/min", VolumeFlowUnit.LiterPerMinute)] - [InlineData("LPM", VolumeFlowUnit.LiterPerMinute)] - [InlineData("l/s", VolumeFlowUnit.LiterPerSecond)] - [InlineData("LPS", VolumeFlowUnit.LiterPerSecond)] - [InlineData("Ml/day", VolumeFlowUnit.MegaliterPerDay)] - [InlineData("Ml/d", VolumeFlowUnit.MegaliterPerDay)] - [InlineData("MLPD", VolumeFlowUnit.MegaliterPerDay)] - [InlineData("Ml/h", VolumeFlowUnit.MegaliterPerHour)] - [InlineData("MLPH", VolumeFlowUnit.MegaliterPerHour)] - [InlineData("Ml/min", VolumeFlowUnit.MegaliterPerMinute)] - [InlineData("MLPM", VolumeFlowUnit.MegaliterPerMinute)] - [InlineData("Ml/s", VolumeFlowUnit.MegaliterPerSecond)] - [InlineData("MLPS", VolumeFlowUnit.MegaliterPerSecond)] - [InlineData("Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay)] - [InlineData("Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond)] - [InlineData("Mgpd", VolumeFlowUnit.MegausGallonPerDay)] - [InlineData("Mgal/d", VolumeFlowUnit.MegausGallonPerDay)] - [InlineData("µl/day", VolumeFlowUnit.MicroliterPerDay)] - [InlineData("µl/d", VolumeFlowUnit.MicroliterPerDay)] - [InlineData("µLPD", VolumeFlowUnit.MicroliterPerDay)] - [InlineData("µl/h", VolumeFlowUnit.MicroliterPerHour)] - [InlineData("µLPH", VolumeFlowUnit.MicroliterPerHour)] - [InlineData("µl/min", VolumeFlowUnit.MicroliterPerMinute)] - [InlineData("µLPM", VolumeFlowUnit.MicroliterPerMinute)] - [InlineData("µl/s", VolumeFlowUnit.MicroliterPerSecond)] - [InlineData("µLPS", VolumeFlowUnit.MicroliterPerSecond)] - [InlineData("ml/day", VolumeFlowUnit.MilliliterPerDay)] - [InlineData("ml/d", VolumeFlowUnit.MilliliterPerDay)] - [InlineData("mLPD", VolumeFlowUnit.MilliliterPerDay)] - [InlineData("ml/h", VolumeFlowUnit.MilliliterPerHour)] - [InlineData("mLPH", VolumeFlowUnit.MilliliterPerHour)] - [InlineData("ml/min", VolumeFlowUnit.MilliliterPerMinute)] - [InlineData("mLPM", VolumeFlowUnit.MilliliterPerMinute)] - [InlineData("ml/s", VolumeFlowUnit.MilliliterPerSecond)] - [InlineData("mLPS", VolumeFlowUnit.MilliliterPerSecond)] - [InlineData("MGD", VolumeFlowUnit.MillionUsGallonPerDay)] - [InlineData("nl/day", VolumeFlowUnit.NanoliterPerDay)] - [InlineData("nl/d", VolumeFlowUnit.NanoliterPerDay)] - [InlineData("nLPD", VolumeFlowUnit.NanoliterPerDay)] - [InlineData("nl/h", VolumeFlowUnit.NanoliterPerHour)] - [InlineData("nLPH", VolumeFlowUnit.NanoliterPerHour)] - [InlineData("nl/min", VolumeFlowUnit.NanoliterPerMinute)] - [InlineData("nLPM", VolumeFlowUnit.NanoliterPerMinute)] - [InlineData("nl/s", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("en-US", "af/d", VolumeFlowUnit.AcreFootPerDay)] + [InlineData("en-US", "af/h", VolumeFlowUnit.AcreFootPerHour)] + [InlineData("en-US", "af/m", VolumeFlowUnit.AcreFootPerMinute)] + [InlineData("en-US", "af/s", VolumeFlowUnit.AcreFootPerSecond)] + [InlineData("en-US", "cl/day", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cl/d", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cLPD", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cl/h", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("en-US", "cLPH", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("en-US", "cl/min", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("en-US", "cLPM", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("en-US", "cl/s", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("en-US", "cLPS", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("en-US", "cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("en-US", "dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("en-US", "ft³/h", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("en-US", "cf/hr", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("en-US", "ft³/min", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("en-US", "CFM", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("en-US", "ft³/s", VolumeFlowUnit.CubicFootPerSecond)] + [InlineData("en-US", "m³/d", VolumeFlowUnit.CubicMeterPerDay)] + [InlineData("en-US", "m³/h", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("en-US", "m³/min", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("en-US", "m³/s", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("en-US", "mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("en-US", "cy/day", VolumeFlowUnit.CubicYardPerDay)] + [InlineData("en-US", "yd³/h", VolumeFlowUnit.CubicYardPerHour)] + [InlineData("en-US", "yd³/min", VolumeFlowUnit.CubicYardPerMinute)] + [InlineData("en-US", "yd³/s", VolumeFlowUnit.CubicYardPerSecond)] + [InlineData("en-US", "dal/day", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "dal/d", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "daLPD", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "dal/h", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("en-US", "daLPH", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("en-US", "dal/min", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("en-US", "daLPM", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("en-US", "dal/s", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("en-US", "daLPS", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("en-US", "dl/day", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dl/d", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dLPD", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dl/h", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("en-US", "dLPH", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("en-US", "dl/min", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("en-US", "dLPM", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("en-US", "dl/s", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("en-US", "dLPS", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("en-US", "hl/day", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hl/d", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hLPD", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hl/h", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("en-US", "hLPH", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("en-US", "hl/min", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("en-US", "hLPM", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("en-US", "hl/s", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("en-US", "hLPS", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("en-US", "kl/day", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kl/d", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kLPD", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kl/h", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("en-US", "kLPH", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("en-US", "kl/min", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("en-US", "kLPM", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("en-US", "kl/s", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("en-US", "kLPS", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("en-US", "kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("en-US", "KGPM", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("en-US", "l/day", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "l/d", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "LPD", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "l/h", VolumeFlowUnit.LiterPerHour)] + [InlineData("en-US", "LPH", VolumeFlowUnit.LiterPerHour)] + [InlineData("en-US", "l/min", VolumeFlowUnit.LiterPerMinute)] + [InlineData("en-US", "LPM", VolumeFlowUnit.LiterPerMinute)] + [InlineData("en-US", "l/s", VolumeFlowUnit.LiterPerSecond)] + [InlineData("en-US", "LPS", VolumeFlowUnit.LiterPerSecond)] + [InlineData("en-US", "Ml/day", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "Ml/d", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "MLPD", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "Ml/h", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("en-US", "MLPH", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("en-US", "Ml/min", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("en-US", "MLPM", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("en-US", "Ml/s", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("en-US", "MLPS", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("en-US", "Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay)] + [InlineData("en-US", "Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond)] + [InlineData("en-US", "Mgpd", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("en-US", "Mgal/d", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("en-US", "µl/day", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µl/d", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µLPD", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µl/h", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("en-US", "µLPH", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("en-US", "µl/min", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("en-US", "µLPM", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("en-US", "µl/s", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("en-US", "µLPS", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("en-US", "ml/day", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "ml/d", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "mLPD", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "ml/h", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("en-US", "mLPH", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("en-US", "ml/min", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("en-US", "mLPM", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("en-US", "ml/s", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("en-US", "mLPS", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("en-US", "MGD", VolumeFlowUnit.MillionUsGallonPerDay)] + [InlineData("en-US", "nl/day", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nl/d", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nLPD", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nl/h", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("en-US", "nLPH", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("en-US", "nl/min", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("en-US", "nLPM", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("en-US", "nl/s", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("en-US", "nLPS", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("en-US", "bbl/d", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("en-US", "BOPD", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("en-US", "bbl/hr", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("en-US", "bph", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("en-US", "bbl/min", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("en-US", "bpm", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("en-US", "bbl/s", VolumeFlowUnit.OilBarrelPerSecond)] + [InlineData("en-US", "gal (U. K.)/d", VolumeFlowUnit.UkGallonPerDay)] + [InlineData("en-US", "gal (imp.)/h", VolumeFlowUnit.UkGallonPerHour)] + [InlineData("en-US", "gal (imp.)/min", VolumeFlowUnit.UkGallonPerMinute)] + [InlineData("en-US", "gal (imp.)/s", VolumeFlowUnit.UkGallonPerSecond)] + [InlineData("en-US", "gpd", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("en-US", "gal/d", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("en-US", "gal (U.S.)/h", VolumeFlowUnit.UsGallonPerHour)] + [InlineData("en-US", "gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("en-US", "GPM", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("en-US", "gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond)] + [InlineData("ru-RU", "сл/ч", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("ru-RU", "сл/мин", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("ru-RU", "сл/c", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("ru-RU", "см³/мин", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("ru-RU", "дм³/мин", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("ru-RU", "м³/ч", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("ru-RU", "м³/мин", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("ru-RU", "м³/с", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("ru-RU", "мм³/с", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("ru-RU", "дал/ч", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("ru-RU", "дал/мин", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("ru-RU", "дал/c", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("ru-RU", "дл/ч", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("ru-RU", "дл/мин", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("ru-RU", "дл/c", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("ru-RU", "гл/ч", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("ru-RU", "гл/мин", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("ru-RU", "гл/c", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("ru-RU", "кл/ч", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("ru-RU", "кл/мин", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("ru-RU", "кл/c", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("ru-RU", "л/ч", VolumeFlowUnit.LiterPerHour)] + [InlineData("ru-RU", "л/мин", VolumeFlowUnit.LiterPerMinute)] + [InlineData("ru-RU", "л/c", VolumeFlowUnit.LiterPerSecond)] + [InlineData("ru-RU", "Мл/ч", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("ru-RU", "Мл/мин", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("ru-RU", "Мл/c", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("ru-RU", "мкл/ч", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("ru-RU", "мкл/мин", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("ru-RU", "мкл/c", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("ru-RU", "мл/ч", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("ru-RU", "мл/мин", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("ru-RU", "мл/c", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("ru-RU", "нл/ч", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("ru-RU", "нл/мин", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("ru-RU", "нл/c", VolumeFlowUnit.NanoliterPerSecond)] + public void ParseUnit_WithCulture(string culture, string abbreviation, VolumeFlowUnit expectedUnit) + { + VolumeFlowUnit parsedUnit = VolumeFlow.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("af/d", VolumeFlowUnit.AcreFootPerDay)] + [InlineData("af/h", VolumeFlowUnit.AcreFootPerHour)] + [InlineData("af/m", VolumeFlowUnit.AcreFootPerMinute)] + [InlineData("af/s", VolumeFlowUnit.AcreFootPerSecond)] + [InlineData("cl/day", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cl/d", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cLPD", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cl/h", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("cLPH", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("cl/min", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("cLPM", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("cl/s", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("cLPS", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("ft³/h", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("cf/hr", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("ft³/min", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("CFM", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("ft³/s", VolumeFlowUnit.CubicFootPerSecond)] + [InlineData("m³/d", VolumeFlowUnit.CubicMeterPerDay)] + [InlineData("m³/h", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("m³/min", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("m³/s", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("cy/day", VolumeFlowUnit.CubicYardPerDay)] + [InlineData("yd³/h", VolumeFlowUnit.CubicYardPerHour)] + [InlineData("yd³/min", VolumeFlowUnit.CubicYardPerMinute)] + [InlineData("yd³/s", VolumeFlowUnit.CubicYardPerSecond)] + [InlineData("dal/day", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("dal/d", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("daLPD", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("dal/h", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("daLPH", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("dal/min", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("daLPM", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("dal/s", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("daLPS", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("dl/day", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dl/d", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dLPD", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dl/h", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("dLPH", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("dl/min", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("dLPM", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("dl/s", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("dLPS", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("hl/day", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hl/d", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hLPD", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hl/h", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("hLPH", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("hl/min", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("hLPM", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("hl/s", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("hLPS", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("kl/day", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kl/d", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kLPD", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kl/h", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("kLPH", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("kl/min", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("kLPM", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("kl/s", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("kLPS", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("KGPM", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("l/day", VolumeFlowUnit.LiterPerDay)] + [InlineData("l/d", VolumeFlowUnit.LiterPerDay)] + [InlineData("LPD", VolumeFlowUnit.LiterPerDay)] + [InlineData("l/h", VolumeFlowUnit.LiterPerHour)] + [InlineData("LPH", VolumeFlowUnit.LiterPerHour)] + [InlineData("l/min", VolumeFlowUnit.LiterPerMinute)] + [InlineData("LPM", VolumeFlowUnit.LiterPerMinute)] + [InlineData("l/s", VolumeFlowUnit.LiterPerSecond)] + [InlineData("LPS", VolumeFlowUnit.LiterPerSecond)] + [InlineData("Ml/day", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("Ml/d", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("MLPD", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("Ml/h", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("MLPH", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("Ml/min", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("MLPM", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("Ml/s", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("MLPS", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay)] + [InlineData("Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond)] + [InlineData("Mgpd", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("Mgal/d", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("µl/day", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µl/d", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µLPD", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µl/h", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("µLPH", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("µl/min", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("µLPM", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("µl/s", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("µLPS", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("ml/day", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("ml/d", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("mLPD", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("ml/h", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("mLPH", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("ml/min", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("mLPM", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("ml/s", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("mLPS", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("MGD", VolumeFlowUnit.MillionUsGallonPerDay)] + [InlineData("nl/day", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nl/d", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nLPD", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nl/h", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("nLPH", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("nl/min", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("nLPM", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("nl/s", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("nLPS", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("bbl/d", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("BOPD", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("bbl/hr", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("bph", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("bbl/min", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("bpm", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("bbl/s", VolumeFlowUnit.OilBarrelPerSecond)] + [InlineData("gal (U. K.)/d", VolumeFlowUnit.UkGallonPerDay)] + [InlineData("gal (imp.)/h", VolumeFlowUnit.UkGallonPerHour)] + [InlineData("gal (imp.)/min", VolumeFlowUnit.UkGallonPerMinute)] + [InlineData("gal (imp.)/s", VolumeFlowUnit.UkGallonPerSecond)] + [InlineData("gpd", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("gal/d", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("gal (U.S.)/h", VolumeFlowUnit.UsGallonPerHour)] + [InlineData("gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("GPM", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond)] + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeFlowUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(VolumeFlow.TryParseUnit(abbreviation, out VolumeFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("af/d", VolumeFlowUnit.AcreFootPerDay)] + [InlineData("af/h", VolumeFlowUnit.AcreFootPerHour)] + [InlineData("af/m", VolumeFlowUnit.AcreFootPerMinute)] + [InlineData("af/s", VolumeFlowUnit.AcreFootPerSecond)] + [InlineData("cl/day", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cl/d", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cLPD", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("cl/h", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("cLPH", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("cl/min", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("cLPM", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("cl/s", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("cLPS", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("ft³/h", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("cf/hr", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("ft³/min", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("CFM", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("ft³/s", VolumeFlowUnit.CubicFootPerSecond)] + [InlineData("m³/d", VolumeFlowUnit.CubicMeterPerDay)] + [InlineData("m³/h", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("m³/min", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("m³/s", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("cy/day", VolumeFlowUnit.CubicYardPerDay)] + [InlineData("yd³/h", VolumeFlowUnit.CubicYardPerHour)] + [InlineData("yd³/min", VolumeFlowUnit.CubicYardPerMinute)] + [InlineData("yd³/s", VolumeFlowUnit.CubicYardPerSecond)] + [InlineData("dal/day", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("dal/d", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("daLPD", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("dal/h", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("daLPH", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("dal/min", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("daLPM", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("dal/s", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("daLPS", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("dl/day", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dl/d", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dLPD", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("dl/h", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("dLPH", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("dl/min", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("dLPM", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("dl/s", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("dLPS", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("hl/day", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hl/d", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hLPD", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("hl/h", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("hLPH", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("hl/min", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("hLPM", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("hl/s", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("hLPS", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("kl/day", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kl/d", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kLPD", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("kl/h", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("kLPH", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("kl/min", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("kLPM", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("kl/s", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("kLPS", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("KGPM", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("l/day", VolumeFlowUnit.LiterPerDay)] + [InlineData("l/d", VolumeFlowUnit.LiterPerDay)] + [InlineData("LPD", VolumeFlowUnit.LiterPerDay)] + [InlineData("l/h", VolumeFlowUnit.LiterPerHour)] + [InlineData("LPH", VolumeFlowUnit.LiterPerHour)] + [InlineData("l/min", VolumeFlowUnit.LiterPerMinute)] + [InlineData("LPM", VolumeFlowUnit.LiterPerMinute)] + [InlineData("l/s", VolumeFlowUnit.LiterPerSecond)] + [InlineData("LPS", VolumeFlowUnit.LiterPerSecond)] + [InlineData("Ml/day", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("Ml/d", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("MLPD", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("Ml/h", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("MLPH", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("Ml/min", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("MLPM", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("Ml/s", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("MLPS", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay)] + [InlineData("Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond)] + [InlineData("Mgpd", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("Mgal/d", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("µl/day", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µl/d", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µLPD", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("µl/h", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("µLPH", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("µl/min", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("µLPM", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("µl/s", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("µLPS", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("ml/day", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("ml/d", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("mLPD", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("ml/h", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("mLPH", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("ml/min", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("mLPM", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("ml/s", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("mLPS", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("MGD", VolumeFlowUnit.MillionUsGallonPerDay)] + [InlineData("nl/day", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nl/d", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nLPD", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("nl/h", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("nLPH", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("nl/min", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("nLPM", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("nl/s", VolumeFlowUnit.NanoliterPerSecond)] [InlineData("nLPS", VolumeFlowUnit.NanoliterPerSecond)] [InlineData("bbl/d", VolumeFlowUnit.OilBarrelPerDay)] [InlineData("BOPD", VolumeFlowUnit.OilBarrelPerDay)] @@ -3447,9 +3913,188 @@ public void ParseUnitWithCulture(string culture, string abbreviation, VolumeFlow [InlineData("gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute)] [InlineData("GPM", VolumeFlowUnit.UsGallonPerMinute)] [InlineData("gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond)] - public void TryParseUnit(string abbreviation, VolumeFlowUnit expectedUnit) + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumeFlowUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(VolumeFlow.TryParseUnit(abbreviation, out VolumeFlowUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "af/d", VolumeFlowUnit.AcreFootPerDay)] + [InlineData("en-US", "af/h", VolumeFlowUnit.AcreFootPerHour)] + [InlineData("en-US", "af/m", VolumeFlowUnit.AcreFootPerMinute)] + [InlineData("en-US", "af/s", VolumeFlowUnit.AcreFootPerSecond)] + [InlineData("en-US", "cl/day", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cl/d", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cLPD", VolumeFlowUnit.CentiliterPerDay)] + [InlineData("en-US", "cl/h", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("en-US", "cLPH", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("en-US", "cl/min", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("en-US", "cLPM", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("en-US", "cl/s", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("en-US", "cLPS", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("en-US", "cm³/min", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("en-US", "dm³/min", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("en-US", "ft³/h", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("en-US", "cf/hr", VolumeFlowUnit.CubicFootPerHour)] + [InlineData("en-US", "ft³/min", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("en-US", "CFM", VolumeFlowUnit.CubicFootPerMinute)] + [InlineData("en-US", "ft³/s", VolumeFlowUnit.CubicFootPerSecond)] + [InlineData("en-US", "m³/d", VolumeFlowUnit.CubicMeterPerDay)] + [InlineData("en-US", "m³/h", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("en-US", "m³/min", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("en-US", "m³/s", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("en-US", "mm³/s", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("en-US", "cy/day", VolumeFlowUnit.CubicYardPerDay)] + [InlineData("en-US", "yd³/h", VolumeFlowUnit.CubicYardPerHour)] + [InlineData("en-US", "yd³/min", VolumeFlowUnit.CubicYardPerMinute)] + [InlineData("en-US", "yd³/s", VolumeFlowUnit.CubicYardPerSecond)] + [InlineData("en-US", "dal/day", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "dal/d", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "daLPD", VolumeFlowUnit.DecaliterPerDay)] + [InlineData("en-US", "dal/h", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("en-US", "daLPH", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("en-US", "dal/min", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("en-US", "daLPM", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("en-US", "dal/s", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("en-US", "daLPS", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("en-US", "dl/day", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dl/d", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dLPD", VolumeFlowUnit.DeciliterPerDay)] + [InlineData("en-US", "dl/h", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("en-US", "dLPH", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("en-US", "dl/min", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("en-US", "dLPM", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("en-US", "dl/s", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("en-US", "dLPS", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("en-US", "hl/day", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hl/d", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hLPD", VolumeFlowUnit.HectoliterPerDay)] + [InlineData("en-US", "hl/h", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("en-US", "hLPH", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("en-US", "hl/min", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("en-US", "hLPM", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("en-US", "hl/s", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("en-US", "hLPS", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("en-US", "kl/day", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kl/d", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kLPD", VolumeFlowUnit.KiloliterPerDay)] + [InlineData("en-US", "kl/h", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("en-US", "kLPH", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("en-US", "kl/min", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("en-US", "kLPM", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("en-US", "kl/s", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("en-US", "kLPS", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("en-US", "kgal (U.S.)/min", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("en-US", "KGPM", VolumeFlowUnit.KilousGallonPerMinute)] + [InlineData("en-US", "l/day", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "l/d", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "LPD", VolumeFlowUnit.LiterPerDay)] + [InlineData("en-US", "l/h", VolumeFlowUnit.LiterPerHour)] + [InlineData("en-US", "LPH", VolumeFlowUnit.LiterPerHour)] + [InlineData("en-US", "l/min", VolumeFlowUnit.LiterPerMinute)] + [InlineData("en-US", "LPM", VolumeFlowUnit.LiterPerMinute)] + [InlineData("en-US", "l/s", VolumeFlowUnit.LiterPerSecond)] + [InlineData("en-US", "LPS", VolumeFlowUnit.LiterPerSecond)] + [InlineData("en-US", "Ml/day", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "Ml/d", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "MLPD", VolumeFlowUnit.MegaliterPerDay)] + [InlineData("en-US", "Ml/h", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("en-US", "MLPH", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("en-US", "Ml/min", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("en-US", "MLPM", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("en-US", "Ml/s", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("en-US", "MLPS", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("en-US", "Mgal (U. K.)/d", VolumeFlowUnit.MegaukGallonPerDay)] + [InlineData("en-US", "Mgal (imp.)/s", VolumeFlowUnit.MegaukGallonPerSecond)] + [InlineData("en-US", "Mgpd", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("en-US", "Mgal/d", VolumeFlowUnit.MegausGallonPerDay)] + [InlineData("en-US", "µl/day", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µl/d", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µLPD", VolumeFlowUnit.MicroliterPerDay)] + [InlineData("en-US", "µl/h", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("en-US", "µLPH", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("en-US", "µl/min", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("en-US", "µLPM", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("en-US", "µl/s", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("en-US", "µLPS", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("en-US", "ml/day", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "ml/d", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "mLPD", VolumeFlowUnit.MilliliterPerDay)] + [InlineData("en-US", "ml/h", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("en-US", "mLPH", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("en-US", "ml/min", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("en-US", "mLPM", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("en-US", "ml/s", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("en-US", "mLPS", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("en-US", "MGD", VolumeFlowUnit.MillionUsGallonPerDay)] + [InlineData("en-US", "nl/day", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nl/d", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nLPD", VolumeFlowUnit.NanoliterPerDay)] + [InlineData("en-US", "nl/h", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("en-US", "nLPH", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("en-US", "nl/min", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("en-US", "nLPM", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("en-US", "nl/s", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("en-US", "nLPS", VolumeFlowUnit.NanoliterPerSecond)] + [InlineData("en-US", "bbl/d", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("en-US", "BOPD", VolumeFlowUnit.OilBarrelPerDay)] + [InlineData("en-US", "bbl/hr", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("en-US", "bph", VolumeFlowUnit.OilBarrelPerHour)] + [InlineData("en-US", "bbl/min", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("en-US", "bpm", VolumeFlowUnit.OilBarrelPerMinute)] + [InlineData("en-US", "bbl/s", VolumeFlowUnit.OilBarrelPerSecond)] + [InlineData("en-US", "gal (U. K.)/d", VolumeFlowUnit.UkGallonPerDay)] + [InlineData("en-US", "gal (imp.)/h", VolumeFlowUnit.UkGallonPerHour)] + [InlineData("en-US", "gal (imp.)/min", VolumeFlowUnit.UkGallonPerMinute)] + [InlineData("en-US", "gal (imp.)/s", VolumeFlowUnit.UkGallonPerSecond)] + [InlineData("en-US", "gpd", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("en-US", "gal/d", VolumeFlowUnit.UsGallonPerDay)] + [InlineData("en-US", "gal (U.S.)/h", VolumeFlowUnit.UsGallonPerHour)] + [InlineData("en-US", "gal (U.S.)/min", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("en-US", "GPM", VolumeFlowUnit.UsGallonPerMinute)] + [InlineData("en-US", "gal (U.S.)/s", VolumeFlowUnit.UsGallonPerSecond)] + [InlineData("ru-RU", "сл/ч", VolumeFlowUnit.CentiliterPerHour)] + [InlineData("ru-RU", "сл/мин", VolumeFlowUnit.CentiliterPerMinute)] + [InlineData("ru-RU", "сл/c", VolumeFlowUnit.CentiliterPerSecond)] + [InlineData("ru-RU", "см³/мин", VolumeFlowUnit.CubicCentimeterPerMinute)] + [InlineData("ru-RU", "дм³/мин", VolumeFlowUnit.CubicDecimeterPerMinute)] + [InlineData("ru-RU", "м³/ч", VolumeFlowUnit.CubicMeterPerHour)] + [InlineData("ru-RU", "м³/мин", VolumeFlowUnit.CubicMeterPerMinute)] + [InlineData("ru-RU", "м³/с", VolumeFlowUnit.CubicMeterPerSecond)] + [InlineData("ru-RU", "мм³/с", VolumeFlowUnit.CubicMillimeterPerSecond)] + [InlineData("ru-RU", "дал/ч", VolumeFlowUnit.DecaliterPerHour)] + [InlineData("ru-RU", "дал/мин", VolumeFlowUnit.DecaliterPerMinute)] + [InlineData("ru-RU", "дал/c", VolumeFlowUnit.DecaliterPerSecond)] + [InlineData("ru-RU", "дл/ч", VolumeFlowUnit.DeciliterPerHour)] + [InlineData("ru-RU", "дл/мин", VolumeFlowUnit.DeciliterPerMinute)] + [InlineData("ru-RU", "дл/c", VolumeFlowUnit.DeciliterPerSecond)] + [InlineData("ru-RU", "гл/ч", VolumeFlowUnit.HectoliterPerHour)] + [InlineData("ru-RU", "гл/мин", VolumeFlowUnit.HectoliterPerMinute)] + [InlineData("ru-RU", "гл/c", VolumeFlowUnit.HectoliterPerSecond)] + [InlineData("ru-RU", "кл/ч", VolumeFlowUnit.KiloliterPerHour)] + [InlineData("ru-RU", "кл/мин", VolumeFlowUnit.KiloliterPerMinute)] + [InlineData("ru-RU", "кл/c", VolumeFlowUnit.KiloliterPerSecond)] + [InlineData("ru-RU", "л/ч", VolumeFlowUnit.LiterPerHour)] + [InlineData("ru-RU", "л/мин", VolumeFlowUnit.LiterPerMinute)] + [InlineData("ru-RU", "л/c", VolumeFlowUnit.LiterPerSecond)] + [InlineData("ru-RU", "Мл/ч", VolumeFlowUnit.MegaliterPerHour)] + [InlineData("ru-RU", "Мл/мин", VolumeFlowUnit.MegaliterPerMinute)] + [InlineData("ru-RU", "Мл/c", VolumeFlowUnit.MegaliterPerSecond)] + [InlineData("ru-RU", "мкл/ч", VolumeFlowUnit.MicroliterPerHour)] + [InlineData("ru-RU", "мкл/мин", VolumeFlowUnit.MicroliterPerMinute)] + [InlineData("ru-RU", "мкл/c", VolumeFlowUnit.MicroliterPerSecond)] + [InlineData("ru-RU", "мл/ч", VolumeFlowUnit.MilliliterPerHour)] + [InlineData("ru-RU", "мл/мин", VolumeFlowUnit.MilliliterPerMinute)] + [InlineData("ru-RU", "мл/c", VolumeFlowUnit.MilliliterPerSecond)] + [InlineData("ru-RU", "нл/ч", VolumeFlowUnit.NanoliterPerHour)] + [InlineData("ru-RU", "нл/мин", VolumeFlowUnit.NanoliterPerMinute)] + [InlineData("ru-RU", "нл/c", VolumeFlowUnit.NanoliterPerSecond)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumeFlowUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(VolumeFlow.TryParseUnit(abbreviation, out VolumeFlowUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -3625,7 +4270,7 @@ public void TryParseUnit(string abbreviation, VolumeFlowUnit expectedUnit) [InlineData("ru-RU", "нл/ч", VolumeFlowUnit.NanoliterPerHour)] [InlineData("ru-RU", "нл/мин", VolumeFlowUnit.NanoliterPerMinute)] [InlineData("ru-RU", "нл/c", VolumeFlowUnit.NanoliterPerSecond)] - public void TryParseUnitWithCulture(string culture, string abbreviation, VolumeFlowUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, VolumeFlowUnit expectedUnit) { Assert.True(VolumeFlow.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumeFlowUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs index e317c57b3a..1db40e1fcd 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumePerLengthTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -394,10 +395,29 @@ public void TryParse() [InlineData("l/mm", VolumePerLengthUnit.LiterPerMillimeter)] [InlineData("bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] [InlineData("gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] - public void ParseUnit(string abbreviation, VolumePerLengthUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumePerLengthUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - VolumePerLengthUnit parsedUnit = VolumePerLength.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + VolumePerLengthUnit parsedUnit = VolumePerLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("m³/m", VolumePerLengthUnit.CubicMeterPerMeter)] + [InlineData("yd³/ft", VolumePerLengthUnit.CubicYardPerFoot)] + [InlineData("yd³/ftUS", VolumePerLengthUnit.CubicYardPerUsSurveyFoot)] + [InlineData("gal (imp.)/mi", VolumePerLengthUnit.ImperialGallonPerMile)] + [InlineData("l/km", VolumePerLengthUnit.LiterPerKilometer)] + [InlineData("l/m", VolumePerLengthUnit.LiterPerMeter)] + [InlineData("l/mm", VolumePerLengthUnit.LiterPerMillimeter)] + [InlineData("bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] + [InlineData("gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumePerLengthUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + VolumePerLengthUnit parsedUnit = VolumePerLength.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -411,7 +431,24 @@ public void ParseUnit(string abbreviation, VolumePerLengthUnit expectedUnit) [InlineData("en-US", "l/mm", VolumePerLengthUnit.LiterPerMillimeter)] [InlineData("en-US", "bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] [InlineData("en-US", "gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] - public void ParseUnitWithCulture(string culture, string abbreviation, VolumePerLengthUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumePerLengthUnit expectedUnit) + { + using var _ = new CultureScope(culture); + VolumePerLengthUnit parsedUnit = VolumePerLength.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "m³/m", VolumePerLengthUnit.CubicMeterPerMeter)] + [InlineData("en-US", "yd³/ft", VolumePerLengthUnit.CubicYardPerFoot)] + [InlineData("en-US", "yd³/ftUS", VolumePerLengthUnit.CubicYardPerUsSurveyFoot)] + [InlineData("en-US", "gal (imp.)/mi", VolumePerLengthUnit.ImperialGallonPerMile)] + [InlineData("en-US", "l/km", VolumePerLengthUnit.LiterPerKilometer)] + [InlineData("en-US", "l/m", VolumePerLengthUnit.LiterPerMeter)] + [InlineData("en-US", "l/mm", VolumePerLengthUnit.LiterPerMillimeter)] + [InlineData("en-US", "bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] + [InlineData("en-US", "gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] + public void ParseUnit_WithCulture(string culture, string abbreviation, VolumePerLengthUnit expectedUnit) { VolumePerLengthUnit parsedUnit = VolumePerLength.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -427,9 +464,45 @@ public void ParseUnitWithCulture(string culture, string abbreviation, VolumePerL [InlineData("l/mm", VolumePerLengthUnit.LiterPerMillimeter)] [InlineData("bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] [InlineData("gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] - public void TryParseUnit(string abbreviation, VolumePerLengthUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumePerLengthUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(VolumePerLength.TryParseUnit(abbreviation, out VolumePerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("m³/m", VolumePerLengthUnit.CubicMeterPerMeter)] + [InlineData("yd³/ft", VolumePerLengthUnit.CubicYardPerFoot)] + [InlineData("yd³/ftUS", VolumePerLengthUnit.CubicYardPerUsSurveyFoot)] + [InlineData("gal (imp.)/mi", VolumePerLengthUnit.ImperialGallonPerMile)] + [InlineData("l/km", VolumePerLengthUnit.LiterPerKilometer)] + [InlineData("l/m", VolumePerLengthUnit.LiterPerMeter)] + [InlineData("l/mm", VolumePerLengthUnit.LiterPerMillimeter)] + [InlineData("bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] + [InlineData("gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumePerLengthUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(VolumePerLength.TryParseUnit(abbreviation, out VolumePerLengthUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "m³/m", VolumePerLengthUnit.CubicMeterPerMeter)] + [InlineData("en-US", "yd³/ft", VolumePerLengthUnit.CubicYardPerFoot)] + [InlineData("en-US", "yd³/ftUS", VolumePerLengthUnit.CubicYardPerUsSurveyFoot)] + [InlineData("en-US", "gal (imp.)/mi", VolumePerLengthUnit.ImperialGallonPerMile)] + [InlineData("en-US", "l/km", VolumePerLengthUnit.LiterPerKilometer)] + [InlineData("en-US", "l/m", VolumePerLengthUnit.LiterPerMeter)] + [InlineData("en-US", "l/mm", VolumePerLengthUnit.LiterPerMillimeter)] + [InlineData("en-US", "bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] + [InlineData("en-US", "gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumePerLengthUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(VolumePerLength.TryParseUnit(abbreviation, out VolumePerLengthUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -444,7 +517,7 @@ public void TryParseUnit(string abbreviation, VolumePerLengthUnit expectedUnit) [InlineData("en-US", "l/mm", VolumePerLengthUnit.LiterPerMillimeter)] [InlineData("en-US", "bbl/ft", VolumePerLengthUnit.OilBarrelPerFoot)] [InlineData("en-US", "gal (U.S.)/mi", VolumePerLengthUnit.UsGallonPerMile)] - public void TryParseUnitWithCulture(string culture, string abbreviation, VolumePerLengthUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, VolumePerLengthUnit expectedUnit) { Assert.True(VolumePerLength.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumePerLengthUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs index 7deb1ce34c..d30d95a125 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumeTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -2030,10 +2031,78 @@ public void TryParse() [InlineData("oz (U.S.)", VolumeUnit.UsOunce)] [InlineData("pt (U.S.)", VolumeUnit.UsPint)] [InlineData("qt (U.S.)", VolumeUnit.UsQuart)] - public void ParseUnit(string abbreviation, VolumeUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - VolumeUnit parsedUnit = Volume.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + VolumeUnit parsedUnit = Volume.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("ac-ft", VolumeUnit.AcreFoot)] + [InlineData("acre-foot", VolumeUnit.AcreFoot)] + [InlineData("acre-feet", VolumeUnit.AcreFoot)] + [InlineData("bf", VolumeUnit.BoardFoot)] + [InlineData("board foot", VolumeUnit.BoardFoot)] + [InlineData("board feet", VolumeUnit.BoardFoot)] + [InlineData("cl", VolumeUnit.Centiliter)] + [InlineData("cm³", VolumeUnit.CubicCentimeter)] + [InlineData("dm³", VolumeUnit.CubicDecimeter)] + [InlineData("ft³", VolumeUnit.CubicFoot)] + [InlineData("in³", VolumeUnit.CubicInch)] + [InlineData("m³", VolumeUnit.CubicMeter)] + [InlineData("µm³", VolumeUnit.CubicMicrometer)] + [InlineData("mi³", VolumeUnit.CubicMile)] + [InlineData("mm³", VolumeUnit.CubicMillimeter)] + [InlineData("yd³", VolumeUnit.CubicYard)] + [InlineData("dal", VolumeUnit.Decaliter)] + [InlineData("dagal (U.S.)", VolumeUnit.DecausGallon)] + [InlineData("dl", VolumeUnit.Deciliter)] + [InlineData("dgal (U.S.)", VolumeUnit.DeciusGallon)] + [InlineData("hft³", VolumeUnit.HectocubicFoot)] + [InlineData("hl", VolumeUnit.Hectoliter)] + [InlineData("hgal (U.S.)", VolumeUnit.HectousGallon)] + [InlineData("bl (imp.)", VolumeUnit.ImperialBeerBarrel)] + [InlineData("gal (imp.)", VolumeUnit.ImperialGallon)] + [InlineData("oz (imp.)", VolumeUnit.ImperialOunce)] + [InlineData("pt (imp.)", VolumeUnit.ImperialPint)] + [InlineData("UK pt", VolumeUnit.ImperialPint)] + [InlineData("pt", VolumeUnit.ImperialPint)] + [InlineData("p", VolumeUnit.ImperialPint)] + [InlineData("qt (imp.)", VolumeUnit.ImperialQuart)] + [InlineData("kft³", VolumeUnit.KilocubicFoot)] + [InlineData("kgal (imp.)", VolumeUnit.KiloimperialGallon)] + [InlineData("kl", VolumeUnit.Kiloliter)] + [InlineData("kgal (U.S.)", VolumeUnit.KilousGallon)] + [InlineData("l", VolumeUnit.Liter)] + [InlineData("Mft³", VolumeUnit.MegacubicFoot)] + [InlineData("Mgal (imp.)", VolumeUnit.MegaimperialGallon)] + [InlineData("Ml", VolumeUnit.Megaliter)] + [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("tsp", VolumeUnit.MetricTeaspoon)] + [InlineData("t", VolumeUnit.MetricTeaspoon)] + [InlineData("ts", VolumeUnit.MetricTeaspoon)] + [InlineData("tspn", VolumeUnit.MetricTeaspoon)] + [InlineData("t.", VolumeUnit.MetricTeaspoon)] + [InlineData("ts.", VolumeUnit.MetricTeaspoon)] + [InlineData("tsp.", VolumeUnit.MetricTeaspoon)] + [InlineData("tspn.", VolumeUnit.MetricTeaspoon)] + [InlineData("teaspoon", VolumeUnit.MetricTeaspoon)] + [InlineData("µl", VolumeUnit.Microliter)] + [InlineData("ml", VolumeUnit.Milliliter)] + [InlineData("nl", VolumeUnit.Nanoliter)] + [InlineData("bbl", VolumeUnit.OilBarrel)] + [InlineData("bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("oz (U.S.)", VolumeUnit.UsOunce)] + [InlineData("pt (U.S.)", VolumeUnit.UsPint)] + [InlineData("qt (U.S.)", VolumeUnit.UsQuart)] + 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. + using var _ = new CultureScope("is-IS"); + VolumeUnit parsedUnit = Volume.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -2132,7 +2201,109 @@ public void ParseUnit(string abbreviation, VolumeUnit expectedUnit) [InlineData("fr-CA", "pmp", VolumeUnit.BoardFoot)] [InlineData("fr-CA", "pied-planche", VolumeUnit.BoardFoot)] [InlineData("fr-CA", "pied de planche", VolumeUnit.BoardFoot)] - public void ParseUnitWithCulture(string culture, string abbreviation, VolumeUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumeUnit expectedUnit) + { + using var _ = new CultureScope(culture); + VolumeUnit parsedUnit = Volume.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "ac-ft", VolumeUnit.AcreFoot)] + [InlineData("en-US", "acre-foot", VolumeUnit.AcreFoot)] + [InlineData("en-US", "acre-feet", VolumeUnit.AcreFoot)] + [InlineData("en-US", "bf", VolumeUnit.BoardFoot)] + [InlineData("en-US", "board foot", VolumeUnit.BoardFoot)] + [InlineData("en-US", "board feet", VolumeUnit.BoardFoot)] + [InlineData("en-US", "cl", VolumeUnit.Centiliter)] + [InlineData("en-US", "cm³", VolumeUnit.CubicCentimeter)] + [InlineData("en-US", "dm³", VolumeUnit.CubicDecimeter)] + [InlineData("en-US", "ft³", VolumeUnit.CubicFoot)] + [InlineData("en-US", "in³", VolumeUnit.CubicInch)] + [InlineData("en-US", "m³", VolumeUnit.CubicMeter)] + [InlineData("en-US", "µm³", VolumeUnit.CubicMicrometer)] + [InlineData("en-US", "mi³", VolumeUnit.CubicMile)] + [InlineData("en-US", "mm³", VolumeUnit.CubicMillimeter)] + [InlineData("en-US", "yd³", VolumeUnit.CubicYard)] + [InlineData("en-US", "dal", VolumeUnit.Decaliter)] + [InlineData("en-US", "dagal (U.S.)", VolumeUnit.DecausGallon)] + [InlineData("en-US", "dl", VolumeUnit.Deciliter)] + [InlineData("en-US", "dgal (U.S.)", VolumeUnit.DeciusGallon)] + [InlineData("en-US", "hft³", VolumeUnit.HectocubicFoot)] + [InlineData("en-US", "hl", VolumeUnit.Hectoliter)] + [InlineData("en-US", "hgal (U.S.)", VolumeUnit.HectousGallon)] + [InlineData("en-US", "bl (imp.)", VolumeUnit.ImperialBeerBarrel)] + [InlineData("en-US", "gal (imp.)", VolumeUnit.ImperialGallon)] + [InlineData("en-US", "oz (imp.)", VolumeUnit.ImperialOunce)] + [InlineData("en-US", "pt (imp.)", VolumeUnit.ImperialPint)] + [InlineData("en-US", "UK pt", VolumeUnit.ImperialPint)] + [InlineData("en-US", "pt", VolumeUnit.ImperialPint)] + [InlineData("en-US", "p", VolumeUnit.ImperialPint)] + [InlineData("en-US", "qt (imp.)", VolumeUnit.ImperialQuart)] + [InlineData("en-US", "kft³", VolumeUnit.KilocubicFoot)] + [InlineData("en-US", "kgal (imp.)", VolumeUnit.KiloimperialGallon)] + [InlineData("en-US", "kl", VolumeUnit.Kiloliter)] + [InlineData("en-US", "kgal (U.S.)", VolumeUnit.KilousGallon)] + [InlineData("en-US", "l", VolumeUnit.Liter)] + [InlineData("en-US", "Mft³", VolumeUnit.MegacubicFoot)] + [InlineData("en-US", "Mgal (imp.)", VolumeUnit.MegaimperialGallon)] + [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] + [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tspn", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "t.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "ts.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tsp.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tspn.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "teaspoon", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "µl", VolumeUnit.Microliter)] + [InlineData("en-US", "ml", VolumeUnit.Milliliter)] + [InlineData("en-US", "nl", VolumeUnit.Nanoliter)] + [InlineData("en-US", "bbl", VolumeUnit.OilBarrel)] + [InlineData("en-US", "bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("en-US", "gal (U.S.)", VolumeUnit.UsGallon)] + [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("ru-RU", "сл", VolumeUnit.Centiliter)] + [InlineData("ru-RU", "см³", VolumeUnit.CubicCentimeter)] + [InlineData("ru-RU", "дм³", VolumeUnit.CubicDecimeter)] + [InlineData("ru-RU", "фут³", VolumeUnit.CubicFoot)] + [InlineData("ru-RU", "дюйм³", VolumeUnit.CubicInch)] + [InlineData("ru-RU", "м³", VolumeUnit.CubicMeter)] + [InlineData("ru-RU", "мкм³", VolumeUnit.CubicMicrometer)] + [InlineData("ru-RU", "миля³", VolumeUnit.CubicMile)] + [InlineData("ru-RU", "мм³", VolumeUnit.CubicMillimeter)] + [InlineData("ru-RU", "ярд³", VolumeUnit.CubicYard)] + [InlineData("ru-RU", "дал", VolumeUnit.Decaliter)] + [InlineData("ru-RU", "даАмериканский галлон", VolumeUnit.DecausGallon)] + [InlineData("ru-RU", "дл", VolumeUnit.Deciliter)] + [InlineData("ru-RU", "дАмериканский галлон", VolumeUnit.DeciusGallon)] + [InlineData("ru-RU", "гфут³", VolumeUnit.HectocubicFoot)] + [InlineData("ru-RU", "гл", VolumeUnit.Hectoliter)] + [InlineData("ru-RU", "гАмериканский галлон", VolumeUnit.HectousGallon)] + [InlineData("ru-RU", "Английский галлон", VolumeUnit.ImperialGallon)] + [InlineData("ru-RU", "Английская унция", VolumeUnit.ImperialOunce)] + [InlineData("ru-RU", "кфут³", VolumeUnit.KilocubicFoot)] + [InlineData("ru-RU", "кАнглийский галлон", VolumeUnit.KiloimperialGallon)] + [InlineData("ru-RU", "кл", VolumeUnit.Kiloliter)] + [InlineData("ru-RU", "кАмериканский галлон", VolumeUnit.KilousGallon)] + [InlineData("ru-RU", "л", VolumeUnit.Liter)] + [InlineData("ru-RU", "Мфут³", VolumeUnit.MegacubicFoot)] + [InlineData("ru-RU", "МАнглийский галлон", VolumeUnit.MegaimperialGallon)] + [InlineData("ru-RU", "Мл", VolumeUnit.Megaliter)] + [InlineData("ru-RU", "МАмериканский галлон", VolumeUnit.MegausGallon)] + [InlineData("ru-RU", "мкл", VolumeUnit.Microliter)] + [InlineData("ru-RU", "мл", VolumeUnit.Milliliter)] + [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)); Assert.Equal(expectedUnit, parsedUnit); @@ -2207,9 +2378,179 @@ public void ParseUnitWithAmbiguousAbbreviation(string culture, string abbreviati [InlineData("oz (U.S.)", VolumeUnit.UsOunce)] [InlineData("pt (U.S.)", VolumeUnit.UsPint)] [InlineData("qt (U.S.)", VolumeUnit.UsQuart)] - public void TryParseUnit(string abbreviation, VolumeUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumeUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(Volume.TryParseUnit(abbreviation, out VolumeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("ac-ft", VolumeUnit.AcreFoot)] + [InlineData("acre-foot", VolumeUnit.AcreFoot)] + [InlineData("acre-feet", VolumeUnit.AcreFoot)] + [InlineData("bf", VolumeUnit.BoardFoot)] + [InlineData("board foot", VolumeUnit.BoardFoot)] + [InlineData("board feet", VolumeUnit.BoardFoot)] + [InlineData("cl", VolumeUnit.Centiliter)] + [InlineData("cm³", VolumeUnit.CubicCentimeter)] + [InlineData("dm³", VolumeUnit.CubicDecimeter)] + [InlineData("ft³", VolumeUnit.CubicFoot)] + [InlineData("in³", VolumeUnit.CubicInch)] + [InlineData("m³", VolumeUnit.CubicMeter)] + [InlineData("µm³", VolumeUnit.CubicMicrometer)] + [InlineData("mi³", VolumeUnit.CubicMile)] + [InlineData("mm³", VolumeUnit.CubicMillimeter)] + [InlineData("yd³", VolumeUnit.CubicYard)] + [InlineData("dal", VolumeUnit.Decaliter)] + [InlineData("dagal (U.S.)", VolumeUnit.DecausGallon)] + [InlineData("dl", VolumeUnit.Deciliter)] + [InlineData("dgal (U.S.)", VolumeUnit.DeciusGallon)] + [InlineData("hft³", VolumeUnit.HectocubicFoot)] + [InlineData("hl", VolumeUnit.Hectoliter)] + [InlineData("hgal (U.S.)", VolumeUnit.HectousGallon)] + [InlineData("bl (imp.)", VolumeUnit.ImperialBeerBarrel)] + [InlineData("gal (imp.)", VolumeUnit.ImperialGallon)] + [InlineData("oz (imp.)", VolumeUnit.ImperialOunce)] + [InlineData("pt (imp.)", VolumeUnit.ImperialPint)] + [InlineData("UK pt", VolumeUnit.ImperialPint)] + [InlineData("pt", VolumeUnit.ImperialPint)] + [InlineData("p", VolumeUnit.ImperialPint)] + [InlineData("qt (imp.)", VolumeUnit.ImperialQuart)] + [InlineData("kft³", VolumeUnit.KilocubicFoot)] + [InlineData("kgal (imp.)", VolumeUnit.KiloimperialGallon)] + [InlineData("kl", VolumeUnit.Kiloliter)] + [InlineData("kgal (U.S.)", VolumeUnit.KilousGallon)] + [InlineData("l", VolumeUnit.Liter)] + [InlineData("Mft³", VolumeUnit.MegacubicFoot)] + [InlineData("Mgal (imp.)", VolumeUnit.MegaimperialGallon)] + [InlineData("Ml", VolumeUnit.Megaliter)] + [InlineData("Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("tsp", VolumeUnit.MetricTeaspoon)] + [InlineData("t", VolumeUnit.MetricTeaspoon)] + [InlineData("ts", VolumeUnit.MetricTeaspoon)] + [InlineData("tspn", VolumeUnit.MetricTeaspoon)] + [InlineData("t.", VolumeUnit.MetricTeaspoon)] + [InlineData("ts.", VolumeUnit.MetricTeaspoon)] + [InlineData("tsp.", VolumeUnit.MetricTeaspoon)] + [InlineData("tspn.", VolumeUnit.MetricTeaspoon)] + [InlineData("teaspoon", VolumeUnit.MetricTeaspoon)] + [InlineData("µl", VolumeUnit.Microliter)] + [InlineData("ml", VolumeUnit.Milliliter)] + [InlineData("nl", VolumeUnit.Nanoliter)] + [InlineData("bbl", VolumeUnit.OilBarrel)] + [InlineData("bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("gal (U.S.)", VolumeUnit.UsGallon)] + [InlineData("oz (U.S.)", VolumeUnit.UsOunce)] + [InlineData("pt (U.S.)", VolumeUnit.UsPint)] + [InlineData("qt (U.S.)", VolumeUnit.UsQuart)] + 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. + using var _ = new CultureScope("is-IS"); + Assert.True(Volume.TryParseUnit(abbreviation, out VolumeUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "ac-ft", VolumeUnit.AcreFoot)] + [InlineData("en-US", "acre-foot", VolumeUnit.AcreFoot)] + [InlineData("en-US", "acre-feet", VolumeUnit.AcreFoot)] + [InlineData("en-US", "bf", VolumeUnit.BoardFoot)] + [InlineData("en-US", "board foot", VolumeUnit.BoardFoot)] + [InlineData("en-US", "board feet", VolumeUnit.BoardFoot)] + [InlineData("en-US", "cl", VolumeUnit.Centiliter)] + [InlineData("en-US", "cm³", VolumeUnit.CubicCentimeter)] + [InlineData("en-US", "dm³", VolumeUnit.CubicDecimeter)] + [InlineData("en-US", "ft³", VolumeUnit.CubicFoot)] + [InlineData("en-US", "in³", VolumeUnit.CubicInch)] + [InlineData("en-US", "m³", VolumeUnit.CubicMeter)] + [InlineData("en-US", "µm³", VolumeUnit.CubicMicrometer)] + [InlineData("en-US", "mi³", VolumeUnit.CubicMile)] + [InlineData("en-US", "mm³", VolumeUnit.CubicMillimeter)] + [InlineData("en-US", "yd³", VolumeUnit.CubicYard)] + [InlineData("en-US", "dal", VolumeUnit.Decaliter)] + [InlineData("en-US", "dagal (U.S.)", VolumeUnit.DecausGallon)] + [InlineData("en-US", "dl", VolumeUnit.Deciliter)] + [InlineData("en-US", "dgal (U.S.)", VolumeUnit.DeciusGallon)] + [InlineData("en-US", "hft³", VolumeUnit.HectocubicFoot)] + [InlineData("en-US", "hl", VolumeUnit.Hectoliter)] + [InlineData("en-US", "hgal (U.S.)", VolumeUnit.HectousGallon)] + [InlineData("en-US", "bl (imp.)", VolumeUnit.ImperialBeerBarrel)] + [InlineData("en-US", "gal (imp.)", VolumeUnit.ImperialGallon)] + [InlineData("en-US", "oz (imp.)", VolumeUnit.ImperialOunce)] + [InlineData("en-US", "pt (imp.)", VolumeUnit.ImperialPint)] + [InlineData("en-US", "UK pt", VolumeUnit.ImperialPint)] + [InlineData("en-US", "pt", VolumeUnit.ImperialPint)] + [InlineData("en-US", "p", VolumeUnit.ImperialPint)] + [InlineData("en-US", "qt (imp.)", VolumeUnit.ImperialQuart)] + [InlineData("en-US", "kft³", VolumeUnit.KilocubicFoot)] + [InlineData("en-US", "kgal (imp.)", VolumeUnit.KiloimperialGallon)] + [InlineData("en-US", "kl", VolumeUnit.Kiloliter)] + [InlineData("en-US", "kgal (U.S.)", VolumeUnit.KilousGallon)] + [InlineData("en-US", "l", VolumeUnit.Liter)] + [InlineData("en-US", "Mft³", VolumeUnit.MegacubicFoot)] + [InlineData("en-US", "Mgal (imp.)", VolumeUnit.MegaimperialGallon)] + [InlineData("en-US", "Ml", VolumeUnit.Megaliter)] + [InlineData("en-US", "Mgal (U.S.)", VolumeUnit.MegausGallon)] + [InlineData("en-US", "tsp", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "t", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "ts", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tspn", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "t.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "ts.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tsp.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "tspn.", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "teaspoon", VolumeUnit.MetricTeaspoon)] + [InlineData("en-US", "µl", VolumeUnit.Microliter)] + [InlineData("en-US", "ml", VolumeUnit.Milliliter)] + [InlineData("en-US", "nl", VolumeUnit.Nanoliter)] + [InlineData("en-US", "bbl", VolumeUnit.OilBarrel)] + [InlineData("en-US", "bl (U.S.)", VolumeUnit.UsBeerBarrel)] + [InlineData("en-US", "gal (U.S.)", VolumeUnit.UsGallon)] + [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("ru-RU", "сл", VolumeUnit.Centiliter)] + [InlineData("ru-RU", "см³", VolumeUnit.CubicCentimeter)] + [InlineData("ru-RU", "дм³", VolumeUnit.CubicDecimeter)] + [InlineData("ru-RU", "фут³", VolumeUnit.CubicFoot)] + [InlineData("ru-RU", "дюйм³", VolumeUnit.CubicInch)] + [InlineData("ru-RU", "м³", VolumeUnit.CubicMeter)] + [InlineData("ru-RU", "мкм³", VolumeUnit.CubicMicrometer)] + [InlineData("ru-RU", "миля³", VolumeUnit.CubicMile)] + [InlineData("ru-RU", "мм³", VolumeUnit.CubicMillimeter)] + [InlineData("ru-RU", "ярд³", VolumeUnit.CubicYard)] + [InlineData("ru-RU", "дал", VolumeUnit.Decaliter)] + [InlineData("ru-RU", "даАмериканский галлон", VolumeUnit.DecausGallon)] + [InlineData("ru-RU", "дл", VolumeUnit.Deciliter)] + [InlineData("ru-RU", "дАмериканский галлон", VolumeUnit.DeciusGallon)] + [InlineData("ru-RU", "гфут³", VolumeUnit.HectocubicFoot)] + [InlineData("ru-RU", "гл", VolumeUnit.Hectoliter)] + [InlineData("ru-RU", "гАмериканский галлон", VolumeUnit.HectousGallon)] + [InlineData("ru-RU", "Английский галлон", VolumeUnit.ImperialGallon)] + [InlineData("ru-RU", "Английская унция", VolumeUnit.ImperialOunce)] + [InlineData("ru-RU", "кфут³", VolumeUnit.KilocubicFoot)] + [InlineData("ru-RU", "кАнглийский галлон", VolumeUnit.KiloimperialGallon)] + [InlineData("ru-RU", "кл", VolumeUnit.Kiloliter)] + [InlineData("ru-RU", "кАмериканский галлон", VolumeUnit.KilousGallon)] + [InlineData("ru-RU", "л", VolumeUnit.Liter)] + [InlineData("ru-RU", "Мфут³", VolumeUnit.MegacubicFoot)] + [InlineData("ru-RU", "МАнглийский галлон", VolumeUnit.MegaimperialGallon)] + [InlineData("ru-RU", "Мл", VolumeUnit.Megaliter)] + [InlineData("ru-RU", "МАмериканский галлон", VolumeUnit.MegausGallon)] + [InlineData("ru-RU", "мкл", VolumeUnit.Microliter)] + [InlineData("ru-RU", "мл", VolumeUnit.Milliliter)] + [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) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(Volume.TryParseUnit(abbreviation, out VolumeUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -2309,7 +2650,7 @@ public void TryParseUnit(string abbreviation, VolumeUnit expectedUnit) [InlineData("fr-CA", "pmp", VolumeUnit.BoardFoot)] [InlineData("fr-CA", "pied-planche", VolumeUnit.BoardFoot)] [InlineData("fr-CA", "pied de planche", VolumeUnit.BoardFoot)] - public void TryParseUnitWithCulture(string culture, string abbreviation, VolumeUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, VolumeUnit expectedUnit) { Assert.True(Volume.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumeUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs index 468cb82fc1..08e54f1474 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/VolumetricHeatCapacityTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -394,10 +395,29 @@ public void TryParse() [InlineData("kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] [InlineData("MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] [InlineData("MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] - public void ParseUnit(string abbreviation, VolumetricHeatCapacityUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumetricHeatCapacityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - VolumetricHeatCapacityUnit parsedUnit = VolumetricHeatCapacity.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + VolumetricHeatCapacityUnit parsedUnit = VolumetricHeatCapacity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("BTU/(ft³·°F)", VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit)] + [InlineData("cal/(cm³·°C)", VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("J/(m³·°C)", VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius)] + [InlineData("J/(m³·K)", VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin)] + [InlineData("kcal/(cm³·°C)", VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("kJ/(m³·°C)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius)] + [InlineData("kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] + [InlineData("MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] + [InlineData("MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumetricHeatCapacityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + VolumetricHeatCapacityUnit parsedUnit = VolumetricHeatCapacity.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -411,7 +431,24 @@ public void ParseUnit(string abbreviation, VolumetricHeatCapacityUnit expectedUn [InlineData("en-US", "kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] [InlineData("en-US", "MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] [InlineData("en-US", "MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] - public void ParseUnitWithCulture(string culture, string abbreviation, VolumetricHeatCapacityUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumetricHeatCapacityUnit expectedUnit) + { + using var _ = new CultureScope(culture); + VolumetricHeatCapacityUnit parsedUnit = VolumetricHeatCapacity.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "BTU/(ft³·°F)", VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit)] + [InlineData("en-US", "cal/(cm³·°C)", VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("en-US", "J/(m³·°C)", VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "J/(m³·K)", VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin)] + [InlineData("en-US", "kcal/(cm³·°C)", VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("en-US", "kJ/(m³·°C)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] + [InlineData("en-US", "MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] + public void ParseUnit_WithCulture(string culture, string abbreviation, VolumetricHeatCapacityUnit expectedUnit) { VolumetricHeatCapacityUnit parsedUnit = VolumetricHeatCapacity.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -427,9 +464,45 @@ public void ParseUnitWithCulture(string culture, string abbreviation, Volumetric [InlineData("kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] [InlineData("MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] [InlineData("MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] - public void TryParseUnit(string abbreviation, VolumetricHeatCapacityUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, VolumetricHeatCapacityUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(VolumetricHeatCapacity.TryParseUnit(abbreviation, out VolumetricHeatCapacityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("BTU/(ft³·°F)", VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit)] + [InlineData("cal/(cm³·°C)", VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("J/(m³·°C)", VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius)] + [InlineData("J/(m³·K)", VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin)] + [InlineData("kcal/(cm³·°C)", VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("kJ/(m³·°C)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius)] + [InlineData("kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] + [InlineData("MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] + [InlineData("MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, VolumetricHeatCapacityUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(VolumetricHeatCapacity.TryParseUnit(abbreviation, out VolumetricHeatCapacityUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "BTU/(ft³·°F)", VolumetricHeatCapacityUnit.BtuPerCubicFootDegreeFahrenheit)] + [InlineData("en-US", "cal/(cm³·°C)", VolumetricHeatCapacityUnit.CaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("en-US", "J/(m³·°C)", VolumetricHeatCapacityUnit.JoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "J/(m³·K)", VolumetricHeatCapacityUnit.JoulePerCubicMeterKelvin)] + [InlineData("en-US", "kcal/(cm³·°C)", VolumetricHeatCapacityUnit.KilocaloriePerCubicCentimeterDegreeCelsius)] + [InlineData("en-US", "kJ/(m³·°C)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] + [InlineData("en-US", "MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] + [InlineData("en-US", "MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, VolumetricHeatCapacityUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(VolumetricHeatCapacity.TryParseUnit(abbreviation, out VolumetricHeatCapacityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -444,7 +517,7 @@ public void TryParseUnit(string abbreviation, VolumetricHeatCapacityUnit expecte [InlineData("en-US", "kJ/(m³·K)", VolumetricHeatCapacityUnit.KilojoulePerCubicMeterKelvin)] [InlineData("en-US", "MJ/(m³·°C)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterDegreeCelsius)] [InlineData("en-US", "MJ/(m³·K)", VolumetricHeatCapacityUnit.MegajoulePerCubicMeterKelvin)] - public void TryParseUnitWithCulture(string culture, string abbreviation, VolumetricHeatCapacityUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, VolumetricHeatCapacityUnit expectedUnit) { Assert.True(VolumetricHeatCapacity.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out VolumetricHeatCapacityUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs index 99a34b606e..6d21f0b0d9 100644 --- a/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs +++ b/UnitsNet.Tests/GeneratedCode/TestsBase/WarpingMomentOfInertiaTestsBase.g.cs @@ -22,6 +22,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using UnitsNet.Tests.Helpers; using UnitsNet.Tests.TestsBase; using UnitsNet.Units; using Xunit; @@ -406,10 +407,32 @@ public void TryParse() [InlineData("m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] [InlineData("mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] [InlineData("mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] - public void ParseUnit(string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + public void ParseUnit_WithUsEnglishCurrentCulture(string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") - WarpingMomentOfInertiaUnit parsedUnit = WarpingMomentOfInertia.ParseUnit(abbreviation); + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + WarpingMomentOfInertiaUnit parsedUnit = WarpingMomentOfInertia.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm⁶", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("cm^6", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("dm⁶", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("dm^6", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("ft⁶", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("ft^6", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("in⁶", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("in^6", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("m⁶", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + [InlineData("mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + public void ParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + WarpingMomentOfInertiaUnit parsedUnit = WarpingMomentOfInertia.ParseUnit(abbreviation); Assert.Equal(expectedUnit, parsedUnit); } @@ -426,7 +449,27 @@ public void ParseUnit(string abbreviation, WarpingMomentOfInertiaUnit expectedUn [InlineData("en-US", "m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] [InlineData("en-US", "mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] [InlineData("en-US", "mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] - public void ParseUnitWithCulture(string culture, string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + public void ParseUnit_WithCurrentCulture(string culture, string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + { + using var _ = new CultureScope(culture); + WarpingMomentOfInertiaUnit parsedUnit = WarpingMomentOfInertia.ParseUnit(abbreviation); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm⁶", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("en-US", "cm^6", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("en-US", "dm⁶", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("en-US", "dm^6", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("en-US", "ft⁶", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("en-US", "ft^6", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("en-US", "in⁶", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("en-US", "in^6", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("en-US", "m⁶", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("en-US", "m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("en-US", "mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + [InlineData("en-US", "mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + public void ParseUnit_WithCulture(string culture, string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) { WarpingMomentOfInertiaUnit parsedUnit = WarpingMomentOfInertia.ParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture)); Assert.Equal(expectedUnit, parsedUnit); @@ -445,9 +488,51 @@ public void ParseUnitWithCulture(string culture, string abbreviation, WarpingMom [InlineData("m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] [InlineData("mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] [InlineData("mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] - public void TryParseUnit(string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + public void TryParseUnit_WithUsEnglishCurrentCulture(string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + { + // Fallback culture "en-US" is always localized + using var _ = new CultureScope("en-US"); + Assert.True(WarpingMomentOfInertia.TryParseUnit(abbreviation, out WarpingMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("cm⁶", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("cm^6", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("dm⁶", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("dm^6", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("ft⁶", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("ft^6", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("in⁶", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("in^6", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("m⁶", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + [InlineData("mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + public void TryParseUnit_WithUnsupportedCurrentCulture_FallsBackToUsEnglish(string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + { + // Currently, no abbreviations are localized for Icelandic, so it should fall back to "en-US" when parsing. + using var _ = new CultureScope("is-IS"); + Assert.True(WarpingMomentOfInertia.TryParseUnit(abbreviation, out WarpingMomentOfInertiaUnit parsedUnit)); + Assert.Equal(expectedUnit, parsedUnit); + } + + [Theory] + [InlineData("en-US", "cm⁶", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("en-US", "cm^6", WarpingMomentOfInertiaUnit.CentimeterToTheSixth)] + [InlineData("en-US", "dm⁶", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("en-US", "dm^6", WarpingMomentOfInertiaUnit.DecimeterToTheSixth)] + [InlineData("en-US", "ft⁶", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("en-US", "ft^6", WarpingMomentOfInertiaUnit.FootToTheSixth)] + [InlineData("en-US", "in⁶", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("en-US", "in^6", WarpingMomentOfInertiaUnit.InchToTheSixth)] + [InlineData("en-US", "m⁶", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("en-US", "m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] + [InlineData("en-US", "mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + [InlineData("en-US", "mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] + public void TryParseUnit_WithCurrentCulture(string culture, string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) { - // regardless of the CurrentCulture is, this should always work with the FallbackCulture ("en-US") + using var _ = new CultureScope(culture); Assert.True(WarpingMomentOfInertia.TryParseUnit(abbreviation, out WarpingMomentOfInertiaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); } @@ -465,7 +550,7 @@ public void TryParseUnit(string abbreviation, WarpingMomentOfInertiaUnit expecte [InlineData("en-US", "m^6", WarpingMomentOfInertiaUnit.MeterToTheSixth)] [InlineData("en-US", "mm⁶", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] [InlineData("en-US", "mm^6", WarpingMomentOfInertiaUnit.MillimeterToTheSixth)] - public void TryParseUnitWithCulture(string culture, string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) + public void TryParseUnit_WithCulture(string culture, string abbreviation, WarpingMomentOfInertiaUnit expectedUnit) { Assert.True(WarpingMomentOfInertia.TryParseUnit(abbreviation, CultureInfo.GetCultureInfo(culture), out WarpingMomentOfInertiaUnit parsedUnit)); Assert.Equal(expectedUnit, parsedUnit); diff --git a/UnitsNet.Tests/Helpers/CultureScope.cs b/UnitsNet.Tests/Helpers/CultureScope.cs new file mode 100644 index 0000000000..37585478ca --- /dev/null +++ b/UnitsNet.Tests/Helpers/CultureScope.cs @@ -0,0 +1,32 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +using System; +using System.Globalization; + +namespace UnitsNet.Tests.Helpers; + +public sealed class CultureScope : IDisposable +{ + private readonly CultureInfo _originalCulture; + // private readonly CultureInfo _originalUICulture; + + public CultureScope(string cultureName) : this(CultureInfo.GetCultureInfo(cultureName)) + { + } + + public CultureScope(CultureInfo culture) + { + _originalCulture = CultureInfo.CurrentCulture; + // _originalUICulture = CultureInfo.CurrentUICulture; + + CultureInfo.CurrentCulture = culture; + // CultureInfo.CurrentUICulture = culture; + } + + public void Dispose() + { + CultureInfo.CurrentCulture = _originalCulture; + // CultureInfo.CurrentUICulture = _originalUICulture; + } +}