File: 03values.t%2Cv

package info (click to toggle)
libsql-abstract-perl 1.18-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 160 kB
  • ctags: 23
  • sloc: perl: 893; makefile: 42
file content (117 lines) | stat: -rwxr-xr-x 2,280 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
head	1.1;
access;
symbols;
locks; strict;
comment	@# @;


1.1
date	2005.03.02.23.37.55;	author nwiger;	state Exp;
branches;
next	;


desc
@tests
@


1.1
log
@Initial revision
@
text
@#!/usr/bin/perl -I. -w

use strict;
use vars qw($TESTING);
$TESTING = 1;
use Test;

# use a BEGIN block so we print our plan before SQL::Abstract is loaded
BEGIN { plan tests => 5 }

use SQL::Abstract;

my $sql = SQL::Abstract->new;

my @@data = (
    {
        user => 'nwiger',
        name => 'Nathan Wiger',
        phone => '123-456-7890',
        addr => 'Yeah, right',
        city => 'Milwalkee',
        state => 'Minnesota',
    },

    {
        user => 'jimbo',
        name => 'Jimbo Bobson',
        phone => '321-456-0987',
        addr => 'Yo Momma',
        city => 'Yo City',
        state => 'Minnesota',
    },

    {
        user => 'mr.hat',
        name => 'Mr. Garrison',
        phone => '123-456-7890',
        addr => undef,
        city => 'South Park',
        state => 'CO',
    },

    {
        user => 'kennyg',
        name => undef,
        phone => '1-800-Sucky-Sucky',
        addr => 'Mr. Garrison',
        city => undef,
        state => 'CO',
    },

    {
        user => 'barbara_streisand',
        name => 'MechaStreisand!',
        phone => 0,
        addr => -9230992340,
        city => 42,
        state => 'CO',
    },
);

# Note to self: I have no idea what this does anymore
# It looks like a cool fucking segment of code though!
# I just wish I remembered writing it... :-\

my($sth, $stmt);
my($laststmt, $numfields);
for my $t (@@data) {
      local $"=', ';

      $stmt = $sql->insert('yo_table', $t);
      my @@val = $sql->values($t);
      $numfields ||= @@val;

      ok((! $laststmt || $stmt eq $laststmt) && @@val == $numfields
          && equal(\@@val, [map { $t->{$_} } sort keys %$t])) or
              print "got\n",
                    "[$stmt] [@@val]\n",
                    "instead of\n",
                    "[$t->{stmt}] [stuff]\n\n";
      $laststmt = $stmt;
}

sub equal {
      my ($a, $b) = @@_;
      return 0 if @@$a != @@$b;
      for (my $i = 0; $i < $#{$a}; $i++) {
              next if (! defined($a->[$i])) && (! defined($b->[$i]));
              return 0 if $a->[$i] ne $b->[$i];
      }
      return 1;
}

@