1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 #include "gtest/gtest.h" 5 6 #include "mozilla/intl/MeasureUnit.h" 7 #include "mozilla/Span.h" 8 9 namespace mozilla::intl { 10 TEST(IntlMeasureUnit,GetAvailable)11TEST(IntlMeasureUnit, GetAvailable) 12 { 13 auto units = MeasureUnit::GetAvailable(); 14 ASSERT_TRUE(units.isOk()); 15 16 // Test a subset of the installed measurement units. 17 auto gigabyte = MakeStringSpan("gigabyte"); 18 auto liter = MakeStringSpan("liter"); 19 auto meter = MakeStringSpan("meter"); 20 auto meters = MakeStringSpan("meters"); // Plural "meters" is invalid. 21 22 bool hasGigabyte = false; 23 bool hasLiter = false; 24 bool hasMeter = false; 25 bool hasMeters = false; 26 27 for (auto unit : units.unwrap()) { 28 ASSERT_TRUE(unit.isOk()); 29 auto span = unit.unwrap(); 30 31 hasGigabyte |= span == gigabyte; 32 hasLiter |= span == liter; 33 hasMeter |= span == meter; 34 hasMeters |= span == meters; 35 } 36 37 ASSERT_TRUE(hasGigabyte); 38 ASSERT_TRUE(hasLiter); 39 ASSERT_TRUE(hasMeter); 40 ASSERT_FALSE(hasMeters); 41 } 42 43 } // namespace mozilla::intl 44