| Jake Farrell | b5a18a1 | 2012-10-09 01:10:43 +0000 | [diff] [blame] | 1 | # encoding: UTF-8 |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 2 | # |
| 3 | # Licensed to the Apache Software Foundation (ASF) under one |
| 4 | # or more contributor license agreements. See the NOTICE file |
| 5 | # distributed with this work for additional information |
| 6 | # regarding copyright ownership. The ASF licenses this file |
| 7 | # to you under the Apache License, Version 2.0 (the |
| 8 | # "License"); you may not use this file except in compliance |
| 9 | # with the License. You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, |
| 14 | # software distributed under the License is distributed on an |
| 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | # KIND, either express or implied. See the License for the |
| 17 | # specific language governing permissions and limitations |
| 18 | # under the License. |
| 19 | # |
| 20 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 21 | require 'spec_helper' |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 22 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 23 | describe 'JsonProtocol' do |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 24 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 25 | describe Thrift::JsonProtocol do |
| 26 | before(:each) do |
| 27 | @trans = Thrift::MemoryBufferTransport.new |
| 28 | @prot = Thrift::JsonProtocol.new(@trans) |
| 29 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 30 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 31 | it "should write json escaped char" do |
| 32 | @prot.write_json_escape_char("\n") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 33 | expect(@trans.read(@trans.available)).to eq('\u000a') |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 34 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 35 | @prot.write_json_escape_char(" ") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 36 | expect(@trans.read(@trans.available)).to eq('\u0020') |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 37 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 38 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 39 | it "should write json char" do |
| 40 | @prot.write_json_char("\n") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 41 | expect(@trans.read(@trans.available)).to eq('\\n') |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 42 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 43 | @prot.write_json_char(" ") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 44 | expect(@trans.read(@trans.available)).to eq(' ') |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 45 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 46 | @prot.write_json_char("\\") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 47 | expect(@trans.read(@trans.available)).to eq("\\\\") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 48 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 49 | @prot.write_json_char("@") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 50 | expect(@trans.read(@trans.available)).to eq('@') |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 51 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 52 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 53 | it "should write json string" do |
| 54 | @prot.write_json_string("this is a \\ json\nstring") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 55 | expect(@trans.read(@trans.available)).to eq("\"this is a \\\\ json\\nstring\"") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 56 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 57 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 58 | it "should write json base64" do |
| 59 | @prot.write_json_base64("this is a base64 string") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 60 | expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 61 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 62 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 63 | it "should write json integer" do |
| 64 | @prot.write_json_integer(45) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 65 | expect(@trans.read(@trans.available)).to eq("45") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 66 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 67 | @prot.write_json_integer(33000) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 68 | expect(@trans.read(@trans.available)).to eq("33000") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 69 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 70 | @prot.write_json_integer(3000000000) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 71 | expect(@trans.read(@trans.available)).to eq("3000000000") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 72 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 73 | @prot.write_json_integer(6000000000) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 74 | expect(@trans.read(@trans.available)).to eq("6000000000") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 75 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 76 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 77 | it "should write json double" do |
| 78 | @prot.write_json_double(12.3) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 79 | expect(@trans.read(@trans.available)).to eq("12.3") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 80 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 81 | @prot.write_json_double(-3.21) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 82 | expect(@trans.read(@trans.available)).to eq("-3.21") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 83 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 84 | @prot.write_json_double(((+1.0/0.0)/(+1.0/0.0))) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 85 | expect(@trans.read(@trans.available)).to eq("\"NaN\"") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 86 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 87 | @prot.write_json_double((+1.0/0.0)) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 88 | expect(@trans.read(@trans.available)).to eq("\"Infinity\"") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 89 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 90 | @prot.write_json_double((-1.0/0.0)) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 91 | expect(@trans.read(@trans.available)).to eq("\"-Infinity\"") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 92 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 93 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 94 | it "should write json object start" do |
| 95 | @prot.write_json_object_start |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 96 | expect(@trans.read(@trans.available)).to eq("{") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 97 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 98 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 99 | it "should write json object end" do |
| 100 | @prot.write_json_object_end |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 101 | expect(@trans.read(@trans.available)).to eq("}") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 102 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 103 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 104 | it "should write json array start" do |
| 105 | @prot.write_json_array_start |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 106 | expect(@trans.read(@trans.available)).to eq("[") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 107 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 108 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 109 | it "should write json array end" do |
| 110 | @prot.write_json_array_end |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 111 | expect(@trans.read(@trans.available)).to eq("]") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 112 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 113 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 114 | it "should write message begin" do |
| 115 | @prot.write_message_begin("name", 12, 32) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 116 | expect(@trans.read(@trans.available)).to eq("[1,\"name\",12,32") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 117 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 118 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 119 | it "should write message end" do |
| 120 | @prot.write_message_end |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 121 | expect(@trans.read(@trans.available)).to eq("]") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 122 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 123 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 124 | it "should write struct begin" do |
| 125 | @prot.write_struct_begin("name") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 126 | expect(@trans.read(@trans.available)).to eq("{") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 127 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 128 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 129 | it "should write struct end" do |
| 130 | @prot.write_struct_end |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 131 | expect(@trans.read(@trans.available)).to eq("}") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 132 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 133 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 134 | it "should write field begin" do |
| 135 | @prot.write_field_begin("name", Thrift::Types::STRUCT, 32) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 136 | expect(@trans.read(@trans.available)).to eq("32{\"rec\"") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 137 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 138 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 139 | it "should write field end" do |
| 140 | @prot.write_field_end |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 141 | expect(@trans.read(@trans.available)).to eq("}") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 142 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 143 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 144 | it "should write field stop" do |
| 145 | @prot.write_field_stop |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 146 | expect(@trans.read(@trans.available)).to eq("") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 147 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 148 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 149 | it "should write map begin" do |
| 150 | @prot.write_map_begin(Thrift::Types::STRUCT, Thrift::Types::LIST, 32) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 151 | expect(@trans.read(@trans.available)).to eq("[\"rec\",\"lst\",32,{") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 152 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 153 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 154 | it "should write map end" do |
| 155 | @prot.write_map_end |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 156 | expect(@trans.read(@trans.available)).to eq("}]") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 157 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 158 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 159 | it "should write list begin" do |
| 160 | @prot.write_list_begin(Thrift::Types::STRUCT, 32) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 161 | expect(@trans.read(@trans.available)).to eq("[\"rec\",32") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 162 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 163 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 164 | it "should write list end" do |
| 165 | @prot.write_list_end |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 166 | expect(@trans.read(@trans.available)).to eq("]") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 167 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 168 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 169 | it "should write set begin" do |
| 170 | @prot.write_set_begin(Thrift::Types::STRUCT, 32) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 171 | expect(@trans.read(@trans.available)).to eq("[\"rec\",32") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 172 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 173 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 174 | it "should write set end" do |
| 175 | @prot.write_set_end |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 176 | expect(@trans.read(@trans.available)).to eq("]") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 177 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 178 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 179 | it "should write bool" do |
| 180 | @prot.write_bool(true) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 181 | expect(@trans.read(@trans.available)).to eq("1") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 182 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 183 | @prot.write_bool(false) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 184 | expect(@trans.read(@trans.available)).to eq("0") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 185 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 186 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 187 | it "should write byte" do |
| 188 | @prot.write_byte(100) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 189 | expect(@trans.read(@trans.available)).to eq("100") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 190 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 191 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 192 | it "should write i16" do |
| 193 | @prot.write_i16(1000) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 194 | expect(@trans.read(@trans.available)).to eq("1000") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 195 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 196 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 197 | it "should write i32" do |
| 198 | @prot.write_i32(3000000000) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 199 | expect(@trans.read(@trans.available)).to eq("3000000000") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 200 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 201 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 202 | it "should write i64" do |
| 203 | @prot.write_i64(6000000000) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 204 | expect(@trans.read(@trans.available)).to eq("6000000000") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 205 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 206 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 207 | it "should write double" do |
| 208 | @prot.write_double(1.23) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 209 | expect(@trans.read(@trans.available)).to eq("1.23") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 210 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 211 | @prot.write_double(-32.1) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 212 | expect(@trans.read(@trans.available)).to eq("-32.1") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 213 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 214 | @prot.write_double(((+1.0/0.0)/(+1.0/0.0))) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 215 | expect(@trans.read(@trans.available)).to eq("\"NaN\"") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 216 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 217 | @prot.write_double((+1.0/0.0)) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 218 | expect(@trans.read(@trans.available)).to eq("\"Infinity\"") |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 219 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 220 | @prot.write_double((-1.0/0.0)) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 221 | expect(@trans.read(@trans.available)).to eq("\"-Infinity\"") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 222 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 223 | |
| Dmytro Shteflyuk | d24b8a0 | 2025-12-01 18:41:20 -0500 | [diff] [blame^] | 224 | it 'should write string' do |
| 225 | @prot.write_string('this is a test string') |
| 226 | a = @trans.read(@trans.available) |
| 227 | expect(a).to eq('"this is a test string"'.force_encoding(Encoding::BINARY)) |
| 228 | expect(a.encoding).to eq(Encoding::BINARY) |
| 229 | end |
| Jake Farrell | b5a18a1 | 2012-10-09 01:10:43 +0000 | [diff] [blame] | 230 | |
| Dmytro Shteflyuk | d24b8a0 | 2025-12-01 18:41:20 -0500 | [diff] [blame^] | 231 | it 'should write string with unicode characters' do |
| 232 | @prot.write_string("this is a test string with unicode characters: \u20AC \u20AD") |
| 233 | a = @trans.read(@trans.available) |
| 234 | expect(a).to eq("\"this is a test string with unicode characters: \u20AC \u20AD\"".force_encoding(Encoding::BINARY)) |
| 235 | expect(a.encoding).to eq(Encoding::BINARY) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 236 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 237 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 238 | it "should write binary" do |
| 239 | @prot.write_binary("this is a base64 string") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 240 | expect(@trans.read(@trans.available)).to eq("\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\"") |
| Jens Geyer | 123258b | 2015-10-02 00:38:17 +0200 | [diff] [blame] | 241 | end |
| 242 | |
| 243 | it "should write long binary" do |
| 244 | @prot.write_binary((0...256).to_a.pack('C*')) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 245 | expect(@trans.read(@trans.available)).to eq("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 246 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 247 | |
| Dmytro Shteflyuk | e9ac8e3 | 2025-11-19 23:33:23 -0500 | [diff] [blame] | 248 | it "should write a uuid" do |
| 249 | @prot.write_uuid("00112233-4455-6677-8899-aabbccddeeff") |
| 250 | expect(@trans.read(@trans.available)).to eq("\"00112233-4455-6677-8899-aabbccddeeff\"") |
| 251 | end |
| 252 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 253 | it "should get type name for type id" do |
| 254 | expect {@prot.get_type_name_for_type_id(Thrift::Types::STOP)}.to raise_error(NotImplementedError) |
| 255 | expect {@prot.get_type_name_for_type_id(Thrift::Types::VOID)}.to raise_error(NotImplementedError) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 256 | expect(@prot.get_type_name_for_type_id(Thrift::Types::BOOL)).to eq("tf") |
| 257 | expect(@prot.get_type_name_for_type_id(Thrift::Types::BYTE)).to eq("i8") |
| 258 | expect(@prot.get_type_name_for_type_id(Thrift::Types::DOUBLE)).to eq("dbl") |
| 259 | expect(@prot.get_type_name_for_type_id(Thrift::Types::I16)).to eq("i16") |
| 260 | expect(@prot.get_type_name_for_type_id(Thrift::Types::I32)).to eq("i32") |
| 261 | expect(@prot.get_type_name_for_type_id(Thrift::Types::I64)).to eq("i64") |
| 262 | expect(@prot.get_type_name_for_type_id(Thrift::Types::STRING)).to eq("str") |
| 263 | expect(@prot.get_type_name_for_type_id(Thrift::Types::STRUCT)).to eq("rec") |
| 264 | expect(@prot.get_type_name_for_type_id(Thrift::Types::MAP)).to eq("map") |
| 265 | expect(@prot.get_type_name_for_type_id(Thrift::Types::SET)).to eq("set") |
| 266 | expect(@prot.get_type_name_for_type_id(Thrift::Types::LIST)).to eq("lst") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 267 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 268 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 269 | it "should get type id for type name" do |
| 270 | expect {@prot.get_type_id_for_type_name("pp")}.to raise_error(NotImplementedError) |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 271 | expect(@prot.get_type_id_for_type_name("tf")).to eq(Thrift::Types::BOOL) |
| 272 | expect(@prot.get_type_id_for_type_name("i8")).to eq(Thrift::Types::BYTE) |
| 273 | expect(@prot.get_type_id_for_type_name("dbl")).to eq(Thrift::Types::DOUBLE) |
| 274 | expect(@prot.get_type_id_for_type_name("i16")).to eq(Thrift::Types::I16) |
| 275 | expect(@prot.get_type_id_for_type_name("i32")).to eq(Thrift::Types::I32) |
| 276 | expect(@prot.get_type_id_for_type_name("i64")).to eq(Thrift::Types::I64) |
| 277 | expect(@prot.get_type_id_for_type_name("str")).to eq(Thrift::Types::STRING) |
| 278 | expect(@prot.get_type_id_for_type_name("rec")).to eq(Thrift::Types::STRUCT) |
| 279 | expect(@prot.get_type_id_for_type_name("map")).to eq(Thrift::Types::MAP) |
| 280 | expect(@prot.get_type_id_for_type_name("set")).to eq(Thrift::Types::SET) |
| 281 | expect(@prot.get_type_id_for_type_name("lst")).to eq(Thrift::Types::LIST) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 282 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 283 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 284 | it "should read json syntax char" do |
| 285 | @trans.write('F') |
| 286 | expect {@prot.read_json_syntax_char('G')}.to raise_error(Thrift::ProtocolException) |
| 287 | @trans.write('H') |
| 288 | @prot.read_json_syntax_char('H') |
| 289 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 290 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 291 | it "should read json escape char" do |
| 292 | @trans.write('0054') |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 293 | expect(@prot.read_json_escape_char).to eq('T') |
| Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 294 | |
| 295 | @trans.write("\"\\\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 296 | expect(@prot.read_json_string(false)).to eq("\"") |
| Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 297 | |
| 298 | @trans.write("\"\\\\\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 299 | expect(@prot.read_json_string(false)).to eq("\\") |
| Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 300 | |
| 301 | @trans.write("\"\\/\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 302 | expect(@prot.read_json_string(false)).to eq("\/") |
| Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 303 | |
| 304 | @trans.write("\"\\b\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 305 | expect(@prot.read_json_string(false)).to eq("\b") |
| Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 306 | |
| 307 | @trans.write("\"\\f\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 308 | expect(@prot.read_json_string(false)).to eq("\f") |
| Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 309 | |
| 310 | @trans.write("\"\\n\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 311 | expect(@prot.read_json_string(false)).to eq("\n") |
| Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 312 | |
| 313 | @trans.write("\"\\r\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 314 | expect(@prot.read_json_string(false)).to eq("\r") |
| Nobuaki Sukegawa | 8cd519f | 2015-10-10 01:52:13 +0900 | [diff] [blame] | 315 | |
| 316 | @trans.write("\"\\t\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 317 | expect(@prot.read_json_string(false)).to eq("\t") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 318 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 319 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 320 | it "should read json string" do |
| 321 | @trans.write("\"\\P") |
| 322 | expect {@prot.read_json_string(false)}.to raise_error(Thrift::ProtocolException) |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 323 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 324 | @trans.write("\"this is a test string\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 325 | expect(@prot.read_json_string).to eq("this is a test string") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 326 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 327 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 328 | it "should read json base64" do |
| 329 | @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 330 | expect(@prot.read_json_base64).to eq("this is a test string") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 331 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 332 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 333 | it "should is json numeric" do |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 334 | expect(@prot.is_json_numeric("A")).to eq(false) |
| 335 | expect(@prot.is_json_numeric("+")).to eq(true) |
| 336 | expect(@prot.is_json_numeric("-")).to eq(true) |
| 337 | expect(@prot.is_json_numeric(".")).to eq(true) |
| 338 | expect(@prot.is_json_numeric("0")).to eq(true) |
| 339 | expect(@prot.is_json_numeric("1")).to eq(true) |
| 340 | expect(@prot.is_json_numeric("2")).to eq(true) |
| 341 | expect(@prot.is_json_numeric("3")).to eq(true) |
| 342 | expect(@prot.is_json_numeric("4")).to eq(true) |
| 343 | expect(@prot.is_json_numeric("5")).to eq(true) |
| 344 | expect(@prot.is_json_numeric("6")).to eq(true) |
| 345 | expect(@prot.is_json_numeric("7")).to eq(true) |
| 346 | expect(@prot.is_json_numeric("8")).to eq(true) |
| 347 | expect(@prot.is_json_numeric("9")).to eq(true) |
| 348 | expect(@prot.is_json_numeric("E")).to eq(true) |
| 349 | expect(@prot.is_json_numeric("e")).to eq(true) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 350 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 351 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 352 | it "should read json numeric chars" do |
| 353 | @trans.write("1.453E45T") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 354 | expect(@prot.read_json_numeric_chars).to eq("1.453E45") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 355 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 356 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 357 | it "should read json integer" do |
| 358 | @trans.write("1.45\"\"") |
| 359 | expect {@prot.read_json_integer}.to raise_error(Thrift::ProtocolException) |
| 360 | @prot.read_string |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 361 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 362 | @trans.write("1453T") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 363 | expect(@prot.read_json_integer).to eq(1453) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 364 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 365 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 366 | it "should read json double" do |
| 367 | @trans.write("1.45e3e01\"\"") |
| 368 | expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException) |
| 369 | @prot.read_string |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 370 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 371 | @trans.write("\"1.453e01\"") |
| 372 | expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException) |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 373 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 374 | @trans.write("1.453e01\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 375 | expect(@prot.read_json_double).to eq(14.53) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 376 | @prot.read_string |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 377 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 378 | @trans.write("\"NaN\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 379 | expect(@prot.read_json_double.nan?).to eq(true) |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 380 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 381 | @trans.write("\"Infinity\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 382 | expect(@prot.read_json_double).to eq(+1.0/0.0) |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 383 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 384 | @trans.write("\"-Infinity\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 385 | expect(@prot.read_json_double).to eq(-1.0/0.0) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 386 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 387 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 388 | it "should read json object start" do |
| 389 | @trans.write("{") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 390 | expect(@prot.read_json_object_start).to eq(nil) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 391 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 392 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 393 | it "should read json object end" do |
| 394 | @trans.write("}") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 395 | expect(@prot.read_json_object_end).to eq(nil) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 396 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 397 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 398 | it "should read json array start" do |
| 399 | @trans.write("[") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 400 | expect(@prot.read_json_array_start).to eq(nil) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 401 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 402 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 403 | it "should read json array end" do |
| 404 | @trans.write("]") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 405 | expect(@prot.read_json_array_end).to eq(nil) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 406 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 407 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 408 | it "should read_message_begin" do |
| 409 | @trans.write("[2,") |
| 410 | expect {@prot.read_message_begin}.to raise_error(Thrift::ProtocolException) |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 411 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 412 | @trans.write("[1,\"name\",12,32\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 413 | expect(@prot.read_message_begin).to eq(["name", 12, 32]) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 414 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 415 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 416 | it "should read message end" do |
| 417 | @trans.write("]") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 418 | expect(@prot.read_message_end).to eq(nil) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 419 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 420 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 421 | it "should read struct begin" do |
| 422 | @trans.write("{") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 423 | expect(@prot.read_struct_begin).to eq(nil) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 424 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 425 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 426 | it "should read struct end" do |
| 427 | @trans.write("}") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 428 | expect(@prot.read_struct_end).to eq(nil) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 429 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 430 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 431 | it "should read field begin" do |
| 432 | @trans.write("1{\"rec\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 433 | expect(@prot.read_field_begin).to eq([nil, 12, 1]) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 434 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 435 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 436 | it "should read field end" do |
| 437 | @trans.write("}") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 438 | expect(@prot.read_field_end).to eq(nil) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 439 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 440 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 441 | it "should read map begin" do |
| 442 | @trans.write("[\"rec\",\"lst\",2,{") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 443 | expect(@prot.read_map_begin).to eq([12, 15, 2]) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 444 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 445 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 446 | it "should read map end" do |
| 447 | @trans.write("}]") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 448 | expect(@prot.read_map_end).to eq(nil) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 449 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 450 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 451 | it "should read list begin" do |
| 452 | @trans.write("[\"rec\",2\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 453 | expect(@prot.read_list_begin).to eq([12, 2]) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 454 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 455 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 456 | it "should read list end" do |
| 457 | @trans.write("]") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 458 | expect(@prot.read_list_end).to eq(nil) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 459 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 460 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 461 | it "should read set begin" do |
| Roger Meier | 772b2b1 | 2013-01-19 21:04:12 +0100 | [diff] [blame] | 462 | @trans.write("[\"rec\",2\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 463 | expect(@prot.read_set_begin).to eq([12, 2]) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 464 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 465 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 466 | it "should read set end" do |
| 467 | @trans.write("]") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 468 | expect(@prot.read_set_end).to eq(nil) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 469 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 470 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 471 | it "should read bool" do |
| 472 | @trans.write("0\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 473 | expect(@prot.read_bool).to eq(false) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 474 | @prot.read_string |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 475 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 476 | @trans.write("1\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 477 | expect(@prot.read_bool).to eq(true) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 478 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 479 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 480 | it "should read byte" do |
| 481 | @trans.write("60\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 482 | expect(@prot.read_byte).to eq(60) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 483 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 484 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 485 | it "should read i16" do |
| 486 | @trans.write("1000\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 487 | expect(@prot.read_i16).to eq(1000) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 488 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 489 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 490 | it "should read i32" do |
| 491 | @trans.write("3000000000\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 492 | expect(@prot.read_i32).to eq(3000000000) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 493 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 494 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 495 | it "should read i64" do |
| 496 | @trans.write("6000000000\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 497 | expect(@prot.read_i64).to eq(6000000000) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 498 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 499 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 500 | it "should read double" do |
| 501 | @trans.write("12.23\"\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 502 | expect(@prot.read_double).to eq(12.23) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 503 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 504 | |
| Dmytro Shteflyuk | d24b8a0 | 2025-12-01 18:41:20 -0500 | [diff] [blame^] | 505 | it 'should read string' do |
| 506 | @trans.write('"this is a test string"'.force_encoding(Encoding::BINARY)) |
| 507 | a = @prot.read_string |
| 508 | expect(a).to eq('this is a test string') |
| 509 | expect(a.encoding).to eq(Encoding::UTF_8) |
| 510 | end |
| Jake Farrell | b5a18a1 | 2012-10-09 01:10:43 +0000 | [diff] [blame] | 511 | |
| Dmytro Shteflyuk | d24b8a0 | 2025-12-01 18:41:20 -0500 | [diff] [blame^] | 512 | it 'should read string with unicode characters' do |
| 513 | @trans.write('"this is a test string with unicode characters: \u20AC \u20AD"'.force_encoding(Encoding::BINARY)) |
| 514 | a = @prot.read_string |
| 515 | expect(a).to eq("this is a test string with unicode characters: \u20AC \u20AD") |
| 516 | expect(a.encoding).to eq(Encoding::UTF_8) |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 517 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 518 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 519 | it "should read binary" do |
| 520 | @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 521 | expect(@prot.read_binary).to eq("this is a test string") |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 522 | end |
| Jens Geyer | 123258b | 2015-10-02 00:38:17 +0200 | [diff] [blame] | 523 | |
| 524 | it "should read long binary" do |
| 525 | @trans.write("\"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==\"") |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 526 | expect(@prot.read_binary.bytes.to_a).to eq((0...256).to_a) |
| Jens Geyer | 123258b | 2015-10-02 00:38:17 +0200 | [diff] [blame] | 527 | end |
| Dmytro Shteflyuk | e9ac8e3 | 2025-11-19 23:33:23 -0500 | [diff] [blame] | 528 | |
| 529 | it "should read a uuid" do |
| 530 | @trans.write("\"00112233-4455-6677-8899-aabbccddeeff\"") |
| 531 | expect(@prot.read_uuid).to eq("00112233-4455-6677-8899-aabbccddeeff") |
| 532 | end |
| 533 | |
| 534 | it "should normalize uppercase uuid on read" do |
| 535 | @trans.write("\"00112233-4455-6677-8899-AABBCCDDEEFF\"") |
| 536 | expect(@prot.read_uuid).to eq("00112233-4455-6677-8899-aabbccddeeff") |
| 537 | end |
| 538 | |
| James E. King III | 9aaf295 | 2018-03-20 15:06:08 -0400 | [diff] [blame] | 539 | it "should provide a reasonable to_s" do |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 540 | expect(@prot.to_s).to eq("json(memory)") |
| James E. King III | 9aaf295 | 2018-03-20 15:06:08 -0400 | [diff] [blame] | 541 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 542 | end |
| 543 | |
| Jake Farrell | a87810f | 2012-09-28 01:59:04 +0000 | [diff] [blame] | 544 | describe Thrift::JsonProtocolFactory do |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 545 | it "should create a JsonProtocol" do |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 546 | expect(Thrift::JsonProtocolFactory.new.get_protocol(double("MockTransport"))).to be_instance_of(Thrift::JsonProtocol) |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 547 | end |
| James E. King III | 9aaf295 | 2018-03-20 15:06:08 -0400 | [diff] [blame] | 548 | |
| 549 | it "should provide a reasonable to_s" do |
| James E. King III | 2724707 | 2018-03-22 20:50:23 -0400 | [diff] [blame] | 550 | expect(Thrift::JsonProtocolFactory.new.to_s).to eq("json") |
| James E. King III | 9aaf295 | 2018-03-20 15:06:08 -0400 | [diff] [blame] | 551 | end |
| Jake Farrell | 6f0f527 | 2012-01-31 03:39:30 +0000 | [diff] [blame] | 552 | end |
| 553 | end |