Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 1e78ad681c
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 61 lines (47 sloc) 2.01 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
//
// main.m
// Tipi
//
// Created by Chris Ross on 05/04/2012.
// Copyright (c) 2012 hiddenMemory Ltd. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "Tipi.h"

int main(int argc, const char * argv[]) {

@autoreleasepool {
NSMutableDictionary *environment = [NSMutableDictionary dictionary];

[environment setObject:[^NSString*( TPTemplateNode *node, NSMutableDictionary *environment ) {
TPMarkdownDataParser *parser = [TPMarkdownDataParser parserForFile:[node.values objectAtIndex:0]];

// Duplicate the environment for implementing the child nodes
NSMutableDictionary *invokeEnvironment = [NSMutableDictionary dictionaryWithDictionary:environment];

// Add the key-values from the data file
[invokeEnvironment addEntriesFromDictionary:parser.values];

return [node.childNodes tp_templateNodesExpandedUsingEnvironment:invokeEnvironment];
} copy] forKey:@"include"];

for( int i = 1; i <= 6; i++ ) {
NSString *inputPath = [NSString stringWithFormat:@"/Users/chris/Repositories/git/hiddenMemory/Tipi/Tests/basic/Test0%d.input", i];
NSString *outputPath = [NSString stringWithFormat:@"/Users/chris/Repositories/git/hiddenMemory/Tipi/Tests/basic/Test0%d.output", i];

TPTemplateParser *q = [TPTemplateParser parserForFile:inputPath];
NSString *expansion = [q expansionUsingEnvironment:[NSDictionary dictionary]];

if( [[NSFileManager defaultManager] fileExistsAtPath:outputPath] ) {
NSString *goldenExpansion = [NSString stringWithContentsOfFile:outputPath
encoding:NSUTF8StringEncoding
error:nil];

if( [goldenExpansion isEqualToString:expansion] ) {
NSLog(@"Test %d passed", i);
}
else {
NSLog(@">>>> Test %d failed <<<<", i);
}
}
else {
NSLog(@"Expansion:\nSTART:\n%@:END", expansion);
[expansion writeToFile:outputPath
atomically:NO
encoding:NSUTF8StringEncoding
error:nil];
}
}
}
    return 0;
}

Something went wrong with that request. Please try again.