2015-07-13 15:42:32 +00:00
|
|
|
/**
|
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
|
|
|
*
|
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2015-06-06 20:37:36 +00:00
|
|
|
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
|
|
|
|
#import "RCTConvert.h"
|
|
|
|
|
|
|
|
@interface RCTConvert_UIFontTests : XCTestCase
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTConvert_UIFontTests
|
|
|
|
|
|
|
|
#define RCTAssertEqualFonts(font1, font2) { \
|
|
|
|
XCTAssertEqualObjects(font1, font2); \
|
|
|
|
}
|
|
|
|
|
2015-07-09 23:45:48 +00:00
|
|
|
- (void)testWeight
|
2015-06-06 20:37:36 +00:00
|
|
|
{
|
|
|
|
{
|
2015-07-09 23:45:48 +00:00
|
|
|
UIFont *expected = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
|
2015-06-06 20:37:36 +00:00
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontWeight": @"bold"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
2015-07-09 23:45:48 +00:00
|
|
|
UIFont *expected = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
|
2015-06-06 20:37:36 +00:00
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontWeight": @"500"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
2015-07-09 23:45:48 +00:00
|
|
|
UIFont *expected = [UIFont systemFontOfSize:14 weight:UIFontWeightUltraLight];
|
2015-06-06 20:37:36 +00:00
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontWeight": @"100"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
2015-07-09 23:45:48 +00:00
|
|
|
UIFont *expected = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
|
2015-06-06 20:37:36 +00:00
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontWeight": @"normal"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)testSize
|
|
|
|
{
|
|
|
|
{
|
2015-07-09 23:45:48 +00:00
|
|
|
UIFont *expected = [UIFont systemFontOfSize:18.5];
|
2015-06-06 20:37:36 +00:00
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontSize": @18.5}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)testFamily
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont fontWithName:@"Cochin" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"Cochin"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"Helvetica Neue"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue-Italic" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"HelveticaNeue-Italic"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)testStyle
|
|
|
|
{
|
|
|
|
{
|
2015-07-09 23:45:48 +00:00
|
|
|
UIFont *font = [UIFont systemFontOfSize:14];
|
|
|
|
UIFontDescriptor *fontDescriptor = [font fontDescriptor];
|
|
|
|
UIFontDescriptorSymbolicTraits symbolicTraits = fontDescriptor.symbolicTraits;
|
|
|
|
symbolicTraits |= UIFontDescriptorTraitItalic;
|
|
|
|
fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits];
|
|
|
|
UIFont *expected = [UIFont fontWithDescriptor:fontDescriptor size:14];
|
2015-06-06 20:37:36 +00:00
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontStyle": @"italic"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
2015-07-09 23:45:48 +00:00
|
|
|
UIFont *expected = [UIFont systemFontOfSize:14];
|
2015-06-06 20:37:36 +00:00
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontStyle": @"normal"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 23:45:48 +00:00
|
|
|
- (void)testStyleAndWeight
|
2015-06-06 20:37:36 +00:00
|
|
|
{
|
|
|
|
{
|
2015-07-09 23:45:48 +00:00
|
|
|
UIFont *font = [UIFont systemFontOfSize:14 weight:UIFontWeightUltraLight];
|
|
|
|
UIFontDescriptor *fontDescriptor = [font fontDescriptor];
|
|
|
|
UIFontDescriptorSymbolicTraits symbolicTraits = fontDescriptor.symbolicTraits;
|
|
|
|
symbolicTraits |= UIFontDescriptorTraitItalic;
|
|
|
|
fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits];
|
|
|
|
UIFont *expected = [UIFont fontWithDescriptor:fontDescriptor size:14];
|
2015-06-06 20:37:36 +00:00
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontStyle": @"italic", @"fontWeight": @"100"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
2015-07-09 23:45:48 +00:00
|
|
|
UIFont *font = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
|
|
|
|
UIFontDescriptor *fontDescriptor = [font fontDescriptor];
|
|
|
|
UIFontDescriptorSymbolicTraits symbolicTraits = fontDescriptor.symbolicTraits;
|
|
|
|
symbolicTraits |= UIFontDescriptorTraitItalic;
|
|
|
|
fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits];
|
|
|
|
UIFont *expected = [UIFont fontWithDescriptor:fontDescriptor size:14];
|
2015-06-06 20:37:36 +00:00
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontStyle": @"italic", @"fontWeight": @"bold"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 23:45:48 +00:00
|
|
|
- (void)testFamilyAndWeight
|
2015-06-06 20:37:36 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue-Bold" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"Helvetica Neue", @"fontWeight": @"bold"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"HelveticaNeue-Bold", @"fontWeight": @"normal"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont fontWithName:@"Cochin-Bold" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"Cochin", @"fontWeight": @"700"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont fontWithName:@"Cochin" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"Cochin", @"fontWeight": @"100"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)testFamilyAndStyle
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue-Italic" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"Helvetica Neue", @"fontStyle": @"italic"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"HelveticaNeue-Italic", @"fontStyle": @"normal"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 23:45:48 +00:00
|
|
|
- (void)testFamilyStyleAndWeight
|
2015-06-06 20:37:36 +00:00
|
|
|
{
|
|
|
|
{
|
2015-08-11 15:33:28 +00:00
|
|
|
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue-LightItalic" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"Helvetica Neue", @"fontStyle": @"italic", @"fontWeight": @"300"}];
|
2015-06-06 20:37:36 +00:00
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue-Bold" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"HelveticaNeue-Italic", @"fontStyle": @"normal", @"fontWeight": @"bold"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont fontWithName:@"HelveticaNeue" size:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"HelveticaNeue-Italic", @"fontStyle": @"normal", @"fontWeight": @"normal"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 23:45:48 +00:00
|
|
|
- (void)testInvalidFont
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UIFont *expected = [UIFont systemFontOfSize:14];
|
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"foobar"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
{
|
2015-07-13 15:42:32 +00:00
|
|
|
UIFont *expected = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
|
2015-07-09 23:45:48 +00:00
|
|
|
UIFont *result = [RCTConvert UIFont:@{@"fontFamily": @"foobar", @"fontWeight": @"bold"}];
|
|
|
|
RCTAssertEqualFonts(expected, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 20:37:36 +00:00
|
|
|
@end
|