mirror of
https://github.com/facebook/proxygen.git
synced 2025-08-08 18:02:05 +03:00
Summary: As part of folding getdeps into fbcode_builder, this expression parser is needed to allow constrained and deterministic conditionals in the manifest file format. For example, the watchman manifest will use this cargo-inspired syntax for system dependent sections: ``` [dependencies] folly [dependencies.not(os=windows)] thrift ``` Reviewed By: sinancepel Differential Revision: D14691014 fbshipit-source-id: 080bcdb20579da40d225799f5f22debe65708b03
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
# Copyright (c) 2019-present, Facebook, Inc.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the BSD-style license found in the
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
|
|
|
import unittest
|
|
|
|
from ..expr import parse_expr
|
|
|
|
|
|
class ExprTest(unittest.TestCase):
|
|
def test_equal(self):
|
|
e = parse_expr("foo=bar")
|
|
self.assertTrue(e.eval({"foo": "bar"}))
|
|
self.assertFalse(e.eval({"foo": "not-bar"}))
|
|
self.assertFalse(e.eval({"not-foo": "bar"}))
|
|
|
|
def test_not_equal(self):
|
|
e = parse_expr("not(foo=bar)")
|
|
self.assertFalse(e.eval({"foo": "bar"}))
|
|
self.assertTrue(e.eval({"foo": "not-bar"}))
|
|
|
|
def test_bad_not(self):
|
|
with self.assertRaises(Exception):
|
|
parse_expr("foo=not(bar)")
|
|
|
|
def test_all(self):
|
|
e = parse_expr("all(foo = bar, baz = qux)")
|
|
self.assertTrue(e.eval({"foo": "bar", "baz": "qux"}))
|
|
self.assertFalse(e.eval({"foo": "bar", "baz": "nope"}))
|
|
self.assertFalse(e.eval({"foo": "nope", "baz": "nope"}))
|
|
|
|
def test_any(self):
|
|
e = parse_expr("any(foo = bar, baz = qux)")
|
|
self.assertTrue(e.eval({"foo": "bar", "baz": "qux"}))
|
|
self.assertTrue(e.eval({"foo": "bar", "baz": "nope"}))
|
|
self.assertFalse(e.eval({"foo": "nope", "baz": "nope"}))
|