James E. King, III | 375bfee | 2017-10-26 00:09:34 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 20 | "use strict"; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 21 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 22 | const helpers = require("./helpers"); |
| 23 | const ttypes = require(`./${helpers.genPath}/ThriftTest_types`); |
| 24 | const Int64 = require("node-int64"); |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 25 | |
| 26 | //all Languages in UTF-8 |
| 27 | /*jshint -W100 */ |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 28 | const stringTest = (module.exports.stringTest = |
| 29 | "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " + |
| 30 | "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " + |
| 31 | "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " + |
| 32 | "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " + |
| 33 | "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, " + |
| 34 | "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, " + |
| 35 | "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, " + |
| 36 | "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, " + |
| 37 | "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, " + |
| 38 | "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, " + |
| 39 | "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, " + |
| 40 | "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, " + |
| 41 | "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " + |
| 42 | "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " + |
| 43 | "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " + |
| 44 | "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, " + |
| 45 | "Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, " + |
| 46 | "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " + |
| 47 | "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " + |
| 48 | "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple " + |
| 49 | "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, " + |
| 50 | "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, " + |
| 51 | "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " + |
| 52 | "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " + |
| 53 | "Bân-lâm-gú, 粵語"); |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 54 | /*jshint +W100 */ |
| 55 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 56 | const specialCharacters = (module.exports.specialCharacters = |
| 57 | 'quote: " backslash:' + |
| 58 | " forwardslash-escaped: / " + |
| 59 | " backspace: \b formfeed: \f newline: \n return: \r tab: " + |
| 60 | ' now-all-of-them-together: "\\/\b\n\r\t' + |
| 61 | " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><" + |
| 62 | ' char-to-test-json-parsing: ]] "]] \\" }}}{ [[[ '); |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 63 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 64 | const mapTestInput = (module.exports.mapTestInput = { |
| 65 | a: "123", |
| 66 | "a b": "with spaces ", |
| 67 | same: "same", |
| 68 | "0": "numeric key", |
| 69 | longValue: stringTest, |
| 70 | stringTest: "long key" |
| 71 | }); |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 72 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 73 | const simple = [ |
| 74 | ["testVoid", undefined], |
| 75 | ["testString", "Test"], |
| 76 | ["testString", ""], |
| 77 | ["testString", stringTest], |
| 78 | ["testString", specialCharacters], |
| 79 | ["testBool", true], |
| 80 | ["testBool", false], |
| 81 | ["testByte", 1], |
| 82 | ["testByte", 0], |
| 83 | ["testByte", -1], |
| 84 | ["testByte", -127], |
| 85 | ["testI32", -1], |
| 86 | ["testDouble", -5.2098523], |
| 87 | ["testDouble", 7.012052175215044], |
| 88 | ["testEnum", ttypes.Numberz.ONE], |
| 89 | ["testI64", 5], |
| 90 | ["testI64", -5], |
| 91 | ["testI64", 734359738368], |
| 92 | ["testI64", -734359738368], |
| 93 | ["testI64", new Int64(new Buffer([0, 0x20, 0, 0, 0, 0, 0, 1]))], // 2^53+1 |
| 94 | [ |
| 95 | "testI64", |
| 96 | new Int64(new Buffer([0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])) |
| 97 | ], // -2^53-1 |
| 98 | ["testTypedef", 69] |
| 99 | ]; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 100 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 101 | const mapout = {}; |
| 102 | for (let i = 0; i < 5; ++i) { |
| 103 | mapout[i] = i - 10; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 104 | } |
| 105 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 106 | const deep = [ |
| 107 | [ |
| 108 | "testList", |
| 109 | [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
| 110 | ] |
Randy Abernethy | 983bf7d | 2015-10-09 12:28:57 -0700 | [diff] [blame] | 111 | ]; |
| 112 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 113 | const deepUnordered = [ |
| 114 | ["testMap", mapout], |
| 115 | ["testSet", [1, 2, 3]], |
| 116 | ["testStringMap", mapTestInput] |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 117 | ]; |
| 118 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 119 | const out = new ttypes.Xtruct({ |
| 120 | string_thing: "Zero", |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 121 | byte_thing: 1, |
| 122 | i32_thing: -3, |
| 123 | i64_thing: 1000000 |
| 124 | }); |
| 125 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 126 | const out2 = new ttypes.Xtruct2(); |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 127 | out2.byte_thing = 1; |
| 128 | out2.struct_thing = out; |
| 129 | out2.i32_thing = 5; |
| 130 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 131 | const crazy = new ttypes.Insanity({ |
| 132 | userMap: { "5": 5, "8": 8 }, |
| 133 | xtructs: [ |
| 134 | new ttypes.Xtruct({ |
| 135 | string_thing: "Goodbye4", |
| 136 | byte_thing: 4, |
| 137 | i32_thing: 4, |
| 138 | i64_thing: 4 |
| 139 | }), |
| 140 | new ttypes.Xtruct({ |
| 141 | string_thing: "Hello2", |
| 142 | byte_thing: 2, |
| 143 | i32_thing: 2, |
| 144 | i64_thing: 2 |
| 145 | }) |
| 146 | ] |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 147 | }); |
| 148 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 149 | const crazy2 = new ttypes.Insanity({ |
| 150 | userMap: { "5": 5, "8": 8 }, |
| 151 | xtructs: [ |
| 152 | { |
| 153 | string_thing: "Goodbye4", |
| 154 | byte_thing: 4, |
| 155 | i32_thing: 4, |
| 156 | i64_thing: 4 |
| 157 | }, |
| 158 | { |
| 159 | string_thing: "Hello2", |
| 160 | byte_thing: 2, |
| 161 | i32_thing: 2, |
| 162 | i64_thing: 2 |
| 163 | } |
| 164 | ] |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 165 | }); |
| 166 | |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame^] | 167 | const insanity = { |
| 168 | "1": { "2": crazy, "3": crazy }, |
| 169 | "2": { "6": { userMap: {}, xtructs: [] } } |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | module.exports.simple = simple; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 173 | module.exports.deep = deep; |
Randy Abernethy | 983bf7d | 2015-10-09 12:28:57 -0700 | [diff] [blame] | 174 | module.exports.deepUnordered = deepUnordered; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 175 | |
| 176 | module.exports.out = out; |
| 177 | module.exports.out2 = out2; |
| 178 | module.exports.crazy = crazy; |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 179 | module.exports.crazy2 = crazy2; |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 180 | module.exports.insanity = insanity; |