root / trunk / docscripts / tests / TestPackage.php

Revision 6125, 1.9 kB (checked in by pottedmeat, 2 years ago)

Change the way that source parsing works. Still some work left to do with function naming

Line 
1<?php
2
3require_once('../lib/simpletest/unit_tester.php');
4require_once('../lib/simpletest/reporter.php');
5require_once('../inc/Dojo.php');
6require_once('../inc/DojoPackage.php');
7
8class SubDojoPackage extends DojoPackage
9{
10  public function __construct($source, $second_line = false) {
11    parent::__construct(new Dojo('../'), '');
12    $this->source = array($source);
13    if ($second_line) {
14      $this->source[] = $second_line;
15    }
16  }
17}
18
19class TestPackage extends UnitTestCase
20{
21  function testGetSource()
22  {
23    $package = new SubDojoPackage('var rePkg = /(__package__|dojo)\.js([\?\.]|$)/i;');
24    $code = $package->getCode();
25    $this->assertEqual($code[0],  'var rePkg = /                                /i;');
26   
27    $package = new SubDojoPackage('var url = "http://site.com";');
28    $code = $package->getCode();
29    $this->assertEqual($code[0],  'var url = "               ";');
30   
31    $package = new SubDojoPackage('var regex = /(")/; // Check for double quote (")');
32    $code = $package->getCode();
33    $this->assertEqual($code[0],  'var regex = /   /;                              ');
34   
35    $package = new SubDojoPackage('if((typeof this["load"] == "function")&&((typeof this["Packages"] == "function")||(typeof this["Packages"] == "object"))){');
36    $code = $package->getCode();
37    $this->assertEqual($code[0],  'if((typeof this["    "] == "        ")&&((typeof this["        "] == "        ")||(typeof this["        "] == "      "))){');
38   
39    $package = new SubDojoPackage(         '/* Test', ' multiline */');
40    $code = $package->getCode();
41    $this->assertEqual(implode("\n", $code), "       \n             ");
42   
43    $package = new SubDojoPackage('return "["+this.widgetType+" ID:"+this.widgetId+"]"');
44    $code = $package->getCode();
45    $this->assertEqual($code[0],  'return " "+this.widgetType+"    "+this.widgetId+" "');
46  }
47}
48
49$test = &new TestPackage();
50$test->run(new HtmlReporter());
51
52?>
Note: See TracBrowser for help on using the browser.