Permalink
Browse files

Add 1: "Test Highlights"

  • Loading branch information...
janlelis committed May 1, 2015
1 parent 2d6678f commit f36c96bd3b07d63053b40c1e34e59159d4a5f851
Showing with 80 additions and 0 deletions.
  1. +80 −0 source/posts/1-test-highlights.html.md
@@ -0,0 +1,80 @@
---
title: Test Highlights
date: 2015-05-01
tags: syntax, highlighter, tools
---

Compared to other languages, Ruby does not have very good tool support for development. This might not be a problem for many of us, in the end, humans create the code, and not tools.

Nevertheless, it would be better to have better tools. Or at least valid syntax highlighting. The following table shows popular options for code highlighting, but none of them can manage to properly highlight more advanced Ruby features. Here is the:

## Syntax Highlighter Comparison

Editors or Syntax Highlighter | Version | Highlights Ruby Correctly?¹
---------------------------------------------------| ---------------|---------------
[coderay](https://github.com/rubychan/coderay) | 1.1.0 | no. score: 4/5
[ruby mine](https://www.jetbrains.com/ruby/) | 7.1 RM-141.664 | no. score: 4/5
[rouge](https://github.com/jneen/rouge) | 1.8.0 | no. score: 3/5
[emacs](https://www.gnu.org/software/emacs/) | 24.3.1 | no. score: 2/5
[pygments](http://pygments.org/) | 1.6 | no. score: 2/5
[gedit](https://wiki.gnome.org/Apps/Gedit) | 3.10.4 | no. score: 1/5
[prism.js](https://github.com/PrismJS/prism) | 0.0.1 | no. score: 1/5
[rainbow.js](https://github.com/ccampbell/rainbow) | 1.1.9 | no. score: 1/5
[src-highlight](https://www.gnu.org/software/src-highlite/) | 3.1.6 (library: 4:0:0) | no. score: 1/5
[syntaxhighlighter.js](https://github.com/syntaxhighlighter/syntaxhighlighter) | 3.0.83 | no. score: 1/5
[vim](http://www.vim.org/) | 7.4.52 | no. score: 1/5
[atom](https://atom.io/) | 0.192.0 | no. score: 0/5
[highlight.js](https://github.com/isagalaev/highlight.js) | 8.5 | no. score: 0/5
[sublime text](https://www.sublimetext.com/) | 3 Build 3083 | no. score: 0/5

¹ Obviously, passing the test does not necessarily mean that a tool highlights Ruby correctly - but it is an indication.

## The Idiosyncratic Ruby Syntax Highlight Test

# # #
# For Reference
42
"String with #{ :interpolation }"
/regex$/
$/

# # #
# TEST CASE 1: Question Marks
# SHOULD BE HIGHLIGHTED AS: Array of Strings - Operator - String - Operator - String

[?', ?(] ?'a':'b'

# # #
# TEST CASE 2: Percent Format
# SHOULD BE HIGHLIGHTED AS: String - Operator - Array of Numbers

"%d %d %d"%[1,2,3]

# # #
# TEST CASE 3: Space-delimited String
# SHOULD BE HIGHLIGHTED AS: String Delimiter - String

% 5 #

# # #
# TEST CASE 4: Multi-line Regex with Global Variable Interpolation
# SHOULD BE HIGHLIGHTED AS: Regex Delimiter - Regex -
# Interpolation Character (Optional) -
# Global Variable -
# Regex Delimiter - Regex Options

/
$$#$/
/omix

# # #
# TEST CASE 5: Nested Heredoc
# SHOULD BE HIGHLIGHTED AS: Method - String Delimiter - Operator -
# String Delimiter - String - String Delimiter
# String - String Delimiter

puts <<HERE<<<<THERE
foo 42
HERE
bla 43
THERE

4 comments on commit f36c96b

@tony612

This comment has been minimized.

Copy link

tony612 replied Jun 2, 2015

How to get the score? To see how many tests are passed?
But for the Atom, if you comment Test Case 1 out, some of others are right. So, is the score right?

@janlelis

This comment has been minimized.

Copy link
Owner Author

janlelis replied Jun 2, 2015

I tested it all manually (and each test case individually), but might have made a mistake. Which test case does atom pass?

@tony612

This comment has been minimized.

Copy link

tony612 replied Jun 3, 2015

It's my highlight result when I commented the Test Case 1 out. I'm not sure if 5 is right, but 2, 3 and 4 seem similar with yours on the blog.
routes_rb_-_users_tony_repo_projects_lls_playdock-_atom

@janlelis

This comment has been minimized.

Copy link
Owner Author

janlelis replied Aug 30, 2015

Hey @tony612, sorry for the late answer. Here my explanations:

TEST CASE 2: One way to spot the wrong highlighting is to put a space after the percent: It will no longer display the "1,2,3" as a string

TEST CASE 3: Compare it with how %<5>is highlighted: The percent takes the "string delimiter" color

TEST CASE 4: Multiple errors: Again delimiters (/) presented as operators, also it interpretes the # and the rest of the line as a comment

TEST CASE 5: 42 should be the same color as foo, since it is the same string (instead of being method and number)

Please sign in to comment.