File: from_string.t

package info (click to toggle)
libnumber-tolerant-perl 1.710-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 372 kB
  • sloc: perl: 757; makefile: 10
file content (37 lines) | stat: -rw-r--r-- 888 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use Test::More tests => 7;

use strict;
use warnings;

BEGIN { use_ok("Number::Tolerant"); }

{ # constant (without Constant)
  { # integer
    my $tol = Number::Tolerant->from_string("1012");
    ok(
      ! eval { $tol->isa('Number::Tolerant') },
      "a constant isn't a Number::Tolerant type",
    );
    is($tol, "1012", "constant:  1012");
  }
  { # rational
    my $tol = Number::Tolerant->from_string("10.12");
    ok(
      ! eval { $tol->isa('Number::Tolerant') },
      "a constant isn't a Number::Tolerant type",
    );
    is($tol, "10.12", "constant: 10.12");
  }
}

{ # bad string
  my $tol = eval { Number::Tolerant->from_string("is this thing on?") };
  is($tol, undef, "invalid string: undef");
}

{ # instance method call should die
  my $tol = tolerance(10 => to => 20);
  eval { $tol->from_string("10 to 30"); };
  ok("$@", "from_string is a class method only");
}