string_interpolation_complex.gravity 655 B

123456789101112131415161718192021222324252627282930313233
  1. #unittest {
  2. name: "Complex string interpolation.";
  3. error: NONE;
  4. result: true;
  5. };
  6. func main() {
  7. var x = 10;
  8. var y = 20;
  9. // Basic interpolation
  10. var s1 = "sum is \(x + y)";
  11. var r1 = (s1 == "sum is 30");
  12. // Nested parentheses in interpolation
  13. var s2 = "val \((x + y) * 2)";
  14. var r2 = (s2 == "val 60");
  15. // Multiple interpolations
  16. var s3 = "\(x) and \(y)";
  17. var r3 = (s3 == "10 and 20");
  18. // Interpolation with method call
  19. var name = "world";
  20. var s4 = "hello \(name.upper())";
  21. var r4 = (s4 == "hello WORLD");
  22. // Empty prefix/suffix around interpolation
  23. var s5 = "\(42)";
  24. var r5 = (s5 == "42");
  25. return r1 and r2 and r3 and r4 and r5;
  26. }