24 Commits

Author SHA1 Message Date
Gordon Fontenot
a7ca3b5977 Add test for decoding booleans from multiple types 2016-04-08 14:13:22 -05:00
Jon Shier
255196cabc Fix performance test for big_data.json
At some point, the big_data.json fixture became out of sync with the
TestModel type, and so decoding was failing, making these tests useless.
I've generated a new big_data.json fixture that matches the expected
TestModel properties, as well as increasing the size to be able to
really measure performance issues. I've also added a test to ensure that
decoding completed successfully so that we don't run into this issue in
the future.
2016-03-11 10:04:56 -06:00
Niels van Hoorn
90ede0ca1e Added parsing from String for decoding Int64
Javascript isn't any good at handling large numbers natively. Instead,
any number over 53 bits is supposed to be stored as a string. In order
to support this, Argo should really add the ability to decode `Int64`
instances from `String`s, in addition to `Number`s.
2015-12-18 13:24:50 -08:00
Gordon Fontenot and Giles Van Gruisen
0cbecefcf5 Add tests for decoding dictionaries
Turns out, we weren't testing the decoding of dictionaries anywhere.
That seems wrong, so this adds those tests and (thankfully) proves that
our current implementation works as expected.

Also, we ran into a swift bug that I actually hit the other day as well
that I need to file a radar on. The title of which will probably end up
being:

> flatMapping custom monadic type with static function defined in a
> protocol extension results in compiler crash

That's why we're duplicating the meat of `flatMap` for the purpose of
the test.
2015-09-30 21:55:37 -07:00
Tony DiPasquale
bf726b714c Update the documentation for Swift 2
This also breaks up the main README.md into a Documentations directory
with separate documents for different topics. This will be expanded upon
with new PRs going forward.
2015-09-18 16:59:42 -07:00
Gordon Fontenot
143d3833b8 Remove more references to Runes from tests
Somehow this compiled. I'm legitimately not sure how. Maybe I have an
old version of the framework somewhere that Xcode can find. No clue. But
we don't need these references to Runes sitting around now that we
aren't depending on it.
2015-09-17 14:55:34 -07:00
Benedikt Terhechte
4f0065a218 Add <|> alternative operator
This operator chooses between either the left hand side or the right
hand side, whichever contains a successful value. If both sides are
empty, the right hand side will be returned.

Usage is as follows:
<*> j <| "possible-key" <|> j <| "possible-key2"

The precedence is set a bit below the precedence of the other operators
(i.e. `<|`) so that parentheses are not necessary when constructing
expressions.
2015-09-17 14:55:33 -07:00
Tony DiPasquale
3bb667abb8 Cleanup playground paths 2015-09-17 14:55:32 -07:00
Tony DiPasquale
c47a91f2d1 Restore playgrounds
The converter messed up the playgrounds to this reverts back to what was
on master then manually fixing all the errors.
2015-09-17 14:55:32 -07:00
Tony DiPasquale
3a4974e4ec Use Swift 1 to 2 conversion tool and fix errors
Run the conversion tool in Xcode 7 beta 1 to convert to Swift 2. Remove
Box from the project since it is no longer needed. Fix any errors
leftover.
2015-09-17 14:55:32 -07:00
al_skipp
d15f2594e2 Refactored JSONFileReader as a free function 2015-05-29 13:01:19 +01:00
Tony DiPasquale
a564e5de3c Add Printable to Decoded for easy debugging 2015-05-20 12:09:32 -04:00
Tony DiPasquale
5f3a1b1a59 Add null field to tests 2015-04-29 17:29:06 -04:00
Michael McGuire
ddee5da394 Add JSONDecodable extension for Int64
On 32-bit platforms (namely iPhone 4S, iPhone 5 for iOS8+) the Swift Int
type only goes up to 2^31. Even though there is technically no limits
placed upon JSON numeric values, they are often designed around
JavaScript clients which have a maximum integer value of 2^53. I've
added explicit support for the Int64 type to support this limit.

Probably important to mention that if a numeric value of greater than
2^31 is present in the data and you are on a 32-bit device using a plain
Int type, you get a silent overflow on decoding.
2015-04-16 08:25:03 -04:00
Tony DiPasquale
d7a202354e Improve JSON.parse performance
Using the update/append functionality of Dictionaries instead of
implementing a custom merge operator `+`, we see significant speed
increases for large data sets. Given a ~85K json file, it took ~265ms to
parse without this optimization and ~75ms with this optimization.
2015-03-20 11:13:25 -04:00
Reda Lemeden
450415e65f Make Float conform to JSONDecodable 2015-02-16 15:35:27 +01:00
Gordon Fontenot
7a522a5d21 Use map instead of flatMap when parsing
`JSONValue.parse` returns a non-optional `JSONValue`. Unfortunately,
because of Swift Magic, Xcode will happily compile when using `flatMap`
with a function that returns a non-optional. This can (but doesn't
always) result in a EXC_BAD_ACCESS error at runtime. Using `map` here is
actually the correct behavior, but should also fix this crash that
people were seeing.
2015-01-14 10:41:40 -05:00
Gordon Fontenot
0ad59fa59e Introduce DecodedType typealias
Introducing this typealias helps when trying to conform a non-final
class to `JSONDecodable`.

If we just use `Self`, we run into an issue where the compiler can't
ensure that return type is correct, because the class might be
subclassed. By letting classes explicitly define their decoded type, we
can make the compiler happy while maintaining the ability to subclass if
that's what we want.

As an added benefit, we can default `DecodedType` to `Self`, which means
that `structs` and `final` classes don't need to worry about changing
anything from the way they are doing it now.
2015-01-08 14:49:27 -05:00
Tony DiPasquale
f4c06284bd Add some common use case examples to tests 2014-12-30 11:05:02 -05:00
Tony DiPasquale
296a66c0f3 Modify test json for posts to fail 2014-12-29 17:23:42 -05:00
Gordon Fontenot and Tony DiPasquale
e328377752 Don't ignore decoding errors in arrays
The rest of the system treats JSON decoding errors as fatal, we should
do the same for Arrays. Instead of ignoring decoding errors in the
nested JSON, an error should result in `.None` for the entire array.
2014-12-29 14:26:28 -05:00
Tony DiPasquale
930f0dbbbd Introduce JSONValue enum
This value helps reduce the complexity of type inference.

This commit also adds a first pass to change JSON decoding operators to
be prefixed instead of infix, and uses function composition instead of
function application.
2014-12-29 13:43:16 -05:00
Gordon Fontenot
0dea798b4b Add OS X target
Rearranged the project a little bit and added an OS X target so that
this can be used for mac apps.
2014-12-25 20:13:38 -05:00
Tony DiPasquale
9b82ac132b Rename project 2014-09-26 13:03:48 -04:00