| Dmytro Shteflyuk | 5cc1022 | 2025-11-24 18:01:10 -0500 | [diff] [blame] | 1 | # encoding: UTF-8 |
| 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 | |
| 21 | require 'spec_helper' |
| 22 | |
| 23 | $:.unshift File.join(File.dirname(__FILE__), *%w[gen-rb/constants_demo]) |
| 24 | require 'constants_demo_constants' |
| 25 | |
| 26 | describe 'ConstantsDemo' do |
| 27 | it 'should have correct integer constants' do |
| 28 | expect(ConstantsDemo::MyInt).to eq(3) |
| 29 | expect(ConstantsDemo::Hex_const).to eq(0x0001F) |
| 30 | expect(ConstantsDemo::Negative_hex_constant).to eq(-0x0001F) |
| 31 | expect(ConstantsDemo::GEN_ME).to eq(-3523553) |
| 32 | end |
| 33 | |
| 34 | it 'should have correct double constants' do |
| 35 | expect(ConstantsDemo::GEn_DUB).to eq(325.532) |
| 36 | expect(ConstantsDemo::GEn_DU).to eq(85.2355) |
| 37 | expect(ConstantsDemo::E10).to eq(1e+10) |
| 38 | expect(ConstantsDemo::E11).to eq(-1e+10) |
| 39 | end |
| 40 | |
| 41 | it 'should have correct string constants' do |
| 42 | expect(ConstantsDemo::GEN_STRING).to eq("asldkjasfd") |
| 43 | end |
| 44 | |
| 45 | it 'should have correct uuid constants' do |
| 46 | expect(ConstantsDemo::GEN_UUID).to eq("00000000-4444-CCCC-ffff-0123456789ab") |
| 47 | expect(ConstantsDemo::GEN_GUID).to eq("00112233-4455-6677-8899-aaBBccDDeeFF") |
| 48 | expect(ConstantsDemo::MY_UUID).to eq("00000000-4444-CCCC-ffff-0123456789ab") |
| 49 | expect(ConstantsDemo::MY_GUID).to eq("00112233-4455-6677-8899-aaBBccDDeeFF") |
| 50 | end |
| 51 | |
| 52 | it 'should have correct list constants' do |
| 53 | expect(ConstantsDemo::GEN_LIST).to be_a(Array) |
| 54 | expect(ConstantsDemo::GEN_LIST).to eq([235235, 23598352, 3253523]) |
| 55 | end |
| 56 | |
| 57 | it 'should have correct map constants' do |
| 58 | expect(ConstantsDemo::GEN_MAP).to be_a(Hash) |
| 59 | expect(ConstantsDemo::GEN_MAP[35532]).to eq(233) |
| 60 | expect(ConstantsDemo::GEN_MAP[43523]).to eq(853) |
| 61 | |
| 62 | expect(ConstantsDemo::GEN_MAP2).to be_a(Hash) |
| 63 | expect(ConstantsDemo::GEN_MAP2["hello"]).to eq(233) |
| 64 | expect(ConstantsDemo::GEN_MAP2["lkj98d"]).to eq(853) |
| 65 | expect(ConstantsDemo::GEN_MAP2['lkjsdf']).to eq(98325) |
| 66 | |
| 67 | expect(ConstantsDemo::GEN_MAPMAP).to be_a(Hash) |
| 68 | expect(ConstantsDemo::GEN_MAPMAP[235]).to be_a(Hash) |
| 69 | expect(ConstantsDemo::GEN_MAPMAP[235][532]).to eq(53255) |
| 70 | expect(ConstantsDemo::GEN_MAPMAP[235][235]).to eq(235) |
| 71 | end |
| 72 | |
| 73 | it 'should have correct set constants' do |
| 74 | expect(ConstantsDemo::GEN_SET).to be_a(Set) |
| 75 | expect(ConstantsDemo::GEN_SET.size).to eq(2) |
| 76 | expect(ConstantsDemo::GEN_SET.include?(235)).to be true # added twice, but this is a set |
| 77 | expect(ConstantsDemo::GEN_SET.include?(53235)).to be true |
| 78 | |
| 79 | expect(ConstantsDemo::GUID_SET).to be_a(Set) |
| 80 | expect(ConstantsDemo::GUID_SET.size).to eq(2) |
| 81 | expect(ConstantsDemo::GUID_SET.include?("00112233-4455-6677-8899-aaBBccDDeeFF")).to be true |
| 82 | expect(ConstantsDemo::GUID_SET.include?("00000000-4444-CCCC-ffff-0123456789ab")).to be true |
| 83 | end |
| 84 | |
| 85 | it 'should have correct struct constants' do |
| 86 | expect(ConstantsDemo::GEN_THING).to be_a(Thrift::Struct) |
| 87 | expect(ConstantsDemo::GEN_THING.hello).to eq(325) |
| 88 | expect(ConstantsDemo::GEN_THING.goodbye).to eq(325352) |
| 89 | expect(ConstantsDemo::GEN_THING.id).to eq("00112233-4455-6677-8899-aaBBccDDeeFF") |
| 90 | expect(ConstantsDemo::GEN_THING.my_id).to eq("00000000-4444-CCCC-ffff-0123456789ab") |
| 91 | expect(ConstantsDemo::GEN_THING.my_optional_id).to eq("00000000-4444-CCCC-ffff-0123456789ab") |
| 92 | |
| 93 | expect(ConstantsDemo::GEN_WHAT).to be_a(Hash) |
| 94 | expect(ConstantsDemo::GEN_WHAT[35]).to be_a(Thrift::Struct) |
| 95 | expect(ConstantsDemo::GEN_WHAT[35].hello).to eq(325) |
| 96 | expect(ConstantsDemo::GEN_WHAT[35].goodbye).to eq(325352) |
| 97 | expect(ConstantsDemo::GEN_WHAT[35].id).to eq("00000000-4444-CCCC-ffff-0123456789ab") |
| 98 | expect(ConstantsDemo::GEN_WHAT[35].my_id).to eq("00000000-4444-CCCC-ffff-0123456789ab") |
| 99 | expect(ConstantsDemo::GEN_WHAT[35].my_optional_id).to eq("00000000-4444-CCCC-ffff-0123456789ab") |
| 100 | end |
| 101 | end |