builtin_equality.carbon 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // RUN: %{explorer-run}
  7. // RUN: %{explorer-run-trace}
  8. // CHECK:STDOUT: bool: 1
  9. // CHECK:STDOUT: bool: 1
  10. // CHECK:STDOUT: bool: 1
  11. // CHECK:STDOUT: bool: 1
  12. // CHECK:STDOUT: bool: 1
  13. // CHECK:STDOUT: bool: 1
  14. // CHECK:STDOUT: bool: 1
  15. // CHECK:STDOUT: bool: 1
  16. // CHECK:STDOUT: string: 1
  17. // CHECK:STDOUT: string: 1
  18. // CHECK:STDOUT: string: 1
  19. // CHECK:STDOUT: string: 1
  20. // CHECK:STDOUT: string: 1
  21. // CHECK:STDOUT: string: 1
  22. // CHECK:STDOUT: string: 1
  23. // CHECK:STDOUT: string: 1
  24. // CHECK:STDOUT: int: 1
  25. // CHECK:STDOUT: int: 1
  26. // CHECK:STDOUT: int: 1
  27. // CHECK:STDOUT: int: 1
  28. // CHECK:STDOUT: int: 1
  29. // CHECK:STDOUT: int: 1
  30. // CHECK:STDOUT: int: 1
  31. // CHECK:STDOUT: int: 1
  32. // CHECK:STDOUT: result: 0
  33. package ExplorerTest api;
  34. fn CompareEqualValues[T:! EqWith(.Self)](format: String, a: T, b: T) {
  35. Print(format, if a == b then 1 else 0);
  36. Print(format, if a != b then 0 else 1);
  37. }
  38. fn CompareDifferentValues[U:! EqWith(.Self)](format: String, a: U, b: U) {
  39. Print(format, if a == b then 0 else 1);
  40. Print(format, if a != b then 1 else 0);
  41. }
  42. fn CompareAll[V:! EqWith(.Self)](format: String, a: V, b: V) {
  43. CompareEqualValues(format, a, a);
  44. CompareEqualValues(format, b, b);
  45. CompareDifferentValues(format, a, b);
  46. CompareDifferentValues(format, b, a);
  47. }
  48. fn Main() -> i32 {
  49. CompareAll("bool: {0}", false, true);
  50. CompareAll("string: {0}", "hello", "world");
  51. CompareAll("int: {0}", 1, 2);
  52. return 0;
  53. }