Sha256: 6394a9abadadc185561ce0511c4c271010eae1f30b721cd3a1d72dbd51158148

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Types::BigInt do
  it "encodes big and small integers as strings" do
    big_integer_1 = 99**99
    expected_str_1 = "369729637649726772657187905628805440595668764281741102430259972423552570455277523421410650010128232727940978889548326540119429996769494359451621570193644014418071060667659301384999779999159200499899"
    assert_equal expected_str_1, GraphQL::Types::BigInt.coerce_result(big_integer_1, nil)
    assert_equal big_integer_1, GraphQL::Types::BigInt.coerce_input(expected_str_1, nil)

    big_integer_2 = -(88**88)
    expected_str_2 = "-1301592834942972055182648307417315364538725075960067827915311484722452340966317215805106820959190833309704934346517741237438752456673499160125624414995891111204155079786496"
    assert_equal expected_str_2, GraphQL::Types::BigInt.coerce_result(big_integer_2, nil)
    assert_equal big_integer_2, GraphQL::Types::BigInt.coerce_input(expected_str_2, nil)

    assert_equal "31", GraphQL::Types::BigInt.coerce_result(31, nil)
    assert_equal -17, GraphQL::Types::BigInt.coerce_input("-17", nil)
  end

  it "returns `nil` for invalid inputs" do
    assert_equal nil, GraphQL::Types::BigInt.coerce_input("xyz", nil)
    assert_equal nil, GraphQL::Types::BigInt.coerce_input("2.2", nil)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphql-1.9.11 spec/graphql/types/big_int_spec.rb
graphql-1.9.10 spec/graphql/types/big_int_spec.rb
graphql-1.9.9 spec/graphql/types/big_int_spec.rb
graphql-1.9.8 spec/graphql/types/big_int_spec.rb
graphql-1.9.7 spec/graphql/types/big_int_spec.rb
graphql-1.9.6 spec/graphql/types/big_int_spec.rb
graphql-1.9.5 spec/graphql/types/big_int_spec.rb
graphql-1.9.4 spec/graphql/types/big_int_spec.rb