Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/test/PhpParser/Node/NameTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 5fb285c0d0e3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace PhpParser\Node; | |
4 | |
5 class NameTest extends \PHPUnit_Framework_TestCase | |
6 { | |
7 public function testConstruct() { | |
8 $name = new Name(array('foo', 'bar')); | |
9 $this->assertSame(array('foo', 'bar'), $name->parts); | |
10 | |
11 $name = new Name('foo\bar'); | |
12 $this->assertSame(array('foo', 'bar'), $name->parts); | |
13 | |
14 $name = new Name($name); | |
15 $this->assertSame(array('foo', 'bar'), $name->parts); | |
16 } | |
17 | |
18 public function testGet() { | |
19 $name = new Name('foo'); | |
20 $this->assertSame('foo', $name->getFirst()); | |
21 $this->assertSame('foo', $name->getLast()); | |
22 | |
23 $name = new Name('foo\bar'); | |
24 $this->assertSame('foo', $name->getFirst()); | |
25 $this->assertSame('bar', $name->getLast()); | |
26 } | |
27 | |
28 public function testToString() { | |
29 $name = new Name('foo\bar'); | |
30 | |
31 $this->assertSame('foo\bar', (string) $name); | |
32 $this->assertSame('foo\bar', $name->toString()); | |
33 } | |
34 | |
35 public function testSlice() { | |
36 $name = new Name('foo\bar\baz'); | |
37 $this->assertEquals(new Name('foo\bar\baz'), $name->slice(0)); | |
38 $this->assertEquals(new Name('bar\baz'), $name->slice(1)); | |
39 $this->assertNull($name->slice(3)); | |
40 $this->assertEquals(new Name('foo\bar\baz'), $name->slice(-3)); | |
41 $this->assertEquals(new Name('bar\baz'), $name->slice(-2)); | |
42 $this->assertEquals(new Name('foo\bar'), $name->slice(0, -1)); | |
43 $this->assertNull($name->slice(0, -3)); | |
44 $this->assertEquals(new Name('bar'), $name->slice(1, -1)); | |
45 $this->assertNull($name->slice(1, -2)); | |
46 $this->assertEquals(new Name('bar'), $name->slice(-2, 1)); | |
47 $this->assertEquals(new Name('bar'), $name->slice(-2, -1)); | |
48 $this->assertNull($name->slice(-2, -2)); | |
49 } | |
50 | |
51 /** | |
52 * @expectedException \OutOfBoundsException | |
53 * @expectedExceptionMessage Offset 4 is out of bounds | |
54 */ | |
55 public function testSliceOffsetTooLarge() { | |
56 (new Name('foo\bar\baz'))->slice(4); | |
57 } | |
58 | |
59 /** | |
60 * @expectedException \OutOfBoundsException | |
61 * @expectedExceptionMessage Offset -4 is out of bounds | |
62 */ | |
63 public function testSliceOffsetTooSmall() { | |
64 (new Name('foo\bar\baz'))->slice(-4); | |
65 } | |
66 | |
67 /** | |
68 * @expectedException \OutOfBoundsException | |
69 * @expectedExceptionMessage Length 4 is out of bounds | |
70 */ | |
71 public function testSliceLengthTooLarge() { | |
72 (new Name('foo\bar\baz'))->slice(0, 4); | |
73 } | |
74 | |
75 /** | |
76 * @expectedException \OutOfBoundsException | |
77 * @expectedExceptionMessage Length -4 is out of bounds | |
78 */ | |
79 public function testSliceLengthTooSmall() { | |
80 (new Name('foo\bar\baz'))->slice(0, -4); | |
81 } | |
82 | |
83 public function testConcat() { | |
84 $this->assertEquals(new Name('foo\bar\baz'), Name::concat('foo', 'bar\baz')); | |
85 $this->assertEquals( | |
86 new Name\FullyQualified('foo\bar'), | |
87 Name\FullyQualified::concat(['foo'], new Name('bar')) | |
88 ); | |
89 | |
90 $attributes = ['foo' => 'bar']; | |
91 $this->assertEquals( | |
92 new Name\Relative('foo\bar\baz', $attributes), | |
93 Name\Relative::concat(new Name\FullyQualified('foo\bar'), 'baz', $attributes) | |
94 ); | |
95 | |
96 $this->assertEquals(new Name('foo'), Name::concat(null, 'foo')); | |
97 $this->assertEquals(new Name('foo'), Name::concat('foo', null)); | |
98 $this->assertNull(Name::concat(null, null)); | |
99 } | |
100 | |
101 public function testIs() { | |
102 $name = new Name('foo'); | |
103 $this->assertTrue ($name->isUnqualified()); | |
104 $this->assertFalse($name->isQualified()); | |
105 $this->assertFalse($name->isFullyQualified()); | |
106 $this->assertFalse($name->isRelative()); | |
107 | |
108 $name = new Name('foo\bar'); | |
109 $this->assertFalse($name->isUnqualified()); | |
110 $this->assertTrue ($name->isQualified()); | |
111 $this->assertFalse($name->isFullyQualified()); | |
112 $this->assertFalse($name->isRelative()); | |
113 | |
114 $name = new Name\FullyQualified('foo'); | |
115 $this->assertFalse($name->isUnqualified()); | |
116 $this->assertFalse($name->isQualified()); | |
117 $this->assertTrue ($name->isFullyQualified()); | |
118 $this->assertFalse($name->isRelative()); | |
119 | |
120 $name = new Name\Relative('foo'); | |
121 $this->assertFalse($name->isUnqualified()); | |
122 $this->assertFalse($name->isQualified()); | |
123 $this->assertFalse($name->isFullyQualified()); | |
124 $this->assertTrue ($name->isRelative()); | |
125 } | |
126 | |
127 /** | |
128 * @expectedException \InvalidArgumentException | |
129 * @expectedExceptionMessage Expected string, array of parts or Name instance | |
130 */ | |
131 public function testInvalidArg() { | |
132 Name::concat('foo', new \stdClass); | |
133 } | |
134 } |