Fixed M lexer name. Merged with upstream's latest changes.

This commit is contained in:
Laurent Parenteau
2012-05-22 13:43:47 -04:00
25 changed files with 603 additions and 74 deletions

View File

@@ -2,8 +2,7 @@ before_install: sudo apt-get install libicu-dev -y
rvm:
- 1.8.7
- 1.9.2
- jruby
- rbx
- 1.9.3
- ree
notifications:
disabled: true

View File

@@ -53,7 +53,7 @@ module Linguist
#
# Returns a content type String.
def content_type
@content_type ||= binary? ? mime_type :
@content_type ||= (binary_mime_type? || binary?) ? mime_type :
(encoding ? "text/plain; charset=#{encoding.downcase}" : "text/plain")
end
@@ -160,6 +160,29 @@ module Linguist
size.to_i > MEGABYTE
end
# Public: Is the blob safe to colorize?
#
# We use Pygments.rb for syntax highlighting blobs, which
# has some quirks and also is essentially 'un-killable' via
# normal timeout. To workaround this we try to
# carefully handling Pygments.rb anything it can't handle.
#
# Return true or false
def safe_to_colorize?
text? && !large? && !high_ratio_of_long_lines?
end
# Internal: Does the blob have a ratio of long lines?
#
# These types of files are usually going to make Pygments.rb
# angry if we try to colorize them.
#
# Return true or false
def high_ratio_of_long_lines?
return false if loc == 0
size / loc > 5000
end
# Public: Is the blob viewable?
#
# Non-viewable blobs will just show a "View Raw" link
@@ -451,27 +474,29 @@ module Linguist
# Internal: Guess language of .m files.
#
# Objective-C heuristics:
# * Keywords
# * Keywords ("#import", "#include", "#ifdef", #define, "@end") or "//" and opening "\*" comments
#
# Matlab heuristics:
# * Leading function keyword
# * Leading "function " of "classdef " keyword
# * "%" comments
#
# M heuristics:
# * Look at first line. It is either a comment (1st regex) or label/code (2nd regex)
#
# Note: All "#" keywords, e.g., "#import", are guaranteed to be Objective-C. Because the ampersand
# is used to created function handles and anonymous functions in Matlab, most "@" keywords are not
# safe heuristics. However, "end" is a reserved term in Matlab and can't be used to create a valid
# function handle. Because @end is required to close any @implementation, @property, @interface,
# @synthesize, etc. directive in Objective-C, only @end needs to be checked for.
#
# Returns a Language.
def guess_m_language
# Objective-C keywords
if lines.grep(/^#import|@(interface|implementation|property|synthesize|end)/).any?
# Objective-C keywords or comments
if lines.grep(/^#(import|include|ifdef|define)|@end/).any? || lines.grep(/^\s*\/\//).any? || lines.grep(/^\s*\/\*/).any?
Language['Objective-C']
# Matlab leading function keyword
elsif lines.first.to_s =~ /^function /
Language['Matlab']
# Matlab comment
elsif lines.grep(/^%/).any?
# Matlab file function or class or comments
elsif lines.any? && lines.first.match(/^\s*(function |classdef )/) || lines.grep(/^\s*%/).any?
Language['Matlab']
# M (see M heuristics above)
@@ -647,7 +672,7 @@ module Linguist
#
# Returns html String
def colorize(options = {})
return if !text? || large? || generated?
return unless safe_to_colorize?
options[:options] ||= {}
options[:options][:encoding] ||= encoding
lexer.highlight(data, options)

View File

@@ -194,6 +194,13 @@ module Linguist
@unpopular ||= all.select(&:unpopular?).sort_by { |lang| lang.name.downcase }
end
# Public: A List of languages with assigned colors.
#
# Returns an Array of Languages.
def self.colors
@colors ||= all.select(&:color).sort_by { |lang| lang.name.downcase }
end
# Public: A List of languages compatible with Ace.
#
# Returns an Array of Languages.
@@ -214,6 +221,8 @@ module Linguist
raise ArgumentError, "invalid type: #{@type}"
end
@color = attributes[:color]
# Set aliases
@aliases = [default_alias_name] + (attributes[:aliases] || [])
@@ -269,6 +278,11 @@ module Linguist
# Returns a type Symbol or nil.
attr_reader :type
# Public: Get color.
#
# Returns a hex color String.
attr_reader :color
# Public: Get aliases
#
# Examples
@@ -434,6 +448,7 @@ module Linguist
YAML.load_file(File.expand_path("../languages.yml", __FILE__)).each do |name, options|
Language.create(
:name => name,
:color => options['color'],
:type => options['type'],
:aliases => options['aliases'],
:lexer => options['lexer'],

View File

@@ -17,6 +17,7 @@
# searchable - Boolean flag to enable searching (defaults to true)
# search_term - Deprecated: Some languages maybe indexed under a
# different alias. Avoid defining new exceptions.
# color - CSS hex color to represent the language.
#
# Any additions or modifications (even trivial) should have corresponding
# test change in `test/test_blob.rb`.
@@ -25,6 +26,7 @@
ASP:
type: programming
color: "#6a40fd"
lexer: aspx-vb
search_term: aspx-vb
aliases:
@@ -43,6 +45,7 @@ ASP:
ActionScript:
type: programming
lexer: ActionScript 3
color: "#e3491a"
search_term: as3
aliases:
- as3
@@ -51,6 +54,7 @@ ActionScript:
Ada:
type: programming
color: "#02f88c"
extensions:
- .adb
- .ads
@@ -71,12 +75,14 @@ AppleScript:
Arc:
type: programming
color: "#ca2afe"
lexer: Text only
extensions:
- .arc
Arduino:
type: programming
color: "#bd79d1"
lexer: C++
extensions:
- .ino
@@ -84,15 +90,22 @@ Arduino:
Assembly:
type: programming
lexer: NASM
color: "#a67219"
search_term: nasm
aliases:
- nasm
extensions:
- .asm
Augeas:
type: programming
extensions:
- .aug
AutoHotkey:
type: programming
lexer: autohotkey
color: "#6594b9"
aliases:
- ahk
extensions:
@@ -119,6 +132,7 @@ BlitzMax:
Boo:
type: programming
color: "#d4bec1"
extensions:
- .boo
@@ -134,6 +148,7 @@ Bro:
C:
type: programming
color: "#555"
overrides:
- .h
primary_extension: .c
@@ -146,6 +161,7 @@ C#:
type: programming
ace_mode: csharp
search_term: csharp
color: "#5a25a2"
aliases:
- csharp
extensions:
@@ -155,6 +171,7 @@ C++:
type: programming
ace_mode: c_cpp
search_term: cpp
color: "#f34b7d"
aliases:
- cpp
primary_extension: .cpp
@@ -206,6 +223,7 @@ ChucK:
Clojure:
type: programming
ace_mode: clojure
color: "#db5855"
primary_extension: .clj
extensions:
- .clj
@@ -214,10 +232,12 @@ Clojure:
CoffeeScript:
type: programming
ace_mode: coffee
color: "#244776"
aliases:
- coffee
primary_extension: .coffee
extensions:
- .coffee
- ._coffee
filenames:
- Cakefile
@@ -225,6 +245,7 @@ ColdFusion:
type: programming
lexer: Coldfusion HTML
ace_mode: coldfusion
color: "#ed2cd6"
search_term: cfm
aliases:
- cfm
@@ -235,16 +256,17 @@ ColdFusion:
Common Lisp:
type: programming
color: "#3fb68b"
aliases:
- lisp
primary_extension: .lisp
extensions:
- .lisp
- .lsp
- .ny
Coq:
type: programming
lexer: Coq
extensions:
- .v
@@ -272,6 +294,7 @@ Cython:
D:
type: programming
color: "#fcd46d"
extensions:
- .d
- .di
@@ -290,14 +313,30 @@ Darcs Patch:
- .darcspatch
- .dpatch
Dart:
type: programming
extensions:
- .dart
Delphi:
type: programming
color: "#b0ce4e"
primary_extension: .pas
extensions:
- .dpr
- .lpr
- .pas
DCPU-16 ASM:
type: programming
lexer: dasm16
primary_extension: .dasm16
extensions:
- .dasm
- .dasm16
aliases:
- dasm16
Diff:
extensions:
- .diff
@@ -305,17 +344,27 @@ Diff:
Dylan:
type: programming
color: "#3ebc27"
extensions:
- .dylan
Ecere Projects:
type: data
group: JavaScript
lexer: JSON
extensions:
- .epj
Eiffel:
type: programming
lexer: Text only
color: "#946d57"
extensions:
- .e
Elixir:
type: programming
color: "#6e4a7e"
primary_extension: .ex
extensions:
- .ex
@@ -324,6 +373,7 @@ Elixir:
Emacs Lisp:
type: programming
lexer: Scheme
color: "#c065db"
aliases:
- elisp
- emacs
@@ -334,6 +384,7 @@ Emacs Lisp:
Erlang:
type: programming
color: "#949e0e"
primary_extension: .erl
extensions:
- .erl
@@ -341,7 +392,8 @@ Erlang:
F#:
type: programming
lexer: OCaml
lexer: FSharp
color: "#b845fc"
search_term: ocaml
extensions:
- .fs
@@ -351,6 +403,7 @@ F#:
FORTRAN:
type: programming
lexer: Fortran
color: "#4d41b1"
primary_extension: .f90
extensions:
- .F
@@ -372,19 +425,23 @@ FORTRAN:
Factor:
type: programming
color: "#636746"
extensions:
- .factor
Fancy:
type: programming
color: "#7b9db4"
primary_extension: .fy
extensions:
- .fancypack
- .fy
filenames:
- Fakefile
Fantom:
type: programming
lexer: Java
color: "#dbded5"
extensions:
- .fan
@@ -423,11 +480,13 @@ Gettext Catalog:
Go:
type: programming
color: "#8d04eb"
extensions:
- .go
Gosu:
type: programming
color: "#82937f"
primary_extension: .gs
extensions:
- .gs
@@ -450,8 +509,8 @@ Groff:
Groovy:
type: programming
lexer: Java
ace_mode: groovy
color: "#e69f56"
primary_extension: .groovy
extensions:
- .gradle
@@ -475,7 +534,6 @@ HTML:
- .htm
- .html
- .xhtml
- .xslt
HTML+Django:
type: markup
@@ -503,6 +561,7 @@ HaXe:
type: programming
lexer: haXe
ace_mode: haxe
color: "#346d51"
extensions:
- .hx
- .hxml
@@ -516,6 +575,7 @@ Haml:
Haskell:
type: programming
color: "#29b544"
extensions:
- .hs
- .hsc
@@ -540,18 +600,19 @@ IRC log:
Io:
type: programming
color: "#a9188d"
extensions:
- .io
Ioke:
type: programming
color: "#078193"
extensions:
- .ik
JSON:
type: data
group: JavaScript
lexer: JavaScript
ace_mode: json
searchable: false
extensions:
@@ -560,6 +621,7 @@ JSON:
Java:
type: programming
ace_mode: java
color: "#b07219"
extensions:
- .java
- .pde
@@ -576,14 +638,17 @@ Java Server Pages:
JavaScript:
type: programming
ace_mode: javascript
color: "#f15501"
aliases:
- js
- node
primary_extension: .js
extensions:
- ._js
- .bones
- .jake
- .js
- .jsfl
- .jsm
- .jss
- .jsx
@@ -593,6 +658,18 @@ JavaScript:
filenames:
- Jakefile
Julia:
type: programming
extensions:
- .jl
Kotlin:
type: programming
extensions:
- .kt
- .ktm
- .kts
LLVM:
extensions:
- .ll
@@ -615,21 +692,20 @@ Literate Haskell:
Logtalk:
type: programming
primary_extension: .lgt
extensions:
- .lgt
Lua:
type: programming
ace_mode: lua
primary_extension: .lua
color: "#fa1fa1"
extensions:
- .lua
- .nse
M:
type: programming
lexer: common-lisp
lexer: Common Lisp
aliases:
- mumps
extensions:
@@ -663,6 +739,7 @@ Markdown:
Matlab:
type: programming
color: "#bb92ac"
primary_extension: .matlab
extensions:
- .m
@@ -670,6 +747,7 @@ Matlab:
Max/MSP:
type: programming
color: "#ce279c"
lexer: Text only
extensions:
- .mxt
@@ -682,6 +760,7 @@ Mirah:
type: programming
lexer: Ruby
search_term: ruby
color: "#c7a938"
extensions:
- .duby
- .mir
@@ -698,11 +777,13 @@ Myghty:
Nemerle:
type: programming
color: "#0d3c6e"
extensions:
- .n
Nimrod:
type: programming
color: "#37775b"
extensions:
- .nim
- .nimrod
@@ -710,6 +791,7 @@ Nimrod:
Nu:
type: programming
lexer: Scheme
color: "#c9df40"
aliases:
- nush
extensions:
@@ -728,6 +810,7 @@ NumPy:
OCaml:
type: programming
ace_mode: ocaml
color: "#3be133"
primary_extension: .ml
extensions:
- .ml
@@ -743,6 +826,7 @@ ObjDump:
Objective-C:
type: programming
color: "#438eff"
overrides:
- .m
primary_extension: .m
@@ -753,13 +837,13 @@ Objective-C:
Objective-J:
type: programming
color: "#ff0c5a"
extensions:
- .j
- .sj
Opa:
type: programming
lexer: Text only
extensions:
- .opa
@@ -784,6 +868,7 @@ OpenEdge ABL:
PHP:
type: programming
ace_mode: php
color: "#6e03c1"
extensions:
- .aw
- .ctp
@@ -792,9 +877,12 @@ PHP:
- .php4
- .php5
- .phpt
filenames:
- Phakefile
Parrot:
type: programming
color: "#f3ca0a"
lexer: Text only
primary_extension: .parrot # Dummy extension
@@ -819,6 +907,7 @@ Parrot Assembly:
Perl:
type: programming
ace_mode: perl
color: "#0298c3"
overrides:
- .pl
- .t
@@ -830,13 +919,13 @@ Perl:
- .pl
- .plx
- .pm
- .pm6
- .pod
- .psgi
- .t
Powershell:
PowerShell:
type: programming
lexer: Text only
ace_mode: powershell
aliases:
- posh
@@ -846,6 +935,7 @@ Powershell:
Prolog:
type: programming
color: "#74283c"
extensions:
- .pl
- .pro
@@ -853,12 +943,15 @@ Prolog:
Puppet:
type: programming
lexer: Text only
color: "#cc5555"
extensions:
- .pp
filenames:
- Modulefile
Pure Data:
type: programming
color: "#91de79"
lexer: Text only
extensions:
- .pd
@@ -866,12 +959,15 @@ Pure Data:
Python:
type: programming
ace_mode: python
color: "#3581ba"
primary_extension: .py
extensions:
- .py
- .pyw
- .wsgi
- .xpy
filenames:
- wscript
Python traceback:
type: data
@@ -883,6 +979,7 @@ Python traceback:
R:
type: programming
color: "#198ce7"
lexer: S
overrides:
- .r
@@ -900,6 +997,7 @@ RHTML:
Racket:
type: programming
lexer: Scheme
color: "#ae17ff"
primary_extension: .rkt
extensions:
- .rkt
@@ -917,6 +1015,7 @@ Raw token data:
Rebol:
type: programming
lexer: REBOL
color: "#358a5b"
extensions:
- .r
- .r2
@@ -930,6 +1029,7 @@ Redcode:
Ruby:
type: programming
ace_mode: ruby
color: "#701516"
aliases:
- jruby
- macruby
@@ -962,8 +1062,8 @@ Ruby:
Rust:
type: programming
color: "#dea584"
lexer: Text only
primary_extension: .rs
extensions:
- .rs
@@ -985,7 +1085,6 @@ Sage:
type: programming
lexer: Python
group: Python
primary_extension: .sage
extensions:
- .sage
@@ -998,6 +1097,7 @@ Sass:
Scala:
type: programming
ace_mode: scala
color: "#7dd3b0"
primary_extension: .scala
extensions:
- .sbt
@@ -1005,6 +1105,7 @@ Scala:
Scheme:
type: programming
color: "#1e4aec"
primary_extension: .scm
extensions:
- .scm
@@ -1021,6 +1122,7 @@ Scilab:
Self:
type: programming
color: "#0579aa"
lexer: Text only
extensions:
- .self
@@ -1029,6 +1131,7 @@ Shell:
type: programming
lexer: Bash
search_term: bash
color: "#5861ce"
aliases:
- sh
- bash
@@ -1047,9 +1150,11 @@ Shell:
- .zshrc
- bashrc
- zshrc
- PKGBUILD
Smalltalk:
type: programming
color: "#596706"
extensions:
- .st
@@ -1059,7 +1164,7 @@ Smarty:
Standard ML:
type: programming
lexer: Standard ML
color: "#dc566d"
aliases:
- sml
primary_extension: .sml
@@ -1069,12 +1174,14 @@ Standard ML:
SuperCollider:
type: programming
color: "#46390b"
lexer: Text only
extensions:
- .sc
Tcl:
type: programming
color: "#e4cc98"
extensions:
- .tcl
@@ -1102,6 +1209,11 @@ TeX:
- .tex
- .toc
Tea:
type: markup
extensions:
- .tea
Text:
type: data
lexer: Text only
@@ -1118,8 +1230,8 @@ Textile:
Turing:
type: programming
color: "#45f715"
lexer: Text only
primary_extension: .t
extensions:
- .t
- .tu
@@ -1133,14 +1245,15 @@ Twig:
VHDL:
type: programming
lexer: Text only
primary_extension: .vhd
lexer: vhdl
color: "#543978"
extensions:
- .vhd
- .vhdl
Vala:
type: programming
color: "#ee7d06"
extensions:
- .vala
- .vapi
@@ -1148,6 +1261,7 @@ Vala:
Verilog:
type: programming
lexer: verilog
color: "#848bf3"
overrides:
- .v
extensions:
@@ -1155,6 +1269,7 @@ Verilog:
VimL:
type: programming
color: "#199c4b"
search_term: vim
aliases:
- vim
@@ -1169,6 +1284,7 @@ VimL:
Visual Basic:
type: programming
lexer: VB.net
color: "#945db7"
primary_extension: .vb
extensions:
- .bas
@@ -1206,6 +1322,7 @@ XML:
XQuery:
type: programming
color: "#2700e2"
extensions:
- .xq
- .xqm
@@ -1217,6 +1334,12 @@ XS:
extensions:
- .xs
XSLT:
type: markup
group: XML
extensions:
- .xslt
YAML:
type: markup
primary_extension: .yml
@@ -1226,6 +1349,14 @@ YAML:
filenames:
- .gemrc
eC:
type: programming
search_term: ec
primary_extension: .ec
extensions:
- .ec
- .eh
mupad:
lexer: MuPAD
extensions:
@@ -1234,6 +1365,7 @@ mupad:
ooc:
type: programming
lexer: Ooc
color: "#b0b77e"
extensions:
- .ooc

View File

@@ -1,6 +1,10 @@
require 'mime/types'
require 'yaml'
class MIME::Type
attr_accessor :override
end
# Register additional mime type extensions
#
# Follows same format as mime-types data file
@@ -33,6 +37,8 @@ File.read(File.expand_path("../mimes.yml", __FILE__)).lines.each do |line|
mime_type.encoding = encoding
end
mime_type.override = true
# Kind of hacky, but we need to reindex the mime type after making changes
MIME::Types.add_type_variant(mime_type)
MIME::Types.index_extensions(mime_type)
@@ -72,8 +78,11 @@ module Linguist
guesses = ::MIME::Types.type_for(ext_or_mime_type)
end
# Prefer text mime types over binary
guesses.detect { |type| type.ascii? } ||
# Use custom override first
guesses.detect { |type| type.override } ||
# Prefer text mime types over binary
guesses.detect { |type| type.ascii? } ||
# Otherwise use the first guess
guesses.first

View File

@@ -50,6 +50,7 @@ application/x-supercollider @sc :8bit
application/x-troff-ms :8bit
application/x-wais-source :8bit
application/xaml+xml @xaml :8bit
application/xslt+xml @xslt :8bit
image/x-icns @icns
text/cache-manifest @manifest
text/plain @cu,cxx

View File

@@ -18,7 +18,7 @@
- ^tools/
# Node depedencies
- ^node_modules/
- node_modules/
# Vendored depedencies
- vendor/
@@ -88,3 +88,9 @@
# NuGet
- ^[Pp]ackages/
# ExtJS
- (^|/)extjs/
# Samples folders
- ^[Ss]amples/

View File

@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.add_dependency 'charlock_holmes', '~> 0.6.6'
s.add_dependency 'escape_utils', '~> 0.2.3'
s.add_dependency 'mime-types', '~> 1.16'
s.add_dependency 'pygments.rb', '~> 0.2.7'
s.add_dependency 'mime-types', '~> 1.18'
s.add_dependency 'pygments.rb', '~> 0.2.11'
s.add_development_dependency 'rake'
end

47
test/fixtures/Foo.kt vendored Normal file
View File

@@ -0,0 +1,47 @@
package addressbook
class Contact(
val name : String,
val emails : List<EmailAddress>,
val addresses : List<PostalAddress>,
val phonenums : List<PhoneNumber>
)
class EmailAddress(
val user : String,
val host : String
)
class PostalAddress(
val streetAddress : String,
val city : String,
val zip : String,
val state : USState?,
val country : Country
) {
assert {(state == null) xor (country == Countries["US"]) }
}
class PhoneNumber(
val country : Country,
val areaCode : Int,
val number : Long
)
object Countries {
fun get(id : CountryID) : Country = countryTable[id]
private var table : Map<String, Country>? = null
private val countryTable : Map<String, Country>
get() {
if (table == null) {
table = HashMap()
for (line in TextFile("countries.txt").lines(stripWhiteSpace = true)) {
table[line] = Country(line)
}
}
return table
}
}
class Country(val name : String)

43
test/fixtures/PKGBUILD vendored Normal file
View File

@@ -0,0 +1,43 @@
# Maintainer: Daniel Micay <danielmicay@gmail.com>
pkgname=stud-git
pkgver=20120316
pkgrel=1
pkgdesc="The Scalable TLS Unwrapping Daemon"
arch=(i686 x86_64)
url="https://github.com/bumptech/stud"
license=('BSD')
depends=(libev openssl)
makedepends=(git)
provides=(stud)
conflicts=(stud)
_gitroot=https://github.com/bumptech/stud.git
_gitname=stud
build() {
cd "$srcdir"
msg "Connecting to GIT server...."
if [[ -d "$_gitname" ]]; then
cd "$_gitname" && git pull origin
msg "The local files are updated."
else
git clone "$_gitroot" "$_gitname"
fi
msg "GIT checkout done or server timeout"
msg "Starting build..."
rm -rf "$srcdir/$_gitname-build"
git clone "$srcdir/$_gitname" "$srcdir/$_gitname-build"
cd "$srcdir/$_gitname-build"
make
}
package() {
cd "$srcdir/$_gitname-build"
make PREFIX=/usr DESTDIR="$pkgdir/" install
install -Dm755 init.stud "$pkgdir/etc/rc.d/stud"
mkdir -p "$pkgdir/etc/stud"
}

0
test/fixtures/empty.m vendored Normal file
View File

1
test/fixtures/foo.tea vendored Normal file
View File

@@ -0,0 +1 @@
<% template foo() %>

14
test/fixtures/foo.vhd vendored Normal file
View File

@@ -0,0 +1,14 @@
-- VHDL example file
library ieee;
use ieee.std_logic_1164.all;
entity inverter is
port(a : in std_logic;
b : out std_logic);
end entity;
architecture rtl of inverter is
begin
b <= not a;
end architecture;

29
test/fixtures/matlab_class.m vendored Normal file
View File

@@ -0,0 +1,29 @@
classdef matlab_class
properties
R;
G;
B;
end
methods
function obj = matlab_class(r,g,b)
obj.R = r;
obj.G = g;
obj.B = b;
end
function disp(obj)
disp(['Red: ' num2str(obj.R) ...
', Green: ' num2str(obj.G) ...
', Blue: ' num2str(obj.B)]);
end
end
enumeration
red (1,0,0)
green (0,1,0)
blue (0,0,1)
cyan (0,1,1)
magenta (1,0,1)
yellow (1,1,0)
black (0,0,0)
white (1,1,1)
end
end

33
test/fixtures/matlab_function2.m vendored Normal file
View File

@@ -0,0 +1,33 @@
function ret = matlab_function2(A,B)
% Simple function that combines two values using function handles and displays
% the return value
% create function handles
fun1=@interface;
fun2=@implementation;
fun3=@property;
fun4=@synthesize;
% use function handles
ret = fun1(A)+fun2(A)+fun3(B)+fun4(B);
% Display the return value
disp('Return value in function');
disp(ret);
function A=interface(A)
% simple sub-function with same name Objective-C @keyword
A=2*A;
function A=implementation(A)
% simple sub-function with same name Objective-C @keyword
A=A^2;
function B=property(B)
% simple sub-function with same name Objective-C @keyword
B=2*B;
function B=synthesize(B)
% simple sub-function with same name Objective-C @keyword
B=B^2;

13
test/fixtures/matlab_script2.m vendored Normal file
View File

@@ -0,0 +1,13 @@
% Matlab example script 2
% Comments precended with arbitrary whitespace (spaces or tabs)
%Call matlab_function function which resides in the same directory
value1 = 5 % semicolon at end of line is not mandatory, only suppresses output to command line.
value2 = 3
% Calculate sum of value1 and value2
result = matlab_function(value1,value2);
disp('called from script')
disp(result);

15
test/fixtures/point.dart vendored Normal file
View File

@@ -0,0 +1,15 @@
class Point {
Point(this.x, this.y);
distanceTo(Point other) {
var dx = x - other.x;
var dy = y - other.y;
return Math.sqrt(dx * dx + dy * dy);
}
var x, y;
}
main() {
Point p = new Point(2, 3);
Point q = new Point(3, 4);
print('distance from p to q = ${p.distanceTo(q)}');
}

24
test/fixtures/steelseries-min.js vendored Normal file

File diff suppressed because one or more lines are too long

37
test/fixtures/stockcorr.jl vendored Normal file
View File

@@ -0,0 +1,37 @@
## Test case from Issue #445
#STOCKCORR - The original, unoptimised code that simulates two correlated assets
function stockcorr()
## Correlated asset information
CurrentPrice = [78. 102.] # Initial Prices of the two stocks
Corr = [1. 0.4; 0.4 1.] # Correlation Matrix
T = 500 # Number of days to simulate = 2years = 500days
n = 100000 # Number of simulations
dt = 1/250 # Time step (1year = 250days)
Div=[0.01 0.01] # Dividend
Vol=[0.2 0.3] # Volatility
## Market Information
r = 0.03 # Risk-free rate
## Define storages
SimulPriceA = zeros(T,n) # Simulated Price of Asset A
SimulPriceA[1,:] = CurrentPrice[1]
SimulPriceB = zeros(T,n) # Simulated Price of Asset B
SimulPriceB[1,:] = CurrentPrice[2]
## Generating the paths of stock prices by Geometric Brownian Motion
UpperTriangle=chol(Corr) # UpperTriangle Matrix by Cholesky decomposition
for i = 1:n
Wiener = randn(T-1,2)
CorrWiener = Wiener*UpperTriangle
for j = 2:T
SimulPriceA[j,i] = SimulPriceA[j-1,i]*exp((r-Div[1]-Vol[1]^2/2)*dt+Vol[1]*sqrt(dt)*CorrWiener[j-1,1])
SimulPriceB[j,i] = SimulPriceB[j-1,i]*exp((r-Div[2]-Vol[2]^2/2)*dt+Vol[2]*sqrt(dt)*CorrWiener[j-1,2])
end
end
return (SimulPriceA, SimulPriceB)
end

25
test/fixtures/test.xslt vendored Normal file
View File

@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

View File

@@ -33,6 +33,7 @@ class TestBlob < Test::Unit::TestCase
def test_mime_type
assert_equal "application/octet-stream", blob("dog.o").mime_type
assert_equal "application/ogg", blob("foo.ogg").mime_type
assert_equal "application/postscript", blob("octocat.ai").mime_type
assert_equal "application/x-ruby", blob("grit.rb").mime_type
assert_equal "application/x-sh", blob("script.sh").mime_type
@@ -42,6 +43,7 @@ class TestBlob < Test::Unit::TestCase
def test_content_type
assert_equal "application/octet-stream", blob("dog.o").content_type
assert_equal "application/ogg", blob("foo.ogg").content_type
assert_equal "application/pdf", blob("foo.pdf").content_type
assert_equal "image/png", blob("foo.png").content_type
assert_equal "text/plain; charset=iso-8859-2", blob("README").content_type
@@ -179,6 +181,7 @@ class TestBlob < Test::Unit::TestCase
def test_vendored
assert !blob("README").vendored?
assert !blob("ext/extconf.rb").vendored?
# Node depedencies
assert blob("node_modules/coffee-script/lib/coffee-script.js").vendored?
@@ -260,7 +263,7 @@ class TestBlob < Test::Unit::TestCase
def test_indexable
assert blob("file.txt").indexable?
assert blob("foo.rb").indexable?
assert !blob("defun.kt").indexable?
assert !blob("defu.nkt").indexable?
assert !blob("dump.sql").indexable?
assert !blob("github.po").indexable?
assert !blob("linguist.gem").indexable?
@@ -285,6 +288,7 @@ class TestBlob < Test::Unit::TestCase
assert_equal Language['Ruby'], blob("script.rb").language
assert_equal Language['Ruby'], blob("wrong_shebang.rb").language
assert_equal Language['Arduino'], blob("hello.ino").language
assert_equal Language['VHDL'], blob("foo.vhd").language
assert_nil blob("octocat.png").language
# .cls disambiguation
@@ -303,10 +307,14 @@ class TestBlob < Test::Unit::TestCase
assert_equal Language['Perl'], blob("test-perl2.pl").language
# .m disambiguation
assert_equal Language['Objective-C'], blob("empty.m").language
assert_equal Language['Objective-C'], blob("Foo.m").language
assert_equal Language['Objective-C'], blob("hello.m").language
assert_equal Language['Matlab'], blob("matlab_function.m").language
assert_equal Language['Matlab'], blob("matlab_script.m").language
assert_equal Language['Matlab'], blob("matlab_function2.m").language
assert_equal Language['Matlab'], blob("matlab_script2.m").language
assert_equal Language['Matlab'], blob("matlab_class.m").language
assert_equal Language['M'], blob("m_simple.m").language
# .r disambiguation
@@ -419,6 +427,24 @@ class TestBlob < Test::Unit::TestCase
# OpenEdge ABL / Progress
assert_equal Language['OpenEdge ABL'], blob("openedge.p").language
# Tea
assert_equal Language['Tea'], blob("foo.tea").language
# Kotlin
assert_equal Language['Kotlin'], blob("Foo.kt").language
# Julia: http://julialang.org/
assert_equal Language['Julia'], blob("stockcorr.jl").language
# Dart: http://dartlang.org/
assert_equal Language['Dart'], blob("point.dart").language
# Arch Linux PKGBUILD
assert_equal Language['Shell'], blob("PKGBUILD").language
# XML
assert_equal Language['XSLT'], blob("test.xslt").language
end
def test_lexer
@@ -428,6 +454,11 @@ class TestBlob < Test::Unit::TestCase
assert_equal Lexer['Ruby'], blob("grit.rb").lexer
assert_equal Lexer['Scheme'], blob("dude.el").lexer
assert_equal Lexer['Text only'], blob("README").lexer
assert_equal Lexer['Tea'], blob("foo.tea").lexer
assert_equal Lexer['vhdl'], blob("foo.vhd").lexer
assert_equal Lexer['Julia'], blob("stockcorr.jl").lexer
assert_equal Lexer['Dart'], blob("point.dart").lexer
assert_equal Lexer['Bash'], blob("PKGBUILD").lexer
end
def test_shebang_script
@@ -483,7 +514,12 @@ class TestBlob < Test::Unit::TestCase
HTML
end
def test_colorize_skips_minified_files
def test_colorize_does_skip_minified_files
assert_nil blob("jquery-1.6.1.min.js").colorize
end
# Pygments.rb was taking exceeding long on this particular file
def test_colorize_doesnt_blow_up_with_files_with_high_ratio_of_long_lines
assert_nil blob("steelseries-min.js").colorize
end
end

View File

@@ -41,24 +41,24 @@ class TestLanguage < Test::Unit::TestCase
assert_equal Lexer['C++'], Language['C++'].lexer
assert_equal Lexer['Coldfusion HTML'], Language['ColdFusion'].lexer
assert_equal Lexer['Coq'], Language['Coq'].lexer
assert_equal Lexer['FSharp'], Language['F#'].lexer
assert_equal Lexer['FSharp'], Language['F#'].lexer
assert_equal Lexer['Fortran'], Language['FORTRAN'].lexer
assert_equal Lexer['Gherkin'], Language['Cucumber'].lexer
assert_equal Lexer['Groovy'], Language['Groovy'].lexer
assert_equal Lexer['HTML'], Language['HTML'].lexer
assert_equal Lexer['HTML+Django/Jinja'], Language['HTML+Django'].lexer
assert_equal Lexer['HTML+PHP'], Language['HTML+PHP'].lexer
assert_equal Lexer['JSON'], Language['JSON'].lexer
assert_equal Lexer['Java'], Language['ChucK'].lexer
assert_equal Lexer['Java'], Language['Groovy'].lexer
assert_equal Lexer['Java'], Language['Java'].lexer
assert_equal Lexer['JavaScript'], Language['JSON'].lexer
assert_equal Lexer['JavaScript'], Language['JavaScript'].lexer
assert_equal Lexer['MOOCode'], Language['Moocode'].lexer
assert_equal Lexer['MuPAD'], Language['mupad'].lexer
assert_equal Lexer['NASM'], Language['Assembly'].lexer
assert_equal Lexer['OCaml'], Language['F#'].lexer
assert_equal Lexer['OCaml'], Language['OCaml'].lexer
assert_equal Lexer['OpenEdge ABL'], Language['OpenEdge ABL'].lexer
assert_equal Lexer['Standard ML'], Language['Standard ML'].lexer
assert_equal Lexer['Ooc'], Language['ooc'].lexer
assert_equal Lexer['OpenEdge ABL'], Language['OpenEdge ABL'].lexer
assert_equal Lexer['REBOL'], Language['Rebol'].lexer
assert_equal Lexer['RHTML'], Language['HTML+ERB'].lexer
assert_equal Lexer['RHTML'], Language['RHTML'].lexer
@@ -69,9 +69,11 @@ class TestLanguage < Test::Unit::TestCase
assert_equal Lexer['Scheme'], Language['Nu'].lexer
assert_equal Lexer['Scheme'], Language['Racket'].lexer
assert_equal Lexer['Scheme'], Language['Scheme'].lexer
assert_equal Lexer['Standard ML'], Language['Standard ML'].lexer
assert_equal Lexer['TeX'], Language['TeX'].lexer
assert_equal Lexer['Text only'], Language['Text'].lexer
assert_equal Lexer['Verilog'], Language['Verilog'].lexer
assert_equal Lexer['XSLT'], Language['XSLT'].lexer
assert_equal Lexer['aspx-vb'], Language['ASP'].lexer
assert_equal Lexer['haXe'], Language['HaXe'].lexer
assert_equal Lexer['reStructuredText'], Language['reStructuredText'].lexer
@@ -94,6 +96,7 @@ class TestLanguage < Test::Unit::TestCase
assert_equal Language['Common Lisp'], Language.find_by_alias('common-lisp')
assert_equal Language['Common Lisp'], Language.find_by_alias('lisp')
assert_equal Language['Darcs Patch'], Language.find_by_alias('dpatch')
assert_equal Language['Dart'], Language.find_by_alias('dart')
assert_equal Language['Emacs Lisp'], Language.find_by_alias('elisp')
assert_equal Language['Emacs Lisp'], Language.find_by_alias('emacs')
assert_equal Language['Emacs Lisp'], Language.find_by_alias('emacs-lisp')
@@ -112,7 +115,7 @@ class TestLanguage < Test::Unit::TestCase
assert_equal Language['OpenEdge ABL'], Language.find_by_alias('progress')
assert_equal Language['OpenEdge ABL'], Language.find_by_alias('abl')
assert_equal Language['Parrot Internal Representation'], Language.find_by_alias('pir')
assert_equal Language['Powershell'], Language.find_by_alias('posh')
assert_equal Language['PowerShell'], Language.find_by_alias('posh')
assert_equal Language['Puppet'], Language.find_by_alias('puppet')
assert_equal Language['Pure Data'], Language.find_by_alias('pure-data')
assert_equal Language['Raw token data'], Language.find_by_alias('raw')
@@ -146,6 +149,7 @@ class TestLanguage < Test::Unit::TestCase
assert_equal Language['Shell'], Language['Gentoo Ebuild'].group
assert_equal Language['Shell'], Language['Gentoo Eclass'].group
assert_equal Language['Shell'], Language['Tcsh'].group
assert_equal Language['XML'], Language['XSLT'].group
# Ensure everyone has a group
Language.all.each do |language|
@@ -196,7 +200,7 @@ class TestLanguage < Test::Unit::TestCase
def test_programming
assert_equal :programming, Language['JavaScript'].type
assert_equal :programming, Language['Perl'].type
assert_equal :programming, Language['Powershell'].type
assert_equal :programming, Language['PowerShell'].type
assert_equal :programming, Language['Python'].type
assert_equal :programming, Language['Ruby'].type
end
@@ -241,6 +245,7 @@ class TestLanguage < Test::Unit::TestCase
def test_find_by_extension
assert_equal Language['Ruby'], Language.find_by_extension('.rb')
assert_equal Language['Ruby'], Language.find_by_extension('rb')
assert_equal Language['Dart'], Language.find_by_extension('dart')
assert_equal Language['Groff'], Language.find_by_extension('man')
assert_equal Language['Groff'], Language.find_by_extension('1')
assert_equal Language['Groff'], Language.find_by_extension('2')
@@ -249,9 +254,14 @@ class TestLanguage < Test::Unit::TestCase
assert_equal Language['PHP'], Language.find_by_extension('php3')
assert_equal Language['PHP'], Language.find_by_extension('php4')
assert_equal Language['PHP'], Language.find_by_extension('php5')
assert_equal Language['Powershell'], Language.find_by_extension('psm1')
assert_equal Language['Powershell'], Language.find_by_extension('ps1')
assert_nil Language.find_by_extension('.kt')
assert_equal Language['PowerShell'], Language.find_by_extension('psm1')
assert_equal Language['PowerShell'], Language.find_by_extension('ps1')
# Aliases for Streamline.js ( https://github.com/Sage/streamlinejs )
assert_equal Language['JavaScript'], Language.find_by_extension('_js')
assert_equal Language['CoffeeScript'], Language.find_by_extension('_coffee')
assert_nil Language.find_by_extension('.nkt')
end
def test_find_all_by_extension
@@ -265,12 +275,13 @@ class TestLanguage < Test::Unit::TestCase
end
def test_find_by_filename
assert_equal Language['Shell'], Language.find_by_filename('PKGBUILD')
assert_equal Language['Ruby'], Language.find_by_filename('foo.rb')
assert_equal Language['Ruby'], Language.find_by_filename('foo/bar.rb')
assert_equal Language['Ruby'], Language.find_by_filename('Rakefile')
assert_nil Language.find_by_filename('rb')
assert_nil Language.find_by_filename('.rb')
assert_nil Language.find_by_filename('.kt')
assert_nil Language.find_by_filename('.nkt')
end
def test_find
@@ -306,6 +317,17 @@ class TestLanguage < Test::Unit::TestCase
end
end
def test_color
assert_equal '#701516', Language['Ruby'].color
assert_equal '#3581ba', Language['Python'].color
assert_equal '#f15501', Language['JavaScript'].color
end
def test_colors
assert Language.colors.include?(Language['Ruby'])
assert Language.colors.include?(Language['Python'])
end
def test_ace_mode
assert_equal 'c_cpp', Language['C++'].ace_mode
assert_equal 'coffee', Language['CoffeeScript'].ace_mode
@@ -331,6 +353,8 @@ class TestLanguage < Test::Unit::TestCase
assert_equal '.pl', Language['Perl'].primary_extension
assert_equal '.py', Language['Python'].primary_extension
assert_equal '.rb', Language['Ruby'].primary_extension
assert_equal '.js', Language['JavaScript'].primary_extension
assert_equal '.coffee', Language['CoffeeScript'].primary_extension
# This is a nasty requirement, but theres some code in GitHub that
# expects this. Really want to drop this.

View File

@@ -14,6 +14,20 @@ class TestMime < Test::Unit::TestCase
# in mimes.yml. Its still useful to test even trivial cases since
# MIME::Type's extension lookup may return multiple matches and we
# only pick one of them. Please keep this list alphabetized.
assert_equal 'application/javascript', Mime.mime_for('.js')
assert_equal 'application/octet-stream', Mime.mime_for('.dll')
assert_equal 'application/octet-stream', Mime.mime_for('.dmg')
assert_equal 'application/octet-stream', Mime.mime_for('.exe')
assert_equal 'application/ogg', Mime.mime_for('.ogg')
assert_equal 'application/postscript', Mime.mime_for('.ai')
assert_equal 'application/postscript', Mime.mime_for('.eps')
assert_equal 'application/postscript', Mime.mime_for('.ps')
assert_equal 'application/vnd.adobe.air-application-installer-package+zip', Mime.mime_for('.air')
assert_equal 'application/vnd.oasis.opendocument.presentation', Mime.mime_for('.odp')
assert_equal 'application/vnd.oasis.opendocument.spreadsheet', Mime.mime_for('.ods')
assert_equal 'application/vnd.oasis.opendocument.text', Mime.mime_for('.odt')
assert_equal 'application/vnd.openofficeorg.extension', Mime.mime_for('.oxt')
assert_equal 'application/vnd.openxmlformats-officedocument.presentationml.presentation', Mime.mime_for('.pptx')
assert_equal 'application/x-chrome-extension', Mime.mime_for('.crx')
assert_equal 'application/x-debian-package', Mime.mime_for('.deb')
assert_equal 'application/x-iwork-keynote-sffkey', Mime.mime_for('.key')
@@ -22,37 +36,19 @@ class TestMime < Test::Unit::TestCase
assert_equal 'application/x-java-archive', Mime.mime_for('.ear')
assert_equal 'application/x-java-archive', Mime.mime_for('.jar')
assert_equal 'application/x-java-archive', Mime.mime_for('.war')
assert_equal 'application/javascript', Mime.mime_for('.js')
assert_equal 'application/x-latex', Mime.mime_for('.latex')
assert_equal 'application/x-ms-xbap', Mime.mime_for('.xbap')
assert_equal 'application/octet-stream', Mime.mime_for('.dll')
assert_equal 'application/octet-stream', Mime.mime_for('.dmg')
assert_equal 'application/octet-stream', Mime.mime_for('.exe')
assert_equal 'application/x-perl', Mime.mime_for('.pl')
assert_equal 'application/x-perl', Mime.mime_for('.pm')
assert_equal 'application/postscript', Mime.mime_for('.ai')
assert_equal 'application/postscript', Mime.mime_for('.eps')
assert_equal 'application/postscript', Mime.mime_for('.ps')
assert_equal 'application/x-python', Mime.mime_for('.py')
assert_equal 'application/x-ruby', Mime.mime_for('.rb')
assert_equal 'application/x-sh', Mime.mime_for('.sh')
assert_equal 'application/x-shockwave-flash', Mime.mime_for('.swf')
assert_equal 'application/x-silverlight-app', Mime.mime_for('.xap')
assert_equal 'application/x-supercollider', Mime.mime_for('.sc')
assert_equal 'application/vnd.adobe.air-application-installer-package+zip', Mime.mime_for('.air')
assert_equal 'application/vnd.oasis.opendocument.presentation', Mime.mime_for('.odp')
assert_equal 'application/vnd.oasis.opendocument.spreadsheet', Mime.mime_for('.ods')
assert_equal 'application/vnd.oasis.opendocument.text', Mime.mime_for('.odt')
assert_equal 'application/vnd.openofficeorg.extension', Mime.mime_for('.oxt')
assert_equal 'application/vnd.openxmlformats-officedocument.presentationml.presentation', Mime.mime_for('.pptx')
assert_equal 'application/xaml+xml', Mime.mime_for('.xaml')
assert_equal 'text/cache-manifest', Mime.mime_for('.manifest')
assert_equal 'text/html', Mime.mime_for('.html')
assert_equal 'text/x-nemerle', Mime.mime_for('.n')
assert_equal 'text/x-nimrod', Mime.mime_for('.nim')
assert_equal 'text/x-ocaml', Mime.mime_for('.ml')
assert_equal 'text/x-ocaml', Mime.mime_for('.sig')
assert_equal 'text/x-ocaml', Mime.mime_for('.sml')
assert_equal 'text/plain', Mime.mime_for('.c')
assert_equal 'text/plain', Mime.mime_for('.cc')
assert_equal 'text/plain', Mime.mime_for('.cpp')
@@ -63,8 +59,13 @@ class TestMime < Test::Unit::TestCase
assert_equal 'text/plain', Mime.mime_for('.hpp')
assert_equal 'text/plain', Mime.mime_for('.kt')
assert_equal 'text/x-logtalk', Mime.mime_for('.lgt')
assert_equal 'text/x-rust', Mime.mime_for('.rs')
assert_equal 'text/x-nemerle', Mime.mime_for('.n')
assert_equal 'text/x-nimrod', Mime.mime_for('.nim')
assert_equal 'text/x-ocaml', Mime.mime_for('.ml')
assert_equal 'text/x-ocaml', Mime.mime_for('.sig')
assert_equal 'text/x-ocaml', Mime.mime_for('.sml')
assert_equal 'text/x-rust', Mime.mime_for('.rc')
assert_equal 'text/x-rust', Mime.mime_for('.rs')
assert_equal 'video/quicktime', Mime.mime_for('.mov')
end
end

View File

@@ -41,7 +41,7 @@ class TestPathname < Test::Unit::TestCase
assert_equal Language['Python'], Pathname.new("itty.py").language
assert_equal Language['Nu'], Pathname.new("itty.nu").language
assert_nil Pathname.new("defun.kt").language
assert_nil Pathname.new("defu.nkt").language
end
def test_lexer
@@ -50,13 +50,13 @@ class TestPathname < Test::Unit::TestCase
assert_equal Lexer['Bash'], Pathname.new("file.ebuild").lexer
assert_equal Lexer['Python'], Pathname.new("itty.py").lexer
assert_equal Lexer['Scheme'], Pathname.new("itty.nu").lexer
assert_equal Lexer['Text only'], Pathname.new("defun.kt").lexer
assert_equal Lexer['Text only'], Pathname.new("defu.nkt").lexer
end
def test_mime_type
assert_equal 'application/x-ruby', Pathname.new("file.rb").mime_type
assert_equal 'application/javascript', Pathname.new("file.js").mime_type
assert_equal 'application/x-python', Pathname.new("itty.py").mime_type
assert_equal 'text/plain', Pathname.new("defun.kt").mime_type
assert_equal 'text/plain', Pathname.new("defu.nkt").mime_type
end
end