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
|
<?php
/* Copyright 2012-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
class nameExprTestCase extends WatchmanTestCase {
function testNameExpr() {
$dir = new WatchmanDirectoryFixture();
$root = $dir->getPath();
touch("$root/foo.c");
mkdir("$root/subdir");
touch("$root/subdir/bar.txt");
$this->watch($root);
$res = $this->watchmanCommand('query', $root, array(
'expression' => array('iname', 'FOO.c'),
'fields' => array('name'),
));
$this->assertEqualFileList(array('foo.c'), $res['files']);
$res = $this->watchmanCommand('query', $root, array(
'expression' => array('iname', array('FOO.c', 'INVALID.txt')),
'fields' => array('name'),
));
$this->assertEqualFileList(array('foo.c'), $res['files']);
$res = $this->watchmanCommand('query', $root, array(
'expression' => array('name', 'foo.c'),
'fields' => array('name'),
));
$this->assertEqualFileList(array('foo.c'), $res['files']);
$res = $this->watchmanCommand('query', $root, array(
'expression' => array('name', array('foo.c', 'invalid')),
'fields' => array('name'),
));
$this->assertEqualFileList(array('foo.c'), $res['files']);
$res = $this->watchmanCommand('query', $root, array(
'expression' => array('name', 'foo.c', 'wholename'),
'fields' => array('name'),
));
$this->assertEqualFileList(array('foo.c'), $res['files']);
if ($this->isCaseInsensitive()) {
$res = $this->watchmanCommand('query', $root, array(
'expression' => array('name', 'Foo.c', 'wholename'),
'fields' => array('name'),
));
$this->assertEqualFileList(array('foo.c'), $res['files']);
}
$res = $this->watchmanCommand('query', $root, array(
'expression' => array('name', 'bar.txt', 'wholename'),
'fields' => array('name'),
));
$this->assertEqualFileList(array(), $res['files']);
$res = $this->watchmanCommand('query', $root, array(
'relative_root' => 'subdir',
'expression' => array('name', 'bar.txt', 'wholename'),
'fields' => array('name'),
));
$this->assertEqualFileList(array('bar.txt'), $res['files']);
// foo.c is not in subdir directory so this shouldn't match
$res = $this->watchmanCommand('query', $root, array(
'relative_root' => 'subdir',
'expression' => array('name', 'foo.c', 'wholename'),
'fields' => array('name'),
));
$this->assertEqual(array(), $res['files']);
$res = $this->watchmanCommand('query', $root, array(
'expression' => 'name',
));
$this->assertRegex(
"/failed to parse query: Expected array for 'i?name' term/",
$res['error']
);
$res = $this->watchmanCommand('query', $root, array(
'expression' => array('name', 'one', 'two', 'three'),
));
$this->assertRegex(
"/failed to parse query: Invalid number of arguments for 'i?name' term/",
$res['error']
);
$res = $this->watchmanCommand('query', $root, array(
'expression' => array('name', 2),
));
$this->assertRegex(
"/failed to parse query: Argument 2 to 'i?name' must be either ".
"a string or an array of string/",
$res['error']
);
$res = $this->watchmanCommand('query', $root, array(
'expression' => array('name', 'one', 2),
));
$this->assertRegex(
"/failed to parse query: Argument 3 to 'i?name' must be a string/",
$res['error']
);
$res = $this->watchmanCommand('query', $root, array(
'expression' => array('name', 'one', 'invalid'),
));
$this->assertRegex(
"/failed to parse query: Invalid scope 'invalid' for i?name expression/",
$res['error']
);
}
}
|