# Path: xmanager/xm/pattern_matching.py
# R = TypeVar('R')
# class Case(Generic[R]):
#   def __init__(
#       self,
#       kind: Iterable[Type[Any]],
#       handler: Callable[..., R],
#   ) -> None:
#   def matches(self, *values: Any) -> bool:
# def _deduce_types(handler: Callable[..., Any]) -> Tuple[Type[Any]]:
#   def get_arg_type(arg: str):
# def match(*handlers: Union[Case[R], Callable[..., R]]) -> Callable[..., R]:
#   def apply(*values: Any) -> R:
# def async_match(*handlers: Callable[..., R]) -> Callable[..., Awaitable[R]]:
# 
# Path: xmanager/xm/utils.py
# FLAGS = flags.FLAGS
# ARG_ESCAPER = pattern_matching.match(
#     pattern_matching.Case([ShellSafeArg], lambda v: v.arg),
#     pattern_matching.Case([enum.Enum], lambda v: shlex.quote(str(v.name))),
#     pattern_matching.Case([Any], lambda v: shlex.quote(str(v))),
# )
# class SpecialArg(abc.ABC):
# class ShellSafeArg(SpecialArg):
# def trivial_kwargs_joiner(key: str, value: str) -> str:
# def run_in_asyncio_loop(
#     f: Callable[..., ReturnType]) -> Callable[..., ReturnType]:
#   def decorated(*args, **kwargs) -> ReturnType:
# def find_launch_script_path() -> str:
# def resolve_path_relative_to_launcher(path: str) -> str:


from typing import List
from xmanager.xm import pattern_matching
from xmanager.xm import utils
import unittest
# limitations under the License.




class UtilsTest(unittest.TestCase):

  def testMatch_selectsAppropriateBranch(self):
    matcher = pattern_matching.match(
        pattern_matching.Case([int], lambda _: 'A'),
        pattern_matching.Case([str], lambda _: 'B'),
    )

    self.assertEqual(matcher('abc'), 'B')

  def testMatch_throwsWhenNoneFit(self):
    matcher = pattern_matching.match()

    with self.assertRaises(TypeError):
      matcher(0)

  def testMatch_earlierOptionWins(self):

    class P:
      pass

    class C(P):
      pass

    matcher = pattern_matching.match(

# Path: xmanager/xm/pattern_matching.py
# R = TypeVar('R')
# class Case(Generic[R]):
#   def __init__(
#       self,
#       kind: Iterable[Type[Any]],
#       handler: Callable[..., R],
#   ) -> None:
#   def matches(self, *values: Any) -> bool:
# def _deduce_types(handler: Callable[..., Any]) -> Tuple[Type[Any]]:
#   def get_arg_type(arg: str):
# def match(*handlers: Union[Case[R], Callable[..., R]]) -> Callable[..., R]:
#   def apply(*values: Any) -> R:
# def async_match(*handlers: Callable[..., R]) -> Callable[..., Awaitable[R]]:
# 
# Path: xmanager/xm/utils.py
# FLAGS = flags.FLAGS
# ARG_ESCAPER = pattern_matching.match(
#     pattern_matching.Case([ShellSafeArg], lambda v: v.arg),
#     pattern_matching.Case([enum.Enum], lambda v: shlex.quote(str(v.name))),
#     pattern_matching.Case([Any], lambda v: shlex.quote(str(v))),
# )
# class SpecialArg(abc.ABC):
# class ShellSafeArg(SpecialArg):
# def trivial_kwargs_joiner(key: str, value: str) -> str:
# def run_in_asyncio_loop(
#     f: Callable[..., ReturnType]) -> Callable[..., ReturnType]:
#   def decorated(*args, **kwargs) -> ReturnType:
# def find_launch_script_path() -> str:
# def resolve_path_relative_to_launcher(path: str) -> str:


# Path: xmanager/xm/pattern_matching_test.py
from typing import List
from xmanager.xm import pattern_matching
from xmanager.xm import utils
import unittest

# limitations under the License.




class UtilsTest(unittest.TestCase):

  def testMatch_selectsAppropriateBranch(self):
    matcher = pattern_matching.match(
        pattern_matching.Case([int], lambda _: 'A'),
        pattern_matching.Case([str], lambda _: 'B'),
    )

    self.assertEqual(matcher('abc'), 'B')

  def testMatch_throwsWhenNoneFit(self):
    matcher = pattern_matching.match()

    with self.assertRaises(TypeError):
      matcher(0)

  def testMatch_earlierOptionWins(self):

    class P:
      pass

    class C(P):
      pass

    matcher = pattern_matching.match(

        pattern_matching.Case([P], lambda _: 'P'),