Overview
| Comment: | ObjFWTest: Add OTOrderedDictionary |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | objfwtest |
| Files: | files | file ages | folders |
| SHA3-256: |
b1a0bfe247ad13e8bdf7e877e04fe30c |
| User & Date: | js on 2024-02-13 21:15:53 |
| Other Links: | branch diff | manifest | tags |
Context
|
2024-02-13
| ||
| 22:18 | OFObjectTests: Remove unused define (check-in: 8bdf345eee user: js tags: objfwtest) | |
| 21:15 | ObjFWTest: Add OTOrderedDictionary (check-in: b1a0bfe247 user: js tags: objfwtest) | |
| 21:13 | Merge trunk into branch "objfwtest" (check-in: fa70ca352c user: js tags: objfwtest) | |
Changes
Modified new_tests/OFJSONTests.m from [fbfa925551] to [2e899d37b6].
| ︙ | ︙ | |||
28 29 30 31 32 33 34 |
@"null//bar\n,\"foo\",false]}";
@implementation OFJSONTests
- (void)setUp
{
[super setUp];
| | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
@"null//bar\n,\"foo\",false]}";
@implementation OFJSONTests
- (void)setUp
{
[super setUp];
_dictionary = [[OTOrderedDictionary alloc] initWithKeysAndObjects:
@"foo", @"b\na\r",
@"x", [OFArray arrayWithObjects:
[OFNumber numberWithFloat: .5f],
[OFNumber numberWithInt: 0xF],
[OFNull null],
@"foo",
[OFNumber numberWithBool: false],
|
| ︙ | ︙ | |||
54 55 56 57 58 59 60 |
- (void)testObjectByParsingJSON
{
OTAssertEqualObjects(string.objectByParsingJSON, _dictionary);
}
- (void)testJSONRepresentation
{
| | < < < < < | | | < < < < < < | | | < < < < < | | 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 |
- (void)testObjectByParsingJSON
{
OTAssertEqualObjects(string.objectByParsingJSON, _dictionary);
}
- (void)testJSONRepresentation
{
OTAssert(_dictionary.JSONRepresentation,
@"{\"foo\":\"b\\na\\r\",\"x\":[0.5,15,null,\"foo\",false]}");
}
- (void)testPrettyJSONRepresentation
{
OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions:
OFJSONRepresentationOptionPretty],
@"{\n\t\"foo\": \"b\\na\\r\",\n\t\"x\": [\n\t\t0.5,\n\t\t15,"
@"\n\t\tnull,\n\t\t\"foo\",\n\t\tfalse\n\t]\n}");
}
- (void)testJSON5Representation
{
OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions:
OFJSONRepresentationOptionJSON5],
@"{foo:\"b\\\na\\r\",x:[0.5,15,null,\"foo\",false]}");
}
- (void)testObjectByParsingJSONFailsWithInvalidJSON
{
OTAssertThrowsSpecific([@"{" objectByParsingJSON],
OFInvalidJSONException);
|
| ︙ | ︙ |
Modified src/test/Makefile from [b269c69e19] to [d0464d1428].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
include ../../extra.mk
DISTCLEAN = Info.plist
STATIC_LIB = libobjfwtest.a
SRCS = OTAssert.m \
OTTestCase.m
INCLUDES := ${SRCS:.m=.h} \
ObjFWTest.h
SRCS += OTAppDelegate.m \
OTAssertionFailedException.m
includesubdir = ObjFWTest
| > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
include ../../extra.mk
DISTCLEAN = Info.plist
STATIC_LIB = libobjfwtest.a
SRCS = OTAssert.m \
OTOrderedDictionary.m \
OTTestCase.m
INCLUDES := ${SRCS:.m=.h} \
ObjFWTest.h
SRCS += OTAppDelegate.m \
OTAssertionFailedException.m
includesubdir = ObjFWTest
|
| ︙ | ︙ |
Added src/test/OTOrderedDictionary.h version [b6c6515436].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 |
/*
* Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#ifdef OBJFWTEST_LOCAL_INCLUDES
# import "ObjFW.h"
#else
# import <ObjFW/ObjFW.h>
#endif
OF_ASSUME_NONNULL_BEGIN
@interface OTOrderedDictionary: OFDictionary
{
OFArray *_keys;
OFArray *_objects;
}
@end
OF_ASSUME_NONNULL_END
|
Added src/test/OTOrderedDictionary.m version [6f48fb899d].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 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 |
/*
* Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "OTOrderedDictionary.h"
@implementation OTOrderedDictionary
- (instancetype)initWithObjects: (id const *)objects
forKeys: (id const *)keys
count: (size_t)count
{
self = [super init];
@try {
OFMutableArray *mutableKeys, *mutableObjects;
mutableKeys = [[OFMutableArray alloc] initWithCapacity: count];
_keys = mutableKeys;
mutableObjects = [[OFMutableArray alloc]
initWithCapacity: count];
_objects = mutableObjects;
for (size_t i = 0; i < count; i++) {
OFLog(@"key=%@, value=%@", keys[i], objects[i]);
[mutableKeys addObject: keys[i]];
[mutableObjects addObject: objects[i]];
}
[mutableKeys makeImmutable];
[mutableObjects makeImmutable];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_keys release];
[_objects release];
[super dealloc];
}
- (id)objectForKey: (id)key
{
size_t i = 0;
for (id iter in _keys) {
if ([iter isEqual: key])
return [_objects objectAtIndex: i];
i++;
}
return nil;
}
- (size_t)count
{
return _keys.count;
}
- (OFEnumerator *)keyEnumerator
{
return [_keys objectEnumerator];
}
- (OFEnumerator *)objectEnumerator
{
return [_objects objectEnumerator];
}
@end
|
Modified src/test/ObjFWTest.h from [c6fa64803a] to [e2709fe53c].
| ︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OTTestCase.h" #import "OTAssert.h" | > | 11 12 13 14 15 16 17 18 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OTTestCase.h" #import "OTAssert.h" #import "OTOrderedDictionary.h" |