ObjFW  Diff

Differences From Artifact [556f5814fc]:

  • File tests/OFINIFileTests.m — part of check-in [12c5b7ee91] at 2014-06-12 13:43:41 on branch trunk — OFINIFile: Add support for quoted keys / values

    This is a much more logical way to handle leading and trailing
    whitespaces and also seems to be used by a few other INI
    implementations.

    Additionally, this imports OFINICategory.h in OFINIFile.h so that
    importing OFINIFile.h is enough - this should be less confusing - and
    allows opening non-existant files, treating them like an empty file. (user: js, size: 3338) [annotate] [blame] [check-ins using]

To Artifact [b708218fa8]:


42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57
58
59
60
61



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
	    @";comment" NL
	    @"new=new" NL
	    NL
	    @"[foobar]" NL
	    @";foobarcomment" NL
	    @"qux=\" asd\"" NL
	    @"quxquxqux=\"hello\\\"world\"" NL
	    @"qux2=\"\\f\"" NL

	    NL
	    @"[types]" NL
	    @"integer=16" NL
	    @"bool=false" NL
	    @"float=0.25" NL
	    @"double=0.75" NL;
	OFINIFile *file;
	OFINICategory *category;

	TEST(@"+[fileWithPath:]",
	    (file = [OFINIFile fileWithPath: @"testfile.ini"]))




	TEST(@"-[categoryForName:]",
	    (category = [file categoryForName: @"tests"]))

	module = @"OFINICategory";

	TEST(@"-[stringForKey:]",
	    [[category stringForKey: @"foo"] isEqual: @"bar"] &&
	    (category = [file categoryForName: @"foobar"]) &&
	    [[category stringForKey: @"quxquxqux"] isEqual: @"hello\"world"])

	category = [file categoryForName: @"tests"];

	TEST(@"-[setString:forKey:]",
	    R([category setString: @"baz"
			   forKey: @"foo"]) &&
	    R([category setString: @"new"
			   forKey: @"new"]))

	category = [file categoryForName: @"types"];

	TEST(@"-[integerForKey:defaultValue:]",
	    [category integerForKey: @"integer"
		       defaultValue: 2] == 0x20)

	TEST(@"-[setInteger:forKey:]", R([category setInteger: 0x10
						       forKey: @"integer"]))

	TEST(@"-[boolForKey:defaultValue:]",
	    [category boolForKey: @"bool"
		    defaultValue: false] == true)

	TEST(@"-[setBool:forKey:]", R([category setBool: false
						 forKey: @"bool"]))

	TEST(@"-[floatForKey:defaultValue:]",
	    [category floatForKey: @"float"
		     defaultValue: 1] == 0.5f)

	TEST(@"-[setFloat:forKey:]", R([category setFloat: 0.25f
						   forKey: @"float"]))

	TEST(@"-[doubleForKey:defaultValue:]",
	    [category doubleForKey: @"double"
		      defaultValue: 3] == 0.25)

	TEST(@"-[setDouble:forKey:]", R([category setDouble: 0.75
						     forKey: @"double"]))

	category = [file categoryForName: @"foobar"];

	TEST(@"-[removeValueForKey:]",
	    R([category removeValueForKey: @"quxqux "]))

	module = @"OFINIFile";

	/* FIXME: Find a way to write files on Nintendo DS */
#ifndef OF_NINTENDO_DS
	TEST(@"-[writeToFile:]", R([file writeToFile: @"tmpfile.ini"]) &&
	    [[OFString stringWithContentsOfFile: @"tmpfile.ini"]







|
>







|




>
>
>

|




|
<
|

<
<

|
|
|
|
|
|


|
|

|
|


|
|

|
|


|
|

|
|


|
|

|
|

<
<

|







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73
74


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110


111
112
113
114
115
116
117
118
119
	    @";comment" NL
	    @"new=new" NL
	    NL
	    @"[foobar]" NL
	    @";foobarcomment" NL
	    @"qux=\" asd\"" NL
	    @"quxquxqux=\"hello\\\"world\"" NL
	    @"qux2=\"a\\f\"" NL
	    @"qux3=a\fb" NL
	    NL
	    @"[types]" NL
	    @"integer=16" NL
	    @"bool=false" NL
	    @"float=0.25" NL
	    @"double=0.75" NL;
	OFINIFile *file;
	OFINICategory *tests, *foobar, *types;

	TEST(@"+[fileWithPath:]",
	    (file = [OFINIFile fileWithPath: @"testfile.ini"]))

	tests = [file categoryForName: @"tests"];
	foobar = [file categoryForName: @"foobar"];
	types = [file categoryForName: @"types"];
	TEST(@"-[categoryForName:]",
	    tests != nil && foobar != nil && types != nil)

	module = @"OFINICategory";

	TEST(@"-[stringForKey:]",
	    [[tests stringForKey: @"foo"] isEqual: @"bar"] &&

	    [[foobar stringForKey: @"quxquxqux"] isEqual: @"hello\"world"])



	TEST(@"-[setString:forKey:]",
	    R([tests setString: @"baz"
			forKey: @"foo"]) &&
	    R([tests setString: @"new"
			forKey: @"new"]) &&
	    R([foobar setString: @"a\fb"
			 forKey: @"qux3"]))

	TEST(@"-[integerForKey:defaultValue:]",
	    [types integerForKey: @"integer"
		    defaultValue: 2] == 0x20)

	TEST(@"-[setInteger:forKey:]", R([types setInteger: 0x10
						    forKey: @"integer"]))

	TEST(@"-[boolForKey:defaultValue:]",
	    [types boolForKey: @"bool"
		 defaultValue: false] == true)

	TEST(@"-[setBool:forKey:]", R([types setBool: false
					      forKey: @"bool"]))

	TEST(@"-[floatForKey:defaultValue:]",
	    [types floatForKey: @"float"
		  defaultValue: 1] == 0.5f)

	TEST(@"-[setFloat:forKey:]", R([types setFloat: 0.25f
						forKey: @"float"]))

	TEST(@"-[doubleForKey:defaultValue:]",
	    [types doubleForKey: @"double"
		   defaultValue: 3] == 0.25)

	TEST(@"-[setDouble:forKey:]", R([types setDouble: 0.75
						  forKey: @"double"]))



	TEST(@"-[removeValueForKey:]",
	    R([foobar removeValueForKey: @"quxqux "]))

	module = @"OFINIFile";

	/* FIXME: Find a way to write files on Nintendo DS */
#ifndef OF_NINTENDO_DS
	TEST(@"-[writeToFile:]", R([file writeToFile: @"tmpfile.ini"]) &&
	    [[OFString stringWithContentsOfFile: @"tmpfile.ini"]