summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-07-03 00:21:25 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2015-07-03 00:21:25 +0100
commit6d353116efdb777dff0ccb06bf93751856765738 (patch)
treefa0660401cb0df13e6441bee06dc272738fef031
parentMove to C++0y (diff)
downloadlibjsonpp-6d353116efdb777dff0ccb06bf93751856765738.tar.bz2
libjsonpp-6d353116efdb777dff0ccb06bf93751856765738.tar.xz
libjsonpp-6d353116efdb777dff0ccb06bf93751856765738.zip
Fix corner case of empty array in object with covering unit test and highlighting samplelibjsonpp-0.9.2
-rw-r--r--libjsonpp/initial/sample2.json391
-rw-r--r--libjsonpp/json.ll8
-rw-r--r--libjsonpp/test1.cpp18
3 files changed, 415 insertions, 2 deletions
diff --git a/libjsonpp/initial/sample2.json b/libjsonpp/initial/sample2.json
new file mode 100644
index 0000000..f21752f
--- /dev/null
+++ b/libjsonpp/initial/sample2.json
@@ -0,0 +1,391 @@
+{
+ "page": 1,
+ "results": [
+ {
+ "backdrop_path": "/eSzpy96DwBujGFj0xMbXBcGcfxX.jpg",
+ "first_air_date": "2008-01-19",
+ "genre_ids": [
+ 18
+ ],
+ "id": 1396,
+ "original_language": "en",
+ "original_name": "Breaking Bad",
+ "overview": "Breaking Bad is an American crime drama television series created and produced by Vince Gilligan. Set and produced in Albuquerque, New Mexico, Breaking Bad is the story of Walter White, a struggling high school chemistry teacher who is diagnosed with inoperable lung cancer at the beginning of the series. He turns to a life of crime, producing and selling methamphetamine, in order to secure his family's financial future before he dies, teaming with his former student, Jesse Pinkman. Heavily serialized, the series is known for positioning its characters in seemingly inextricable corners and has been labeled a contemporary western by its creator.",
+ "origin_country": [
+ "US"
+ ],
+ "poster_path": "/4yMXf3DW6oCL0lVPZaZM2GypgwE.jpg",
+ "popularity": 18.095686,
+ "name": "Breaking Bad",
+ "vote_average": 8.9,
+ "vote_count": 245,
+ "media_type": "tv"
+ },
+ {
+ "backdrop_path": "/amUqExzg5eutOHshr0mbfs3lgbj.jpg",
+ "first_air_date": "2011-04-06",
+ "genre_ids": [
+ 35,
+ 10759
+ ],
+ "id": 34541,
+ "original_language": "en",
+ "original_name": "Breaking In",
+ "overview": "Breaking In is an American sitcom television series, which ran on Fox from April 6, 2011 to April 3, 2012. The series debuted as a midseason replacement following American Idol.\n\nInitially, Fox cancelled the series in May 2011, however three months later TV Guide announced that Breaking In had been renewed for a second season",
+ "origin_country": [
+ "US"
+ ],
+ "poster_path": "/m3SRLQjRgcdkgbLW02ZGerd9C9c.jpg",
+ "popularity": 1.279647,
+ "name": "Breaking In",
+ "vote_average": 3.5,
+ "vote_count": 2,
+ "media_type": "tv"
+ },
+ {
+ "adult": false,
+ "backdrop_path": "/iIvEq8vYFK1edMeLMdJFHVYHoHY.jpg",
+ "genre_ids": [
+ 27,
+ 35
+ ],
+ "id": 80384,
+ "original_language": "en",
+ "original_title": "Breaking Wind",
+ "overview": "A comedic spoof based on the worldwide phenomenon \"The Twilight Saga.\"",
+ "release_date": "2012-03-27",
+ "poster_path": "/jFpKrtmK9zeYwC6Vc2AxV39E0Sb.jpg",
+ "popularity": 1.590522,
+ "title": "Breaking Wind",
+ "video": false,
+ "vote_average": 4.9,
+ "vote_count": 22,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": "/mMKahLSpwb9Yj2B0tB6vku3tkGy.jpg",
+ "genre_ids": [
+ 99
+ ],
+ "id": 239459,
+ "original_language": "en",
+ "original_title": "No Half Measures: Creating the Final Season of Breaking Bad",
+ "overview": "A documentary about the making of season five of the acclaimed AMC series Breaking Bad.",
+ "release_date": "2013-11-26",
+ "poster_path": "/8OixSR45U5dbqv8F0tlspmTbXxN.jpg",
+ "popularity": 0.060672,
+ "title": "No Half Measures: Creating the Final Season of Breaking Bad",
+ "video": false,
+ "vote_average": 8.1,
+ "vote_count": 22,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": null,
+ "genre_ids": [
+ 18
+ ],
+ "id": 288285,
+ "original_language": "en",
+ "original_title": "Breaking Free",
+ "overview": "When troubled, cynical teen Rick chooses service at a camp for the blind over serving time at a correctional facility, he thinks he's found the easy way out. Instead, it's the way to a new life. Friendship. Step by step, as Rick helps a blinded Gymnast rediscover the joys of competition through equestrian show jumping, they begin to take control of the most important journey of all... a journey called life.",
+ "release_date": "1995-09-02",
+ "poster_path": "/5uc3PJISEptFQ8wshzArI24QmKH.jpg",
+ "popularity": 0.000942,
+ "title": "Breaking Free",
+ "video": false,
+ "vote_average": 0.0,
+ "vote_count": 0,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": "/xzkuNJxaXaNxWnSAWpWxvrwRxEh.jpg",
+ "genre_ids": [
+ 18,
+ 10749
+ ],
+ "id": 1253,
+ "original_language": "en",
+ "original_title": "Breaking and Entering",
+ "overview": "Set in a blighted, inner-city neighbourhood of London, Breaking and Entering examines an affair which unfolds between a successful British landscape architect and Amira, a Bosnian woman – the mother of a troubled teen son – who was widowed by the war in Bosnia and Herzegovina.",
+ "release_date": "2006-12-15",
+ "poster_path": "/tH4pFx2e8oxTKTn1DrZv8eqJACn.jpg",
+ "popularity": 0.402758,
+ "title": "Breaking and Entering",
+ "video": false,
+ "vote_average": 6.3,
+ "vote_count": 15,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": "/wvuvEkNmxvDqCdJ21FSQIBYx4Jt.jpg",
+ "genre_ids": [
+ 28,
+ 35,
+ 18,
+ 53,
+ 10769
+ ],
+ "id": 12543,
+ "original_language": "en",
+ "original_title": "Dai si gin",
+ "overview": "When an ambulatory TV news unit live broadcasts the embarrassing defeat of a police battalion by five bank robbers in a ballistic showdown, the credibility of the police force drops to a nadir. While on a separate investigation in a run-down building, detective Cheung discovers the hideout of the robbers. Cheung and his men have also entered the building, getting ready to take their foes out any minute. Meanwhile, in order to beat the media at its own game, Inspector Rebecca decides to turn the stakeout into a breaking news show.",
+ "release_date": "2004-01-01",
+ "poster_path": "/e1QFV4vJJbPmpWuXqISySVjSAhB.jpg",
+ "popularity": 0.207893,
+ "title": "Breaking News",
+ "video": false,
+ "vote_average": 5.8,
+ "vote_count": 6,
+ "media_type": "movie"
+ },
+ {
+ "backdrop_path": "/3lMh5BPOyI7ntGp6Qc4qQz5DhAm.jpg",
+ "first_air_date": "2012-09-09",
+ "genre_ids": [
+ 99
+ ],
+ "id": 45754,
+ "original_language": "en",
+ "original_name": "Breaking Amish",
+ "overview": "Breaking Amish, the second season of which carries a subtitle as Breaking Amish: Los Angeles, is an American reality television series on TLC that debuted September 9, 2012. The series revolves around five young Anabaptist adults who move to New York City in order to experience a different life and to make a difficult decision regarding whether to return to their communities, or to remain outside their old communities and face potential ostracism by their family and friends. It follows the cast members as they experience life in New York and face new situations involving work, friendship, romance, and lifestyle, plus the drama that develops between cast members as they undergo various experiences.\n\nThe cast-members' move to New York City differs from Rumspringa, the rite of passage in which some 16-year-old Amish are allowed to experience the outside world and to decide whether or not they wish to remain with their home communities.\n\nIn February 2013, TLC ordered a second season of Breaking Amish. On April 3, 2013, TLC confirmed this was not a second season but a spinoff, Breaking Amish: Brave New World, starring the original cast members starting their lives in Sarasota, Florida, home to a large ex-Amish and Amish community. The second season, subtitled as Breaking Amish: Los Angeles, premiered on July 21, 2013.",
+ "origin_country": [
+ "US"
+ ],
+ "poster_path": "/ivpf0UixdgdLREbm3OBe8AIvQSp.jpg",
+ "popularity": 1.056051,
+ "name": "Breaking Amish",
+ "vote_average": 0.0,
+ "vote_count": 0,
+ "media_type": "tv"
+ },
+ {
+ "adult": false,
+ "backdrop_path": "/ivb9YppjIFAokjjaTNpiglNLAGw.jpg",
+ "genre_ids": [
+ 35,
+ 18,
+ 10749
+ ],
+ "id": 26393,
+ "original_language": "en",
+ "original_title": "Breaking Up",
+ "overview": "An aloof, struggling food photographer thinks he has found true love with a fiery grade-school teacher. At first, the relationship is all wine and roses, but as they realize they have little in common besides great sex, the romance wanes, and they struggle through a succession of break-ups and reunions as they try to work things out.",
+ "release_date": "1997-10-17",
+ "poster_path": "/sHRjxdEBaqxBUaT7Jzfd39YNAxb.jpg",
+ "popularity": 1.272862,
+ "title": "Breaking Up",
+ "video": false,
+ "vote_average": 5.4,
+ "vote_count": 2,
+ "media_type": "movie"
+ },
+ {
+ "backdrop_path": null,
+ "first_air_date": "1963-09-16",
+ "genre_ids": [
+ 18
+ ],
+ "id": 16377,
+ "original_language": "en",
+ "original_name": "Breaking Point",
+ "overview": "Breaking Point is an American medical drama that aired on ABC from September 16, 1963, to April 27, 1964, continuing in rebroadcasts until September 7. The series, which was a spinoff of Ben Casey, stars Paul Richards and Eduard Franz. The series was created by Meta Rosenberg.",
+ "origin_country": [
+ "US"
+ ],
+ "poster_path": null,
+ "popularity": 1.049332,
+ "name": "Breaking Point",
+ "vote_average": 0.0,
+ "vote_count": 0,
+ "media_type": "tv"
+ },
+ {
+ "backdrop_path": null,
+ "first_air_date": null,
+ "genre_ids": [],
+ "id": 50910,
+ "original_language": "en",
+ "original_name": "Breaking News",
+ "overview": null,
+ "origin_country": [],
+ "poster_path": null,
+ "popularity": 1.00002,
+ "name": "Breaking News",
+ "vote_average": 0.0,
+ "vote_count": 0,
+ "media_type": "tv"
+ },
+ {
+ "adult": false,
+ "backdrop_path": "/aH25DYXwoWMI2Wj9cQtkLk3Ax4T.jpg",
+ "genre_ids": [
+ 35,
+ 18
+ ],
+ "id": 20283,
+ "original_language": "en",
+ "original_title": "Breaking Away",
+ "overview": "Dave, nineteen, has just graduated high school, with his 3 friends, The comical Cyril, the warm hearted but short-tempered Moocher, and the athletic, spiteful but good-hearted Mike. Now, Dave enjoys racing bikes and hopes to race the Italians one day, and even takes up the Italian culture, much to his friends and parents annoyance.",
+ "release_date": "1979-07-20",
+ "poster_path": "/sCuhny2y7vbquI9uRESpKCBzfgM.jpg",
+ "popularity": 0.184963,
+ "title": "Breaking Away",
+ "video": false,
+ "vote_average": 7.3,
+ "vote_count": 15,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": "/v6mbkSCQe8m3LgQANlKXxsAacNX.jpg",
+ "genre_ids": [
+ 28,
+ 12,
+ 18,
+ 53
+ ],
+ "id": 32005,
+ "original_language": "en",
+ "original_title": "Breaking Point",
+ "overview": "\"Breaking Point\" is a dramatic tale of corruption and self-realization, in which one man has to overcome a deep seeded conspiracy and his own lingering past in order to gain the redemption he desires.",
+ "release_date": "2009-01-01",
+ "poster_path": "/MKYsuNDyzoAyy0nLRxkbvPJoVY.jpg",
+ "popularity": 0.139665,
+ "title": "Breaking Point",
+ "video": false,
+ "vote_average": 3.8,
+ "vote_count": 3,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": "/3o9s6CeNRNuJNsQ8dSKG0AeesYb.jpg",
+ "genre_ids": [
+ 18
+ ],
+ "id": 65442,
+ "original_language": "de",
+ "original_title": "Auftauchen",
+ "overview": "Having just landed a gig with a trendy magazine, young photographer Nadja celebrates at the local disco, where she bumps into Darius, a 20-year-old skateboarder. Although her frankness at first scares him, the two quickly become a couple, and as their intoxicating affair takes off, they seem like passionate soul mates. Soon, however, career demands and emotional intensity gradually put a strain on their rapport, and things turn even more complicated...",
+ "release_date": "2006-10-25",
+ "poster_path": "/lVGYuffa9GqvPddYIg6C1u62VKg.jpg",
+ "popularity": 1.098577,
+ "title": "Breaking the Surface",
+ "video": false,
+ "vote_average": 3.5,
+ "vote_count": 1,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": null,
+ "genre_ids": [],
+ "id": 214351,
+ "original_language": "en",
+ "original_title": "Breaking Loose",
+ "overview": "Four best friends. They've been to war, they've seen life, but they are still passionate, young and willing to serve their country. They found their place at OMON - Russian Special Police Squad. They can count only on each other, and their real family is themselves. After working hours they become simple guys with ordinary dreams like family and comfort. But life changes when once in a night club the friends incidentally get in a fight with the local mafia. It turns out that they have no fear and they are ready to stand for each other whatever happens.",
+ "release_date": "2014-05-08",
+ "poster_path": "/5jZWisKO0K9GgWbMBIkW27K3ldv.jpg",
+ "popularity": 1.013158,
+ "title": "Breaking Loose",
+ "video": false,
+ "vote_average": 0.0,
+ "vote_count": 0,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": null,
+ "genre_ids": [],
+ "id": 306326,
+ "original_language": "en",
+ "original_title": "Breaking Barriers",
+ "overview": "Breaking Barriers demonstrates what it takes to build and drive a vehicle faster than anyone on the planet. Follow American automobile entrepreneur John Hennessey's pursuit of the production vehicle land speed record and trace the roots of land speed racing from the early days of hot rodding to today. We discover that since the advent of the automobile, the pursuit of speed and the fight for the title of \"fastest car\" are intrinsically connected.",
+ "release_date": "2014-05-07",
+ "poster_path": null,
+ "popularity": 1.005699,
+ "title": "Breaking Barriers",
+ "video": false,
+ "vote_average": 0.0,
+ "vote_count": 0,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": "/2IFEvbvveOT5Xx15etROmMXAzyV.jpg",
+ "genre_ids": [],
+ "id": 303686,
+ "original_language": "en",
+ "original_title": "Breaking Trail",
+ "overview": "Last season Utah’s Wasatch Mountains and most of North America experienced a record breaking doozie, making our never ending mission to flatten as many snowflakes as possible almost easy. We estimate the number of crystals crushed to be somewhere in the trillions. If you’ve had the\r extreme pleasure of viewing one of our previous films, then the obscenedisplay of exploding snow will be nothing new. On closer inspection you will notice that Powderwhore is no longer focusing primarily on the telemark turn. BREAKING TRAIL will highlight riders of all disciplines choosing their own backcountry adventures. Warning! There are no shots of helicopters filming other helicopters or hankie-clad 16-year-olds hepped up on energy drinks spinning to rap music. And you won’t win a Jeep if you come out to a premiere. You will find a mixed bag of highly talented and dedicated\r individuals who enjoy hiking out into the unknown in search of turns and adventure.",
+ "release_date": "2011-11-10",
+ "poster_path": "/qGtPVHThCZcsinhchTjdIAFQrrJ.jpg",
+ "popularity": 1.002161,
+ "title": "Breaking Trail",
+ "video": false,
+ "vote_average": 0.0,
+ "vote_count": 0,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": null,
+ "genre_ids": [],
+ "id": 149227,
+ "original_language": "en",
+ "original_title": "Breaking Man",
+ "overview": "Pastor Sean seems to have everything, but inside his life is falling apart. His wife is leaving, he loses his job & has quit believing in God. As his life spirals out of control he is faced with the option of standing strong or breaking.",
+ "release_date": "2012-02-07",
+ "poster_path": "/hNtX67PNhhbfVDYDcTviDaEecRb.jpg",
+ "popularity": 1.002087,
+ "title": "Breaking Man",
+ "video": false,
+ "vote_average": 0.0,
+ "vote_count": 0,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": "/7L6wIguZewE9FhqOUoPPZ7jaMdV.jpg",
+ "genre_ids": [
+ 53
+ ],
+ "id": 32707,
+ "original_language": "en",
+ "original_title": "Breaking Dawn",
+ "overview": "Within the confines of an insane asylum languish many would-be seers and messiahs. Medical students meet them day in, day out. But when Eve meets Don Wake, she discovers he's not your run-of-the-mill paranoic. In fact, his visions of her life on the outside tread the line between fantasy and reality as a stalker becomes known to her. She could be in danger; it could all be in her head.",
+ "release_date": "2005-02-02",
+ "poster_path": "/cysO5EwGbNFJWzETY0u8YBBomWj.jpg",
+ "popularity": 0.00179,
+ "title": "Breaking Dawn",
+ "video": false,
+ "vote_average": 0.0,
+ "vote_count": 1,
+ "media_type": "movie"
+ },
+ {
+ "adult": false,
+ "backdrop_path": null,
+ "genre_ids": [],
+ "id": 332501,
+ "original_language": "en",
+ "original_title": "Breaking Night",
+ "overview": "As night gives way to morning, GIRL breaks free becoming WOMAN. Yolonda Ross: director.",
+ "release_date": "2012-01-01",
+ "poster_path": null,
+ "popularity": 1.001721,
+ "title": "Breaking Night",
+ "video": false,
+ "vote_average": 0.0,
+ "vote_count": 0,
+ "media_type": "movie"
+ }
+ ],
+ "total_pages": 7,
+ "total_results": 134
+}
diff --git a/libjsonpp/json.ll b/libjsonpp/json.ll
index aae3ed2..58dff7a 100644
--- a/libjsonpp/json.ll
+++ b/libjsonpp/json.ll
@@ -97,7 +97,13 @@ escape "\\"
yy_pop_state();
}
-<ARRAY_ITEM,ARRAY_NEXT>{endarray} {
+<ARRAY_ITEM>{endarray} {
+ PushArray();
+ yy_pop_state();
+ yy_pop_state();
+}
+
+<ARRAY_NEXT>{endarray} {
PushArray();
yy_pop_state();
}
diff --git a/libjsonpp/test1.cpp b/libjsonpp/test1.cpp
index 8b18e3b..fd98c44 100644
--- a/libjsonpp/test1.cpp
+++ b/libjsonpp/test1.cpp
@@ -84,7 +84,17 @@ BOOST_AUTO_TEST_CASE( parse_empty_array )
{
const Glib::ustring val(" [ ] ");
BOOST_REQUIRE(boost::get<json::Array>(json::parseValue(val)).empty());
+}
+BOOST_AUTO_TEST_CASE( parse_empty_arrary_in_object )
+{
+ const Glib::ustring val(" { \"v1\": [ ], \"v2\": 100 } ");
+ auto value = json::parseValue(val);
+ BOOST_REQUIRE_EQUAL(3, value.which());
+ auto obj = boost::get<json::Object>(value);
+ BOOST_REQUIRE_EQUAL(2, obj.size());
+ BOOST_REQUIRE(boost::get<json::Array>(*obj["v1"]).empty());
+ BOOST_REQUIRE_EQUAL(100, boost::get<json::Number>(*obj["v2"]));
}
BOOST_AUTO_TEST_CASE( parse_broken_array )
@@ -174,12 +184,18 @@ BOOST_AUTO_TEST_CASE( parse_string_escapedUnicode )
BOOST_REQUIRE_EQUAL("A Űņĩćőđē string.", boost::get<json::String>(json::parseValue(val)));
}
-BOOST_AUTO_TEST_CASE( parse_sample_complexFile )
+BOOST_AUTO_TEST_CASE( parse_sample_complexFile1 )
{
std::ifstream inFile((root / "initial" / "sample1.json").string());
json::Value obj = json::parseValue(inFile, "utf-8");
}
+BOOST_AUTO_TEST_CASE( parse_sample_complexFile2 )
+{
+ std::ifstream inFile((root / "initial" / "sample2.json").string());
+ json::Value obj = json::parseValue(inFile, "utf-8");
+}
+
BOOST_AUTO_TEST_CASE( parse_from_itr )
{
const Glib::ustring val(" \"A \\u0170\\u0146\\u0129\\u0107\\u0151\\u0111\\u0113 string.\" ");