//
//  XTHtmlTagTests.m
//  TadsTerp
//
//  Created by Rune Berg on 22/08/14.
//  Copyright (c) 2014 Rune Berg. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "XTHtmlTagFont.h"


@interface XTHtmlTagTests : XCTestCase

@property XTHtmlTagFont *tag;

@end


@implementation XTHtmlTagTests

- (void)setUp
{
    [super setUp];
	self.tag = [XTHtmlTagFont new];
	self.tag.closing = NO;
}

- (void)tearDown
{
    [super tearDown];
}

//TODO more tests

- (void)test_attributeAsCommaSeparatedStrings_missingAttr
{
	NSArray *a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(0, a.count);
}

- (void)test_attributeAsCommaSeparatedStrings_0strings
{
	self.tag.attributes[@"face"] = @"";
	NSArray *a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(0, a.count);
}

- (void)test_attributeAsCommaSeparatedStrings_1string
{
	self.tag.attributes[@"face"] = @"Courier";
	NSArray *a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(1, a.count);
	XCTAssertEqualObjects(@"Courier", a[0]);
	
	self.tag.attributes[@"face"] = @" ";
	a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(1, a.count);
	XCTAssertEqualObjects(@"", a[0]);
	
	self.tag.attributes[@"face"] = @"   ";
	a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(1, a.count);
	XCTAssertEqualObjects(@"", a[0]);
}

- (void)test_attributeAsCommaSeparatedStrings_2strings
{
	self.tag.attributes[@"face"] = @"Courier,Arial";
	NSArray *a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(2, a.count);
	XCTAssertEqualObjects(@"Courier", a[0]);
	XCTAssertEqualObjects(@"Arial", a[1]);

	self.tag.attributes[@"face"] = @"C,A";
	a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(2, a.count);
	XCTAssertEqualObjects(@"C", a[0]);
	XCTAssertEqualObjects(@"A", a[1]);
	
	self.tag.attributes[@"face"] = @"C,";
	a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(2, a.count);
	XCTAssertEqualObjects(@"C", a[0]);
	XCTAssertEqualObjects(@"", a[1]);
	
	self.tag.attributes[@"face"] = @",A";
	a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(2, a.count);
	XCTAssertEqualObjects(@"", a[0]);
	XCTAssertEqualObjects(@"A", a[1]);
	
	self.tag.attributes[@"face"] = @" Courier,Arial ";
	a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(2, a.count);
	XCTAssertEqualObjects(@"Courier", a[0]);
	XCTAssertEqualObjects(@"Arial", a[1]);
	
	self.tag.attributes[@"face"] = @" Courier ,  Arial ";
	a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(2, a.count);
	XCTAssertEqualObjects(@"Courier", a[0]);
	XCTAssertEqualObjects(@"Arial", a[1]);
	
	self.tag.attributes[@"face"] = @",";
	a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(2, a.count);
	XCTAssertEqualObjects(@"", a[0]);
	XCTAssertEqualObjects(@"", a[1]);
	
	self.tag.attributes[@"face"] = @"  ,   ";
	a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(2, a.count);
	XCTAssertEqualObjects(@"", a[0]);
	XCTAssertEqualObjects(@"", a[1]);
}

- (void)test_attributeAsCommaSeparatedStrings_3strings
{
	self.tag.attributes[@"face"] = @"Courier,Arial,Dingbats";
	NSArray *a = [self.tag attributeAsCommaSeparatedStrings:@"face"];
	XCTAssertEqual(3, a.count);
	XCTAssertEqualObjects(@"Courier", a[0]);
	XCTAssertEqualObjects(@"Arial", a[1]);
	XCTAssertEqualObjects(@"Dingbats", a[2]);
}

@end
