github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/acceptance/testdata/elixir/test_crdb/test/decimal_test.exs (about)

     1  defmodule Cockroach.TestDecimal do
     2    use ExUnit.Case
     3  
     4    test "handles decimal correctly" do
     5      ssl_opts = [certfile: System.get_env("PGSSLCERT"), keyfile: System.get_env("PGSSLKEY")]
     6      {port, _} = Integer.parse(System.get_env("PGPORT") || "26257")
     7      {start_ok, pid} = Postgrex.start_link(
     8        hostname: System.get_env("PGHOST") || "localhost",
     9        username: System.get_env("PGUSER") || "root",
    10        password: "",
    11        database: "testdb",
    12        port: port,
    13        ssl: (System.get_env("PGSSLCERT") != nil && true) || false,
    14        ssl_opts: ssl_opts
    15      )
    16      assert start_ok
    17      for dec <- [
    18        Decimal.new("0"),
    19        Decimal.new("0.0"),
    20        Decimal.new("0.00"),
    21        Decimal.new("0.000"),
    22        Decimal.new("0.0000"),
    23        Decimal.new("0.00000"),
    24        Decimal.new("0.00001"),
    25        Decimal.new("0.000012"),
    26        Decimal.new("0.0000012"),
    27        Decimal.new("0.00000012"),
    28        Decimal.new("0.00000012"),
    29        Decimal.new(".00000012"),
    30        Decimal.new("1"),
    31        Decimal.new("1.0"),
    32        Decimal.new("1.000"),
    33        Decimal.new("1.0000"),
    34        Decimal.new("1.00000"),
    35        Decimal.new("1.000001"),
    36        Decimal.new("12345"),
    37        Decimal.new("12345.0"),
    38        Decimal.new("12345.000"),
    39        Decimal.new("12345.0000"),
    40        Decimal.new("12345.00000"),
    41        Decimal.new("12345.000001"),
    42        Decimal.new("12340"),
    43        Decimal.new("123400"),
    44        Decimal.new("1234000"),
    45        Decimal.new("12340000"),
    46        Decimal.new("12340.00"),
    47        Decimal.new("123400.00"),
    48        Decimal.new("1234000.00"),
    49        Decimal.new("12340000.00"),
    50        Decimal.new("1.2345e-10"),
    51        Decimal.new("1.23450e-10"),
    52        Decimal.new("1.234500e-10"),
    53        Decimal.new("1.2345000e-10"),
    54        Decimal.new("1.23450000e-10"),
    55        Decimal.new("1.234500000e-10"),
    56      ] do
    57        {result_ok, result} = Postgrex.query(pid, "SELECT CAST($1 AS DECIMAL)", [dec])
    58        assert result_ok
    59        [[ret]] = result.rows
    60        assert ret == dec
    61      end
    62    end
    63  end