File: CSS-Minifier.t

package info (click to toggle)
libcss-minifier-perl 0.01-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 120 kB
  • sloc: perl: 189; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,677 bytes parent folder | download | duplicates (4)
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
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl CSS-Minifier.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

use Test::More tests => 4;
BEGIN { use_ok('CSS::Minifier', qw(minify)) };

#########################

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

sub filesMatch {
  my $file1 = shift;
  my $file2 = shift;
  my $a;
  my $b;

  while (1) {
    $a = getc($file1);
    $b = getc($file2);

    if (!defined($a) && !defined($b)) { # both files end at same place
      return 1;
    }
    elsif (!defined($b) || # file2 ends first
           !defined($a) || # file1 ends first
           $a ne $b) {     # a and b not the same
      return 0;
    }
  }
}

sub minTest {
  my $filename = shift;
  
  open(INFILE, 't/sheets/' . $filename . '.css') or die("couldn't open file");
  open(GOTFILE, '>t/sheets/' . $filename . '-got.css') or die("couldn't open file");
    minify(input => *INFILE, outfile => *GOTFILE);
  close(INFILE);
  close(GOTFILE);

  open(EXPECTEDFILE, 't/sheets/' . $filename . '-expected.css') or die("couldn't open file");
  open(GOTFILE, 't/sheets/' . $filename . '-got.css') or die("couldn't open file");
    ok(filesMatch(GOTFILE, EXPECTEDFILE));
  close(EXPECTEDFILE);
  close(GOTFILE);
}

BEGIN {
  
  minTest('s2', 'testing s2');    # general
  minTest('s3', 'testing s3');    # self clearing floats with Mac/IE5 comment hack

  is(minify(input => "foo {\na: b;\n}"), 'foo{a:b;}', 'string literal input and ouput');
}