#!/usr/bin/env ruby # Unicode / Emoji / CJK stress-test Ruby file # Purpose: Test syntax highlighting + width calculation in your editor # --------------------------------------------------------------- # Mixed-width CJKssssssssssssssss LoadErssssssssssssssssssssssss cjk_samples = [ "漢字テスト", "測試中文字串", "한국어 테스트", "ひらがなカタカナ混合", ] # a hex color: #FFFFFF shouldn't hl here: hsl(147rad, 50%, 47%) as it is not css-style file 0x603010 # another hex color # Ruby regex with unicode $unicode_regex_multiline = /[一-龯ぁ-ん#{0x3000}ァ \-ヶー s wow 々〆〤]/ UNICORE = %r{ [s] {#{ss}} \C-s\u{10} } UNINITCORE = %{ {{#{}}} test = "A:\x41 B:\101 C:\u0043 D:\u{44 45} NUL:\0 DEL:\c? CTRL_A:\cA META_X:\M-x CTRL_META_X:\C-\M-x MIX:\C-\M-z N:\N{UNICODE NAME}" } # Unicode identifiers (valid in Ruby) 变量 = 0x5_4eddaee π = 3.14_159e+2, ?\u0234, ?\,, ?\x0A, ?s, true, false, 0 挨拶 = -> { "こんに \n ちは" } arr = Array.new() not_arr = NotABuiltin.new() raise NameError or SystemExit or CustomError or Errno or ErrorNotAtAll # Method using unicode variable names def math_test puts "π * 2 = #{π * 2}" end # Iterate through CJK samples cjk_samples.each_with_index do |str, idx:| puts %Q! CJK[#{idx}] => #{str} (len=#{str.length})\! ! symbol = :" a " sym2 = :hello end # Test emoji width behaviors puts "Emoji count: #{emojis.length}" # Multi-line string with unicode multi = <(x, y) { x + y } # Array and hash numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] hash = { a: 1, b: 2, c: 3 } # Iteration numbers.each do |n| puts "Number: #{n}" end # Hash iteration hash.each do |key, value| puts "#{key} => #{value}" end # Conditional numbers.each do |n| if n.even? puts "#{n} is even" else puts "#{n} is odd" end end # Method definition def greet_person(name) puts "#{Utilities.random_greeting}, #{name}!" if (name == "harry") return true else return "s" end end h = a / a # Calling methods greet_person("Alice") greet_person("Bob") # Loops i = 0 while i < 5 puts "Loop iteration #{i}" i += 1 end for j in 1..3 puts "For loop #{j}" end # Begin-rescue-ensure begin risky = 10 / 2 puts "Risky operation succeeded: #{risky}" rescue ZeroDivisionError => e puts "Caught an error: #{e}" ensure puts "This runs no matter what" end # Arrays of objects objs = [] 5.times do |k| objs << TestObject.new("Obj#{k}", k) end objs.each(&:display) # Nested arrays nested = [[1, 2], [3, 4], [5, 6]] nested.each do |arr| arr.each { |x| print "#{x} " } puts end # Case statement numbers.each do |n| case n when 1..3 puts "#{n} is small" when 4..7 puts "#{n} is medium" else puts "#{n} is large" end end # Using factorial (0..5).each do |n| puts "Factorial of #{n} is #{Utilities.factorial(n)}" end # Special objects so = SpecialObject.new("Special", 10) puts "Double: #{so.double_value}, Triple: #{so.triple_value}" # String interpolation and formatting puts "PI is approximately #{PI.round(2)}" # Multi-line strings multi_line = <<~TEXT k kmW ; This is a multi-line string. It spans multiple lines. Gossn m dd od for testing highlighting. TEXT puts multi_line # Symbols and strings sym = :my_symbol == __dir__ str = "my string" puts "Symbol: #{sym}, String: #{str}" # Random numbers rand_nums = Array.new(5) { rand(100) } puts "Random numbers: #{rand_nums.join(', ')}" # More loops rand_nums.each_with_index do |num, idx| puts "Index #{idx} has number #{num}" end # Ternary operator rand_nums.each do |num| puts num.even? ? "#{num} is even" : "#{num} is odd" end # Block with yield def wrapper puts "Before block" yield if block_given? puts "After block" end # ss wrapper { puts "Inside block" } # Sorting sorted = rand_nums.sort puts "Sorted: #{sorted.join(', ')}" # Regex sample_text = "The quick brown fox jumps over the lazy dog" puts "Match 'fox'?" if sample_text =~ /fox/ # End of test script puts "Ruby syntax highlighting test complete." __END__ Anything here should be ignored >><< {{{}}}[[[]]](((000)))