#!/usr/bin/php
<?php

require_once('Net/PublicSuffix.php');

global $errorcount;

function p($x) {
  if (is_null($x))
    return 'NULL';
  else
    return $x;
}

function checkPublicSuffix($d, $v) {
  global $errorcount;
  try {
    $n = Net_PublicSuffix::registered_domain($d);
    if ($n !== $v) {
      $errorcount++;
      printf("    error: d: %s\tv: %s\tn: %s\n", p($d), p($v), p($n));
    }
  } catch (Exception $e) {
    $errorcount++;
    printf("exception: d: %s\tv: %s\tn: %s\n", p($d), p($v), p($n));
  }
}

//print_r(get_prevailing_suffix_rule('nancy.george.com.uk'));
eval(file_get_contents('/usr/share/doc/publicsuffix/examples/test.txt'));

printf("%d errors total\n", $errorcount);

if ($errorcount > 0)
  exit(1);
else
  exit(0);

