diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-12-26 15:07:43 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2017-01-04 08:52:41 -0800 |
commit | aef36956ee062ea2992c43d658cebf52954b5213 (patch) | |
tree | a16dd7677374ff128fd0f0e50564e4027a4f4607 /platform/darwin/test/MGLExpressionTests.mm | |
parent | e6132d248b54d202c3fa132b3084660a0bbe3c06 (diff) | |
download | qtlocation-mapboxgl-aef36956ee062ea2992c43d658cebf52954b5213.tar.gz |
[ios, macos] Cleaned up expression conversion
Diffstat (limited to 'platform/darwin/test/MGLExpressionTests.mm')
-rw-r--r-- | platform/darwin/test/MGLExpressionTests.mm | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index e78f87a99b..00b57c15f0 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -28,27 +28,35 @@ - (void)testExpressionConversionString { NSComparisonPredicate *predicate = [self equalityComparisonPredicateWithRightConstantValue:@"bar"]; - mbgl::Value convertedValue = predicate.rightExpression.mgl_filterValue; - XCTAssert(convertedValue.is<std::string>() == true); + mbgl::Value convertedValue = predicate.rightExpression.mgl_constantMBGLValue; + XCTAssertTrue(convertedValue.is<std::string>()); XCTAssertEqualObjects(@(convertedValue.get<std::string>().c_str()), @"bar"); } +- (void)testExpressionConversionStringWithUnicode +{ + NSComparisonPredicate *predicate = [self equalityComparisonPredicateWithRightConstantValue:@"🆔🆗🇦🇶"]; + mbgl::Value convertedValue = predicate.rightExpression.mgl_constantMBGLValue; + XCTAssertTrue(convertedValue.is<std::string>()); + XCTAssertEqual(convertedValue.get<std::string>(), "🆔🆗🇦🇶"); +} + #pragma mark - Boolean Tests - (void)testExpressionConversionBooleanTrue { NSComparisonPredicate *predicate = [self equalityComparisonPredicateWithRightConstantValue:@YES]; - mbgl::Value convertedValue = predicate.rightExpression.mgl_filterValue; - XCTAssert(convertedValue.is<bool>() == true); - XCTAssert(convertedValue.get<bool>() == true); + mbgl::Value convertedValue = predicate.rightExpression.mgl_constantMBGLValue; + XCTAssertTrue(convertedValue.is<bool>()); + XCTAssertEqual(convertedValue.get<bool>(), true); } - (void)testExpressionConversionBooleanFalse { NSComparisonPredicate *predicate = [self equalityComparisonPredicateWithRightConstantValue:@NO]; - mbgl::Value convertedValue = predicate.rightExpression.mgl_filterValue; - XCTAssert(convertedValue.is<bool>() == true); - XCTAssert(convertedValue.get<bool>() == false); + mbgl::Value convertedValue = predicate.rightExpression.mgl_constantMBGLValue; + XCTAssertTrue(convertedValue.is<bool>()); + XCTAssertEqual(convertedValue.get<bool>(), false); } #pragma mark - Floating Point Tests @@ -59,12 +67,12 @@ mbgl::Value convertedValue; predicate = [self equalityComparisonPredicateWithRightConstantValue:[NSNumber numberWithDouble:DBL_MIN]]; - convertedValue = predicate.rightExpression.mgl_filterValue; + convertedValue = predicate.rightExpression.mgl_constantMBGLValue; XCTAssertTrue(convertedValue.is<double>()); XCTAssertEqual(convertedValue.get<double>(), DBL_MIN); predicate = [self equalityComparisonPredicateWithRightConstantValue:[NSNumber numberWithDouble:DBL_MAX]]; - convertedValue = predicate.rightExpression.mgl_filterValue; + convertedValue = predicate.rightExpression.mgl_constantMBGLValue; XCTAssertTrue(convertedValue.is<double>()); XCTAssertEqual(convertedValue.get<double>(), DBL_MAX); } @@ -72,7 +80,7 @@ - (void)testExpressionConversionFloat { // Because we can't guarantee precision when using float, and because - // we warn the user to this effect in mgl_convertedValueWithValue:, + // we warn the user to this effect in -[NSExpression mgl_constantMBGLValue], // we just check that things are in the ballpark here with integer values // and some lower-precision checks. @@ -80,26 +88,24 @@ mbgl::Value convertedValue; predicate = [self equalityComparisonPredicateWithRightConstantValue:[NSNumber numberWithFloat:-1]]; - convertedValue = predicate.rightExpression.mgl_filterValue; + convertedValue = predicate.rightExpression.mgl_constantMBGLValue; XCTAssertTrue(convertedValue.is<double>()); XCTAssertEqual(convertedValue.get<double>(), -1); predicate = [self equalityComparisonPredicateWithRightConstantValue:[NSNumber numberWithFloat:1]]; - convertedValue = predicate.rightExpression.mgl_filterValue; + convertedValue = predicate.rightExpression.mgl_constantMBGLValue; XCTAssertTrue(convertedValue.is<double>()); XCTAssertEqual(convertedValue.get<double>(), 1); predicate = [self equalityComparisonPredicateWithRightConstantValue:[NSNumber numberWithFloat:-23.232342]]; - convertedValue = predicate.rightExpression.mgl_filterValue; + convertedValue = predicate.rightExpression.mgl_constantMBGLValue; XCTAssertTrue(convertedValue.is<double>()); - XCTAssertLessThan(-23.24, convertedValue.get<double>()); - XCTAssertGreaterThan(-23.23, convertedValue.get<double>()); + XCTAssertEqualWithAccuracy(convertedValue.get<double>(), -23.232342, 0.000001); predicate = [self equalityComparisonPredicateWithRightConstantValue:[NSNumber numberWithFloat:23.232342]]; - convertedValue = predicate.rightExpression.mgl_filterValue; + convertedValue = predicate.rightExpression.mgl_constantMBGLValue; XCTAssertTrue(convertedValue.is<double>()); - XCTAssertLessThan(23.23, convertedValue.get<double>()); - XCTAssertGreaterThan(23.24, convertedValue.get<double>()); + XCTAssertEqualWithAccuracy(convertedValue.get<double>(), 23.232342, 0.000001); } #pragma mark - Integer Tests @@ -132,7 +138,7 @@ for (NSNumber *min in minValues) { predicate = [self equalityComparisonPredicateWithRightConstantValue:min]; - convertedValue = predicate.rightExpression.mgl_filterValue; + convertedValue = predicate.rightExpression.mgl_constantMBGLValue; XCTAssertTrue(convertedValue.is<int64_t>()); XCTAssertEqual(convertedValue.get<int64_t>(), min.longLongValue); } @@ -144,7 +150,7 @@ for (NSNumber *max in maxValues) { predicate = [self equalityComparisonPredicateWithRightConstantValue:max]; - convertedValue = predicate.rightExpression.mgl_filterValue; + convertedValue = predicate.rightExpression.mgl_constantMBGLValue; XCTAssertTrue(convertedValue.is<uint64_t>()); XCTAssertEqual(convertedValue.get<uint64_t>(), max.unsignedLongLongValue); } @@ -179,7 +185,7 @@ for (NSNumber *min in minValues) { predicate = [self equalityComparisonPredicateWithRightConstantValue:min]; - convertedValue = predicate.rightExpression.mgl_filterValue; + convertedValue = predicate.rightExpression.mgl_constantMBGLValue; XCTAssertTrue(convertedValue.is<uint64_t>()); XCTAssertEqual(convertedValue.get<uint64_t>(), min.unsignedLongLongValue); } @@ -191,7 +197,7 @@ for (NSNumber *max in maxValues) { predicate = [self equalityComparisonPredicateWithRightConstantValue:max]; - convertedValue = predicate.rightExpression.mgl_filterValue; + convertedValue = predicate.rightExpression.mgl_constantMBGLValue; XCTAssertTrue(convertedValue.is<uint64_t>()); XCTAssertEqual(convertedValue.get<uint64_t>(), max.unsignedLongLongValue); } @@ -202,7 +208,7 @@ - (void)testExpressionConversionNull { NSComparisonPredicate *predicate = [self equalityComparisonPredicateWithRightConstantValue:[NSNull null]]; - mbgl::Value convertedValue = predicate.rightExpression.mgl_filterValue; + mbgl::Value convertedValue = predicate.rightExpression.mgl_constantMBGLValue; XCTAssertTrue(convertedValue.is<mbgl::NullValue>()); } |