Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit 33dfd41

Browse files
authored
Prefix Yaml tags with !bson_ (#43)
1 parent 7c9a36a commit 33dfd41

File tree

12 files changed

+27
-27
lines changed

12 files changed

+27
-27
lines changed

generator/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ The `generator/config/*.yaml` files contains the list of operators and stages th
2222
Each operator can contain a `tests` section with a list if pipelines. To represent specific BSON objects,
2323
it is necessary to use Yaml tags:
2424

25-
| BSON Type | Example |
26-
|-------------|----------------------------------------------|
27-
| Regex | `!regex '^abc'` <br/> `!regex ['^abc', 'i']` |
28-
| Int64 | `!long '123456789'` |
29-
| Decimal128 | `!double '0.9'` |
30-
| UTCDateTime | `!date 0` |
31-
| Binary | `!binary 'IA=='` |
25+
| BSON Type | Example |
26+
|-------------|--------------------------------------------------------|
27+
| Regex | `!bson_regex '^abc'` <br/> `!bson_regex ['^abc', 'i']` |
28+
| Int64 | `!bson_int64 '123456789'` |
29+
| Decimal128 | `!bson_decimal128 '0.9'` |
30+
| UTCDateTime | `!bson_utcdatetime 0` |
31+
| Binary | `!bson_binary 'IA=='` |
3232

3333
To add new test cases to operators, you can get inspiration from the official MongoDB documentation and use
3434
the `generator/js2yaml.html` web page to manually convert a pipeline array from JS to Yaml.

generator/config/expression/dateFromString.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ tests:
7777
dateString: '$date'
7878
timezone: '$timezone'
7979
# onNull: new Date(0)
80-
onNull: !date 0
80+
onNull: !bson_utcdatetime 0
8181

generator/config/query/bitsAllClear.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ tests:
3535
pipeline:
3636
- $match:
3737
a:
38-
$bitsAllClear: !binary 'IA=='
38+
$bitsAllClear: !bson_binary 'IA=='

generator/config/query/bitsAllSet.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ tests:
3535
pipeline:
3636
- $match:
3737
a:
38-
$bitsAllSet: !binary 'MA=='
38+
$bitsAllSet: !bson_binary 'MA=='

generator/config/query/bitsAnyClear.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ tests:
3535
pipeline:
3636
- $match:
3737
a:
38-
$bitsAnyClear: !binary 'MA=='
38+
$bitsAnyClear: !bson_binary 'MA=='

generator/config/query/bitsAnySet.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ tests:
3535
pipeline:
3636
- $match:
3737
a:
38-
$bitsAnySet: !binary 'MA=='
38+
$bitsAnySet: !bson_binary 'MA=='

generator/config/query/eq.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ tests:
5353
-
5454
$match:
5555
company:
56-
!regex '^MongoDB'
56+
!bson_regex '^MongoDB'
5757
-
5858
$match:
5959
company:
6060
$eq:
61-
!regex '^MongoDB'
61+
!bson_regex '^MongoDB'

generator/config/query/in.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ tests:
2828
$match:
2929
tags:
3030
$in:
31-
- !regex '^be'
32-
- !regex '^st'
31+
- !bson_regex '^be'
32+
- !bson_regex '^st'

generator/config/query/not.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ tests:
2828
-
2929
$match:
3030
price:
31-
$not: !regex '^p.*'
31+
$not: !bson_regex '^p.*'

generator/config/query/regex.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tests:
2121
$match:
2222
sku:
2323
$regex:
24-
!regex '789$'
24+
!bson_regex '789$'
2525
-
2626
name: 'Perform Case-Insensitive Regular Expression Match'
2727
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/regex/#perform-case-insensitive-regular-expression-match'
@@ -30,4 +30,4 @@ tests:
3030
$match:
3131
sku:
3232
$regex:
33-
!regex ['^ABC', 'i']
33+
!bson_regex ['^ABC', 'i']

generator/js2yaml.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ <h1>Convert JS examples into Yaml</h1>
6969
}
7070

7171
function BinData(type, value) {
72-
return new TaggedValue('binary', value);
72+
return new TaggedValue('bson_binary', value);
7373
}
7474

7575
function convert(jsString) {
@@ -91,11 +91,11 @@ <h1>Convert JS examples into Yaml</h1>
9191
}
9292

9393
if (object instanceof RegExp) {
94-
return ' !regex ' + (object.flags ? "['" + object.source + "', '" + object.flags + "']" : "'" + object.source + "'");
94+
return ' !bson_regex ' + (object.flags ? "['" + object.source + "', '" + object.flags + "']" : "'" + object.source + "'");
9595
}
9696

9797
if (object instanceof Date) {
98-
return ' !date ' + object.getTime();
98+
return ' !bson_utcdatetime ' + object.getTime();
9999
}
100100

101101
if (object instanceof TaggedValue) {

generator/src/OperatorTestGenerator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ private function convertYamlTaggedValues(mixed $object): mixed
138138
$value = $object->getValue();
139139

140140
return match ($object->getTag()) {
141-
'regex' => new Regex(...(array) $value),
142-
'long' => new Int64($value),
143-
'double' => new Decimal128($value),
144-
'date' => new UTCDateTime($value),
145-
'binary' => new Binary(base64_decode($value)),
141+
'bson_regex' => new Regex(...(array) $value),
142+
'bson_int128' => new Int64($value),
143+
'bson_decimal128' => new Decimal128($value),
144+
'bson_utcdatetime' => new UTCDateTime($value),
145+
'bson_binary' => new Binary(base64_decode($value)),
146146
default => throw new InvalidArgumentException(sprintf('Yaml tag "%s" is not supported.', $object->getTag())),
147147
};
148148
}

0 commit comments

Comments
 (0)