mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Merge branch 'master' into 1320-local
Conflicts: lib/linguist/samples.json
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
before_install:
|
before_install:
|
||||||
|
- git fetch origin master:master
|
||||||
|
- git fetch origin v2.0.0:v2.0.0
|
||||||
- sudo apt-get install libicu-dev -y
|
- sudo apt-get install libicu-dev -y
|
||||||
- gem update --system 2.1.11
|
- gem update --system 2.1.11
|
||||||
rvm:
|
rvm:
|
||||||
|
|||||||
@@ -152,4 +152,4 @@ If you are the current maintainer of this gem:
|
|||||||
0. Test behavior locally, branch deploy, whatever needs to happen
|
0. Test behavior locally, branch deploy, whatever needs to happen
|
||||||
0. Merge github/linguist PR
|
0. Merge github/linguist PR
|
||||||
0. Tag and push: `git tag vx.xx.xx; git push --tags`
|
0. Tag and push: `git tag vx.xx.xx; git push --tags`
|
||||||
0. Push to rubygems.org -- `gem push github-linguist-2.10.12.gem`
|
0. Push to rubygems.org -- `gem push github-linguist-3.0.0.gem`
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
require 'linguist/file_blob'
|
require 'linguist/file_blob'
|
||||||
require 'linguist/repository'
|
require 'linguist/repository'
|
||||||
|
require 'rugged'
|
||||||
|
|
||||||
path = ARGV[0] || Dir.pwd
|
path = ARGV[0] || Dir.pwd
|
||||||
|
|
||||||
@@ -18,7 +19,8 @@ ARGV.shift
|
|||||||
breakdown = true if ARGV[0] == "--breakdown"
|
breakdown = true if ARGV[0] == "--breakdown"
|
||||||
|
|
||||||
if File.directory?(path)
|
if File.directory?(path)
|
||||||
repo = Linguist::Repository.from_directory(path)
|
rugged = Rugged::Repository.new(path)
|
||||||
|
repo = Linguist::Repository.new(rugged, rugged.head.target_id)
|
||||||
repo.languages.sort_by { |_, size| size }.reverse.each do |language, size|
|
repo.languages.sort_by { |_, size| size }.reverse.each do |language, size|
|
||||||
percentage = ((size / repo.size.to_f) * 100)
|
percentage = ((size / repo.size.to_f) * 100)
|
||||||
percentage = sprintf '%.2f' % percentage
|
percentage = sprintf '%.2f' % percentage
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|||||||
s.add_dependency 'escape_utils', '~> 1.0.1'
|
s.add_dependency 'escape_utils', '~> 1.0.1'
|
||||||
s.add_dependency 'mime-types', '~> 1.19'
|
s.add_dependency 'mime-types', '~> 1.19'
|
||||||
s.add_dependency 'pygments.rb', '~> 0.6.0'
|
s.add_dependency 'pygments.rb', '~> 0.6.0'
|
||||||
|
s.add_dependency 'rugged', '~> 0.21.0'
|
||||||
|
|
||||||
s.add_development_dependency 'json'
|
s.add_development_dependency 'json'
|
||||||
s.add_development_dependency 'mocha'
|
s.add_development_dependency 'mocha'
|
||||||
|
|||||||
@@ -313,15 +313,7 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Returns a Language or nil if none is detected
|
# Returns a Language or nil if none is detected
|
||||||
def language
|
def language
|
||||||
return @language if defined? @language
|
@language ||= Language.detect(self)
|
||||||
|
|
||||||
if defined?(@data) && @data.is_a?(String)
|
|
||||||
data = @data
|
|
||||||
else
|
|
||||||
data = lambda { (binary_mime_type? || binary?) ? "" : self.data }
|
|
||||||
end
|
|
||||||
|
|
||||||
@language = Language.detect(name.to_s, data, mode)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Internal: Get the lexer of the blob.
|
# Internal: Get the lexer of the blob.
|
||||||
|
|||||||
@@ -92,18 +92,17 @@ module Linguist
|
|||||||
|
|
||||||
# Public: Detects the Language of the blob.
|
# Public: Detects the Language of the blob.
|
||||||
#
|
#
|
||||||
# name - String filename
|
# blob - an object that implements the Linguist `Blob` interface;
|
||||||
# data - String blob data. A block also maybe passed in for lazy
|
# see Linguist::LazyBlob and Linguist::FileBlob for examples
|
||||||
# loading. This behavior is deprecated and you should always
|
|
||||||
# pass in a String.
|
|
||||||
# mode - Optional String mode (defaults to nil)
|
|
||||||
#
|
#
|
||||||
# Returns Language or nil.
|
# Returns Language or nil.
|
||||||
def self.detect(name, data, mode = nil)
|
def self.detect(blob)
|
||||||
|
name = blob.name.to_s
|
||||||
|
|
||||||
# A bit of an elegant hack. If the file is executable but extensionless,
|
# A bit of an elegant hack. If the file is executable but extensionless,
|
||||||
# append a "magic" extension so it can be classified with other
|
# append a "magic" extension so it can be classified with other
|
||||||
# languages that have shebang scripts.
|
# languages that have shebang scripts.
|
||||||
if File.extname(name).empty? && mode && (mode.to_i(8) & 05) == 05
|
if File.extname(name).empty? && blob.mode && (blob.mode.to_i(8) & 05) == 05
|
||||||
name += ".script!"
|
name += ".script!"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -114,7 +113,7 @@ module Linguist
|
|||||||
# extension at all, in the case of extensionless scripts), we need to continue
|
# extension at all, in the case of extensionless scripts), we need to continue
|
||||||
# our detection work
|
# our detection work
|
||||||
if possible_languages.length > 1
|
if possible_languages.length > 1
|
||||||
data = data.call() if data.respond_to?(:call)
|
data = blob.data
|
||||||
possible_language_names = possible_languages.map(&:name)
|
possible_language_names = possible_languages.map(&:name)
|
||||||
|
|
||||||
# Don't bother with emptiness
|
# Don't bother with emptiness
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ Agda:
|
|||||||
|
|
||||||
Alloy:
|
Alloy:
|
||||||
type: programming # 'modeling' would be more appropiate
|
type: programming # 'modeling' would be more appropiate
|
||||||
lexer: Text only
|
lexer: Alloy
|
||||||
color: "#cc5c24"
|
color: "#cc5c24"
|
||||||
extensions:
|
extensions:
|
||||||
- .als
|
- .als
|
||||||
@@ -222,6 +222,8 @@ BlitzBasic:
|
|||||||
- .decls
|
- .decls
|
||||||
|
|
||||||
BlitzMax:
|
BlitzMax:
|
||||||
|
type: programming
|
||||||
|
color: "#cd6400"
|
||||||
extensions:
|
extensions:
|
||||||
- .bmx
|
- .bmx
|
||||||
|
|
||||||
@@ -735,12 +737,14 @@ GLSL:
|
|||||||
- .glsl
|
- .glsl
|
||||||
- .fp
|
- .fp
|
||||||
- .frag
|
- .frag
|
||||||
|
- .frg
|
||||||
- .fshader
|
- .fshader
|
||||||
- .geom
|
- .geom
|
||||||
- .glslv
|
- .glslv
|
||||||
- .gshader
|
- .gshader
|
||||||
- .shader
|
- .shader
|
||||||
- .vert
|
- .vert
|
||||||
|
- .vrx
|
||||||
- .vshader
|
- .vshader
|
||||||
|
|
||||||
Genshi:
|
Genshi:
|
||||||
@@ -798,6 +802,12 @@ Gosu:
|
|||||||
extensions:
|
extensions:
|
||||||
- .gs
|
- .gs
|
||||||
|
|
||||||
|
Grace:
|
||||||
|
type: programming
|
||||||
|
lexer: Text only
|
||||||
|
extensions:
|
||||||
|
- .grace
|
||||||
|
|
||||||
Grammatical Framework:
|
Grammatical Framework:
|
||||||
type: programming
|
type: programming
|
||||||
lexer: Haskell
|
lexer: Haskell
|
||||||
@@ -1397,7 +1407,6 @@ Nimrod:
|
|||||||
|
|
||||||
Nit:
|
Nit:
|
||||||
type: programming
|
type: programming
|
||||||
#lexer: Nit
|
|
||||||
lexer: Text only
|
lexer: Text only
|
||||||
color: "#0d8921"
|
color: "#0d8921"
|
||||||
extensions:
|
extensions:
|
||||||
@@ -1544,6 +1553,8 @@ PHP:
|
|||||||
- .phpt
|
- .phpt
|
||||||
filenames:
|
filenames:
|
||||||
- Phakefile
|
- Phakefile
|
||||||
|
interpreters:
|
||||||
|
- php
|
||||||
|
|
||||||
Pan:
|
Pan:
|
||||||
type: programming
|
type: programming
|
||||||
|
|||||||
37
lib/linguist/lazy_blob.rb
Normal file
37
lib/linguist/lazy_blob.rb
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
require 'linguist/blob_helper'
|
||||||
|
require 'rugged'
|
||||||
|
|
||||||
|
module Linguist
|
||||||
|
class LazyBlob
|
||||||
|
include BlobHelper
|
||||||
|
|
||||||
|
MAX_SIZE = 128 * 1024
|
||||||
|
|
||||||
|
attr_reader :repository
|
||||||
|
attr_reader :oid
|
||||||
|
attr_reader :name
|
||||||
|
attr_reader :mode
|
||||||
|
|
||||||
|
def initialize(repo, oid, name, mode = nil)
|
||||||
|
@repository = repo
|
||||||
|
@oid = oid
|
||||||
|
@name = name
|
||||||
|
@mode = mode
|
||||||
|
end
|
||||||
|
|
||||||
|
def data
|
||||||
|
load_blob!
|
||||||
|
@data
|
||||||
|
end
|
||||||
|
|
||||||
|
def size
|
||||||
|
load_blob!
|
||||||
|
@size
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
def load_blob!
|
||||||
|
@data, @size = Rugged::Blob.to_buffer(repository, oid, MAX_SIZE) if @data.nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
require 'linguist/file_blob'
|
require 'linguist/lazy_blob'
|
||||||
|
require 'rugged'
|
||||||
|
|
||||||
module Linguist
|
module Linguist
|
||||||
# A Repository is an abstraction of a Grit::Repo or a basic file
|
# A Repository is an abstraction of a Grit::Repo or a basic file
|
||||||
@@ -7,100 +8,146 @@ module Linguist
|
|||||||
# Its primary purpose is for gathering language statistics across
|
# Its primary purpose is for gathering language statistics across
|
||||||
# the entire project.
|
# the entire project.
|
||||||
class Repository
|
class Repository
|
||||||
# Public: Initialize a new Repository from a File directory
|
attr_reader :repository
|
||||||
#
|
|
||||||
# base_path - A path String
|
# Public: Create a new Repository based on the stats of
|
||||||
#
|
# an existing one
|
||||||
# Returns a Repository
|
def self.incremental(repo, commit_oid, old_commit_oid, old_stats)
|
||||||
def self.from_directory(base_path)
|
repo = self.new(repo, commit_oid)
|
||||||
new Dir["#{base_path}/**/*"].
|
repo.load_existing_stats(old_commit_oid, old_stats)
|
||||||
select { |f| File.file?(f) }.
|
repo
|
||||||
map { |path| FileBlob.new(path, base_path) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Initialize a new Repository
|
# Public: Initialize a new Repository to be analyzed for language
|
||||||
|
# data
|
||||||
#
|
#
|
||||||
# enum - Enumerator that responds to `each` and
|
# repo - a Rugged::Repository object
|
||||||
# yields Blob objects
|
# commit_oid - the sha1 of the commit that will be analyzed;
|
||||||
|
# this is usually the master branch
|
||||||
#
|
#
|
||||||
# Returns a Repository
|
# Returns a Repository
|
||||||
def initialize(enum)
|
def initialize(repo, commit_oid)
|
||||||
@enum = enum
|
@repository = repo
|
||||||
@computed_stats = false
|
@commit_oid = commit_oid
|
||||||
@language = @size = nil
|
|
||||||
@sizes = Hash.new { 0 }
|
raise TypeError, 'commit_oid must be a commit SHA1' unless commit_oid.is_a?(String)
|
||||||
@file_breakdown = Hash.new { |h,k| h[k] = Array.new }
|
end
|
||||||
|
|
||||||
|
# Public: Load the results of a previous analysis on this repository
|
||||||
|
# to speed up the new scan.
|
||||||
|
#
|
||||||
|
# The new analysis will be performed incrementally as to only take
|
||||||
|
# into account the file changes since the last time the repository
|
||||||
|
# was scanned
|
||||||
|
#
|
||||||
|
# old_commit_oid - the sha1 of the commit that was previously analyzed
|
||||||
|
# old_stats - the result of the previous analysis, obtained by calling
|
||||||
|
# Repository#cache on the old repository
|
||||||
|
#
|
||||||
|
# Returns nothing
|
||||||
|
def load_existing_stats(old_commit_oid, old_stats)
|
||||||
|
@old_commit_oid = old_commit_oid
|
||||||
|
@old_stats = old_stats
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Returns a breakdown of language stats.
|
# Public: Returns a breakdown of language stats.
|
||||||
#
|
#
|
||||||
# Examples
|
# Examples
|
||||||
#
|
#
|
||||||
# # => { Language['Ruby'] => 46319,
|
# # => { 'Ruby' => 46319,
|
||||||
# Language['JavaScript'] => 258 }
|
# 'JavaScript' => 258 }
|
||||||
#
|
#
|
||||||
# Returns a Hash of Language keys and Integer size values.
|
# Returns a Hash of language names and Integer size values.
|
||||||
def languages
|
def languages
|
||||||
compute_stats
|
@sizes ||= begin
|
||||||
@sizes
|
sizes = Hash.new { 0 }
|
||||||
|
cache.each do |_, (language, size)|
|
||||||
|
sizes[language] += size
|
||||||
|
end
|
||||||
|
sizes
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Get primary Language of repository.
|
# Public: Get primary Language of repository.
|
||||||
#
|
#
|
||||||
# Returns a Language
|
# Returns a language name
|
||||||
def language
|
def language
|
||||||
compute_stats
|
@language ||= begin
|
||||||
@language
|
primary = languages.max_by { |(_, size)| size }
|
||||||
|
primary && primary[0]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Get the total size of the repository.
|
# Public: Get the total size of the repository.
|
||||||
#
|
#
|
||||||
# Returns a byte size Integer
|
# Returns a byte size Integer
|
||||||
def size
|
def size
|
||||||
compute_stats
|
@size ||= languages.inject(0) { |s,(_,v)| s + v }
|
||||||
@size
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Public: Return the language breakdown of this repository by file
|
# Public: Return the language breakdown of this repository by file
|
||||||
|
#
|
||||||
|
# Returns a map of language names => [filenames...]
|
||||||
def breakdown_by_file
|
def breakdown_by_file
|
||||||
compute_stats
|
@file_breakdown ||= begin
|
||||||
@file_breakdown
|
breakdown = Hash.new { |h,k| h[k] = Array.new }
|
||||||
|
cache.each do |filename, (language, _)|
|
||||||
|
breakdown[language] << filename
|
||||||
|
end
|
||||||
|
breakdown
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Internal: Compute language breakdown for each blob in the Repository.
|
# Public: Return the cached results of the analysis
|
||||||
#
|
#
|
||||||
# Returns nothing
|
# This is a per-file breakdown that can be passed to other instances
|
||||||
def compute_stats
|
# of Linguist::Repository to perform incremental scans
|
||||||
return if @computed_stats
|
#
|
||||||
|
# Returns a map of filename => [language, size]
|
||||||
|
def cache
|
||||||
|
@cache ||= begin
|
||||||
|
if @old_commit_oid == @commit_oid
|
||||||
|
@old_stats
|
||||||
|
else
|
||||||
|
compute_stats(@old_commit_oid, @commit_oid, @old_stats)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@enum.each do |blob|
|
protected
|
||||||
# Skip files that are likely binary
|
def compute_stats(old_commit_oid, commit_oid, cache = nil)
|
||||||
next if blob.likely_binary?
|
file_map = cache ? cache.dup : {}
|
||||||
|
old_tree = old_commit_oid && Rugged::Commit.lookup(repository, old_commit_oid).tree
|
||||||
|
new_tree = Rugged::Commit.lookup(repository, commit_oid).tree
|
||||||
|
|
||||||
# Skip vendored or generated blobs
|
diff = Rugged::Tree.diff(repository, old_tree, new_tree)
|
||||||
next if blob.vendored? || blob.generated? || blob.language.nil?
|
|
||||||
|
|
||||||
# Only include programming languages and acceptable markup languages
|
diff.each_delta do |delta|
|
||||||
if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name)
|
old = delta.old_file[:path]
|
||||||
|
new = delta.new_file[:path]
|
||||||
|
|
||||||
# Build up the per-file breakdown stats
|
file_map.delete(old)
|
||||||
@file_breakdown[blob.language.group.name] << blob.name
|
next if delta.binary
|
||||||
|
|
||||||
@sizes[blob.language.group] += blob.size
|
if [:added, :modified].include? delta.status
|
||||||
|
# Skip submodules
|
||||||
|
mode = delta.new_file[:mode]
|
||||||
|
next if (mode & 040000) != 0
|
||||||
|
|
||||||
|
blob = Linguist::LazyBlob.new(repository, delta.new_file[:oid], new, mode.to_s(8))
|
||||||
|
|
||||||
|
# Skip vendored or generated blobs
|
||||||
|
next if blob.vendored? || blob.generated? || blob.language.nil?
|
||||||
|
|
||||||
|
# Only include programming languages and acceptable markup languages
|
||||||
|
if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name)
|
||||||
|
file_map[new] = [blob.language.group.name, blob.size]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Compute total size
|
file_map
|
||||||
@size = @sizes.inject(0) { |s,(_,v)| s + v }
|
|
||||||
|
|
||||||
# Get primary language
|
|
||||||
if primary = @sizes.max_by { |(_, size)| size }
|
|
||||||
@language = primary[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
@computed_stats = true
|
|
||||||
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
133598
lib/linguist/samples.json
133598
lib/linguist/samples.json
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,7 @@ module Linguist
|
|||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def self.each(&block)
|
def self.each(&block)
|
||||||
Dir.entries(ROOT).each do |category|
|
Dir.entries(ROOT).sort!.each do |category|
|
||||||
next if category == '.' || category == '..'
|
next if category == '.' || category == '..'
|
||||||
|
|
||||||
# Skip text and binary for now
|
# Skip text and binary for now
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
# Vendored dependencies
|
# Vendored dependencies
|
||||||
- thirdparty/
|
- thirdparty/
|
||||||
- vendors?/
|
- vendors?/
|
||||||
|
- extern(al)?/
|
||||||
|
|
||||||
# Debian packaging
|
# Debian packaging
|
||||||
- ^debian/
|
- ^debian/
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Linguist
|
module Linguist
|
||||||
VERSION = "2.12.0"
|
VERSION = "3.0.0"
|
||||||
end
|
end
|
||||||
|
|||||||
25
samples/BlitzMax/sample.bmx
Normal file
25
samples/BlitzMax/sample.bmx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
SuperStrict
|
||||||
|
|
||||||
|
Framework Brl.StandardIO
|
||||||
|
|
||||||
|
Type TMyType
|
||||||
|
Field property:int
|
||||||
|
|
||||||
|
Function A:int(param:int)
|
||||||
|
'do nothing
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Method B:int(param:int)
|
||||||
|
'do nothing
|
||||||
|
End Method
|
||||||
|
End Type
|
||||||
|
|
||||||
|
|
||||||
|
Global my:TMyType = new TMyType
|
||||||
|
?Win32
|
||||||
|
my.A()
|
||||||
|
my.B()
|
||||||
|
?Linux
|
||||||
|
my.B()
|
||||||
|
my.A()
|
||||||
|
?
|
||||||
6
samples/GLSL/myfragment.frg
Normal file
6
samples/GLSL/myfragment.frg
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
varying vec4 v_color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_FragColor = v_color;
|
||||||
|
}
|
||||||
12
samples/GLSL/myvertex.vrx
Normal file
12
samples/GLSL/myvertex.vrx
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
uniform mat4 u_MVPMatrix;
|
||||||
|
|
||||||
|
attribute vec4 a_position;
|
||||||
|
attribute vec4 a_color;
|
||||||
|
|
||||||
|
varying vec4 v_color;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
v_color = a_color;
|
||||||
|
gl_Position = u_MVPMatrix * pos;
|
||||||
|
}
|
||||||
6
samples/Grace/ackerman_function.grace
Normal file
6
samples/Grace/ackerman_function.grace
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
method ack (m : Number, n : Number) -> Number {
|
||||||
|
print "ack {m} {n}"
|
||||||
|
if (m < = 0) then {n + 1}
|
||||||
|
elseif {n <= 0} then {ack((m -1), 1)}
|
||||||
|
else {ack(m -1, ack(m, n-1))}
|
||||||
|
}
|
||||||
554
samples/Grace/grace_IDE.grace
Normal file
554
samples/Grace/grace_IDE.grace
Normal file
@@ -0,0 +1,554 @@
|
|||||||
|
import "gtk" as gtk
|
||||||
|
import "io" as io
|
||||||
|
import "mgcollections" as collections
|
||||||
|
import "button_factory" as button_factory
|
||||||
|
import "dialog_factory" as dialog_factory
|
||||||
|
import "syntax_highlighter" as highlighter
|
||||||
|
import "auto_completer" as aComp
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
|
||||||
|
// Autocomplete typing
|
||||||
|
|
||||||
|
// FileChooser
|
||||||
|
// Themes
|
||||||
|
|
||||||
|
// Details for the Top Level Window
|
||||||
|
def window = gtk.window(gtk.GTK_WINDOW_TOPLEVEL)
|
||||||
|
window.title := "Grace"
|
||||||
|
window.set_default_size(700, 700)
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
// Placeholder for the console window that can be popped out
|
||||||
|
// of the main window
|
||||||
|
var popped := gtk.window(gtk.GTK_WINDOW_TOPLEVEL)
|
||||||
|
|
||||||
|
// Initialise the Boxes
|
||||||
|
def mBox = gtk.box(gtk.GTK_ORIENTATION_VERTICAL, 2)
|
||||||
|
def buttonBox = gtk.box(gtk.GTK_ORIENTATION_HORIZONTAL, 2)
|
||||||
|
var consoleButtons := gtk.box(gtk.GTK_ORIENTATION_HORIZONTAL, 3)
|
||||||
|
var consoleBox := gtk.box(gtk.GTK_ORIENTATION_VERTICAL, 2)
|
||||||
|
var editorBox := gtk.box(gtk.GTK_ORIENTATION_VERTICAL, 2)
|
||||||
|
var splitPane := gtk.paned(gtk.GTK_ORIENTATION_VERTICAL, 2)
|
||||||
|
def menuBox = gtk.box(gtk.GTK_ORIENTATION_HORIZONTAL, 4)
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
// Initialise the buttons
|
||||||
|
def runButton = button_factory.make("run")
|
||||||
|
var clearButton := button_factory.make("clear")
|
||||||
|
var outButton := button_factory.make("out")
|
||||||
|
var errorButton := button_factory.make("error")
|
||||||
|
var popButton := button_factory.make("pop")
|
||||||
|
def newButton = button_factory.make("new")
|
||||||
|
def openButton = button_factory.make("open")
|
||||||
|
def saveButton = button_factory.make("save")
|
||||||
|
def saveAsButton = button_factory.make("saveAs")
|
||||||
|
def closeButton = button_factory.make("close")
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
// Details for the default text editor and scrolled window
|
||||||
|
var tEdit := gtk.text_view
|
||||||
|
tEdit.set_size_request(700, 400)
|
||||||
|
|
||||||
|
var scrolled_main := gtk.scrolled_window
|
||||||
|
scrolled_main.set_size_request(700, 400)
|
||||||
|
scrolled_main.add(tEdit)
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
// Widget that allows multiple files to be edited (tabs)
|
||||||
|
var notebook := gtk.notebook
|
||||||
|
notebook.scrollable := true
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
// Maps for holding the text_views and scrolled_windows
|
||||||
|
var editor_map := collections.map.new
|
||||||
|
editor_map.put(0, tEdit)
|
||||||
|
var scrolled_map := collections.map.new
|
||||||
|
scrolled_map.put(0, scrolled_main)
|
||||||
|
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
// Class that manages the syntax highlighting (This needs to be passed around otherwise
|
||||||
|
// the text_tag table gets confused, ie there can only be one)
|
||||||
|
def lighter = highlighter.Syntax_Highlighter.new(notebook, editor_map)
|
||||||
|
tEdit.buffer.on "changed" do {
|
||||||
|
lighter.highlightLine
|
||||||
|
}
|
||||||
|
|
||||||
|
// Class that manages any auto completion that is required
|
||||||
|
def completer = aComp.Auto_Completer.new(window, notebook, editor_map)
|
||||||
|
|
||||||
|
// Utility methods
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
method deleteCompileFiles(page_num : Number) {
|
||||||
|
def cur_scrolled = scrolled_map.get(page_num)
|
||||||
|
var filename := notebook.get_tab_label_text(cur_scrolled)
|
||||||
|
filename := filename.substringFrom(0)to(filename.size - 7) //Removes .grace extension
|
||||||
|
|
||||||
|
io.system("rm -f files/" ++ filename)
|
||||||
|
io.system("rm -f files/" ++ filename ++ ".c")
|
||||||
|
io.system("rm -f files/" ++ filename ++ ".gcn")
|
||||||
|
io.system("rm -f files/" ++ filename ++ ".gct")
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var currentConsole := "output" // Which console is being shown
|
||||||
|
var out := false
|
||||||
|
|
||||||
|
|
||||||
|
var outText := ""
|
||||||
|
var errorText := ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Give actions to the buttons
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
runButton.on "clicked" do {
|
||||||
|
clearConsoles()
|
||||||
|
|
||||||
|
// Get the details for the current page selected
|
||||||
|
def cur_page_num = notebook.current_page
|
||||||
|
def cur_page = editor_map.get(cur_page_num)
|
||||||
|
def cur_scrolled = scrolled_map.get(cur_page_num)
|
||||||
|
def cur_page_label = notebook.get_tab_label_text(cur_scrolled)
|
||||||
|
|
||||||
|
// Initialise text iterators
|
||||||
|
def sIter = gtk.text_iter
|
||||||
|
def eIter = gtk.text_iter
|
||||||
|
|
||||||
|
// Set one at the beggining and one at the end of the text
|
||||||
|
cur_page.buffer.get_iter_at_offset(sIter, 0)
|
||||||
|
cur_page.buffer.get_iter_at_offset(eIter, -1)
|
||||||
|
|
||||||
|
// Get the text between the text iterators
|
||||||
|
def text = cur_page.buffer.get_text(sIter, eIter, true)
|
||||||
|
|
||||||
|
// Save the text to the file (in case the user hasn't already saved it)
|
||||||
|
def file = io.open("files/" ++ cur_page_label, "w")
|
||||||
|
file.write(text)
|
||||||
|
file.close
|
||||||
|
|
||||||
|
// Run the program and pipe the output and errors into files to be read
|
||||||
|
io.system("../minigrace/minigrace " ++ "files/" ++ cur_page_label ++ " > output.txt 2> error.txt")
|
||||||
|
def outputFile = io.open("output.txt", "r")
|
||||||
|
def errorFile = io.open("error.txt", "r")
|
||||||
|
outText := outputFile.read
|
||||||
|
errorText := errorFile.read
|
||||||
|
|
||||||
|
io.system("rm -f output.txt error.txt")
|
||||||
|
|
||||||
|
var switched := false
|
||||||
|
|
||||||
|
// Change the console to output if there is output text
|
||||||
|
if((outText.size > 0) && (currentConsole != "output")) then {
|
||||||
|
switch_to_output()
|
||||||
|
switched := true
|
||||||
|
}
|
||||||
|
// Change the console to errors if there were errors
|
||||||
|
if((errorText.size > 0) && (currentConsole != "errors")) then {
|
||||||
|
switch_to_errors()
|
||||||
|
switched := true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remember to populate the console if it wasn't switched
|
||||||
|
if(!switched) then {
|
||||||
|
populateConsoles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clearButton.on "clicked" do {
|
||||||
|
clearConsoles()
|
||||||
|
}
|
||||||
|
|
||||||
|
outButton.on "clicked" do {
|
||||||
|
switch_to_output()
|
||||||
|
}
|
||||||
|
|
||||||
|
errorButton.on "clicked" do {
|
||||||
|
switch_to_errors()
|
||||||
|
}
|
||||||
|
|
||||||
|
popButton.on "clicked" do {
|
||||||
|
if(out) then {
|
||||||
|
popIn()
|
||||||
|
} else {
|
||||||
|
popOut()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gives a dialog to let the user create a new file to edit
|
||||||
|
newButton.on "clicked" do {
|
||||||
|
def new_window_class = dialog_factory.new.new(notebook, editor_map, scrolled_map, lighter)
|
||||||
|
|
||||||
|
def new_window = new_window_class.window()
|
||||||
|
new_window.show_all
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gives a dialog that lets the user open a file to edit
|
||||||
|
openButton.on "clicked" do {
|
||||||
|
def open_window_class = dialog_factory.open.new(notebook, editor_map, scrolled_map, lighter)
|
||||||
|
|
||||||
|
def open_window = open_window_class.window()
|
||||||
|
open_window.show_all
|
||||||
|
}
|
||||||
|
|
||||||
|
// Saves the current file (if the name is Untitled.grace it will ask for a new name)
|
||||||
|
saveButton.on "clicked" do {
|
||||||
|
def cur_page_num = notebook.current_page
|
||||||
|
def cur_page = editor_map.get(cur_page_num)
|
||||||
|
def cur_scrolled = scrolled_map.get(cur_page_num)
|
||||||
|
def cur_page_label = notebook.get_tab_label_text(cur_scrolled)
|
||||||
|
|
||||||
|
if(cur_page_label == "Untitled.grace") then {
|
||||||
|
def saveAs_window_class = dialog_factory.save.new(notebook, editor_map, scrolled_map, true)
|
||||||
|
|
||||||
|
def saveAs_window = saveAs_window_class.window()
|
||||||
|
saveAs_window.show_all
|
||||||
|
} else {
|
||||||
|
// Initialise text iterators
|
||||||
|
def sIter = gtk.text_iter
|
||||||
|
def eIter = gtk.text_iter
|
||||||
|
|
||||||
|
// Set one at the beggining and one at the end of the text
|
||||||
|
cur_page.buffer.get_iter_at_offset(sIter, 0)
|
||||||
|
cur_page.buffer.get_iter_at_offset(eIter, -1)
|
||||||
|
|
||||||
|
// Get the text between the text iterators
|
||||||
|
def text = cur_page.buffer.get_text(sIter, eIter, true)
|
||||||
|
|
||||||
|
// Save the file
|
||||||
|
def file = io.open("files/" ++ cur_page_label, "w")
|
||||||
|
file.write(text)
|
||||||
|
file.close
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gives a dialog that lets the user save the file with a new name
|
||||||
|
saveAsButton.on "clicked" do {
|
||||||
|
def saveAs_window_class = dialog_factory.save.new(notebook, editor_map, scrolled_map, false)
|
||||||
|
|
||||||
|
def saveAs_window = saveAs_window_class.window()
|
||||||
|
saveAs_window.show_all
|
||||||
|
}
|
||||||
|
|
||||||
|
// This will close a tab on the notebook
|
||||||
|
// It also "removes" the page from the map,
|
||||||
|
// by creating a new temporary map and putting all but
|
||||||
|
// the removed page in.
|
||||||
|
closeButton.on "clicked" do {
|
||||||
|
def page_num = notebook.current_page
|
||||||
|
def num_pages = notebook.n_pages
|
||||||
|
|
||||||
|
if(num_pages > 1) then {
|
||||||
|
deleteCompileFiles(page_num)
|
||||||
|
|
||||||
|
def e_map = collections.map.new
|
||||||
|
def s_map = collections.map.new
|
||||||
|
|
||||||
|
// Copy every page up to the current page into the new maps
|
||||||
|
var x := 0
|
||||||
|
while {x < page_num} do {
|
||||||
|
var eValue := editor_map.get(x)
|
||||||
|
var sValue := scrolled_map.get(x)
|
||||||
|
e_map.put(x, eValue)
|
||||||
|
s_map.put(x, sValue)
|
||||||
|
|
||||||
|
x := x + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy every page after the current page into the new map (shifted one down)
|
||||||
|
x := page_num + 1
|
||||||
|
while {x < num_pages} do {
|
||||||
|
var eValue := editor_map.get(x)
|
||||||
|
var sValue := scrolled_map.get(x)
|
||||||
|
e_map.put((x - 1), eValue)
|
||||||
|
s_map.put((x - 1), sValue)
|
||||||
|
|
||||||
|
x := x + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
editor_map := e_map
|
||||||
|
scrolled_map := s_map
|
||||||
|
notebook.remove_page(page_num)
|
||||||
|
|
||||||
|
notebook.show_all
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Consoles:
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
var outConsole := gtk.text_view
|
||||||
|
var outScroll := gtk.scrolled_window
|
||||||
|
var errorConsole := gtk.text_view
|
||||||
|
var errorScroll := gtk.scrolled_window
|
||||||
|
var errorTag := errorConsole.buffer.create_tag("fixed", "foreground", "red")
|
||||||
|
|
||||||
|
|
||||||
|
// Creates a new output console
|
||||||
|
method createOut {
|
||||||
|
outConsole := gtk.text_view
|
||||||
|
outScroll := gtk.scrolled_window
|
||||||
|
outScroll.add(outConsole)
|
||||||
|
if(out) then {
|
||||||
|
outConsole.set_size_request(400, 400)
|
||||||
|
outScroll.set_size_request(400, 400)
|
||||||
|
} else {
|
||||||
|
outConsole.set_size_request(700, 200)
|
||||||
|
outScroll.set_size_request(700, 200)
|
||||||
|
}
|
||||||
|
outConsole.editable := false
|
||||||
|
outConsole.buffer.set_text("[Output]:", -1)
|
||||||
|
}
|
||||||
|
createOut()
|
||||||
|
|
||||||
|
// Creates a new error console
|
||||||
|
method createError {
|
||||||
|
errorConsole := gtk.text_view
|
||||||
|
errorScroll := gtk.scrolled_window
|
||||||
|
errorScroll.add(errorConsole)
|
||||||
|
if(out) then {
|
||||||
|
errorConsole.set_size_request(400, 400)
|
||||||
|
errorScroll.set_size_request(400, 400)
|
||||||
|
} else {
|
||||||
|
errorConsole.set_size_request(700, 200)
|
||||||
|
errorScroll.set_size_request(700, 200)
|
||||||
|
}
|
||||||
|
errorConsole.editable := false
|
||||||
|
errorConsole.buffer.set_text("[Errors]:", -1)
|
||||||
|
errorTag := errorConsole.buffer.create_tag("fixed", "foreground", "red")
|
||||||
|
}
|
||||||
|
createError()
|
||||||
|
|
||||||
|
// Switches the console being shown to be output. This requires
|
||||||
|
// the output console to be remade as it would have been destroyed when
|
||||||
|
// it was switched previously
|
||||||
|
method switch_to_output {
|
||||||
|
if(currentConsole != "output") then {
|
||||||
|
currentConsole := "output"
|
||||||
|
consoleBox.remove(errorScroll) // This destroys the errorConsole
|
||||||
|
|
||||||
|
createOut()
|
||||||
|
|
||||||
|
consoleBox.add(outScroll)
|
||||||
|
|
||||||
|
populateConsoles()
|
||||||
|
if(out) then {
|
||||||
|
popped.show_all
|
||||||
|
} else {
|
||||||
|
window.show_all
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switches the console being shown to be errors. This requires
|
||||||
|
// the error console to be remade as it would have been destroyed when
|
||||||
|
// it was switched previously
|
||||||
|
method switch_to_errors {
|
||||||
|
if(currentConsole != "errors") then {
|
||||||
|
currentConsole := "errors"
|
||||||
|
consoleBox.remove(outScroll) // This destroys the outConsole
|
||||||
|
|
||||||
|
createError()
|
||||||
|
|
||||||
|
consoleBox.add(errorScroll)
|
||||||
|
|
||||||
|
populateConsoles()
|
||||||
|
if(out) then {
|
||||||
|
popped.show_all
|
||||||
|
} else {
|
||||||
|
window.show_all
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there is text to be put into the consoles this will add it
|
||||||
|
method populateConsoles {
|
||||||
|
if((outText.size > 0) && (currentConsole == "output")) then {
|
||||||
|
outConsole.buffer.set_text(outText, -1)
|
||||||
|
}
|
||||||
|
if((errorText.size > 0) && (currentConsole == "errors")) then {
|
||||||
|
def sIter = gtk.text_iter
|
||||||
|
def eIter = gtk.text_iter
|
||||||
|
|
||||||
|
errorConsole.buffer.set_text(errorText, -1)
|
||||||
|
errorConsole.buffer.get_iter_at_offset(sIter, 0)
|
||||||
|
errorConsole.buffer.get_iter_at_offset(eIter, -1)
|
||||||
|
errorConsole.buffer.apply_tag(errorTag, sIter, eIter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
method clearConsoles {
|
||||||
|
if(currentConsole == "output") then {
|
||||||
|
outConsole.buffer.set_text("[Output]:", -1)
|
||||||
|
outText := ""
|
||||||
|
}
|
||||||
|
if(currentConsole == "errors") then {
|
||||||
|
errorConsole.buffer.set_text("[Errors]:", -1)
|
||||||
|
errorText := ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Identical as the popIn method, but can be connected to the window's destroy button
|
||||||
|
def popInBlock = {
|
||||||
|
consoleBox.reparent(splitPane)
|
||||||
|
popButton.label := "Pop Out"
|
||||||
|
|
||||||
|
if(currentConsole == "output") then {
|
||||||
|
outConsole.set_size_request(700, 200)
|
||||||
|
outScroll.set_size_request(700, 200)
|
||||||
|
}
|
||||||
|
if(currentConsole == "errors") then {
|
||||||
|
errorConsole.set_size_request(700, 200)
|
||||||
|
errorScroll.set_size_request(700, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
def cur_page_num = notebook.current_page
|
||||||
|
def cur_scrolled = scrolled_map.get(cur_page_num)
|
||||||
|
def cur_page = editor_map.get(cur_page_num)
|
||||||
|
|
||||||
|
cur_page.set_size_request(700, 400)
|
||||||
|
cur_scrolled.set_size_request(700, 400)
|
||||||
|
|
||||||
|
out := false
|
||||||
|
popped.visible := false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// This pops the console out into a separate window
|
||||||
|
method popOut {
|
||||||
|
popped := gtk.window(gtk.GTK_WINDOW_TOPLEVEL)
|
||||||
|
|
||||||
|
consoleBox.reparent(popped)
|
||||||
|
popButton.label := "Pop In"
|
||||||
|
|
||||||
|
if(currentConsole == "output") then {
|
||||||
|
outConsole.set_size_request(400, 400)
|
||||||
|
outScroll.set_size_request(400, 400)
|
||||||
|
}
|
||||||
|
if(currentConsole == "errors") then {
|
||||||
|
errorConsole.set_size_request(400, 400)
|
||||||
|
errorScroll.set_size_request(400, 400)
|
||||||
|
}
|
||||||
|
|
||||||
|
def cur_page_num = notebook.current_page
|
||||||
|
def cur_scrolled = scrolled_map.get(cur_page_num)
|
||||||
|
def cur_page = editor_map.get(cur_page_num)
|
||||||
|
|
||||||
|
cur_page.set_size_request(700, 580)
|
||||||
|
cur_scrolled.set_size_request(700, 580)
|
||||||
|
|
||||||
|
out := true
|
||||||
|
popped.visible := true
|
||||||
|
popped.connect("destroy", popInBlock)
|
||||||
|
popped.show_all
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Puts the console back into the main window
|
||||||
|
method popIn {
|
||||||
|
consoleBox.reparent(splitPane)
|
||||||
|
popButton.label := "Pop Out"
|
||||||
|
|
||||||
|
if(currentConsole == "output") then {
|
||||||
|
outConsole.set_size_request(700, 200)
|
||||||
|
outScroll.set_size_request(700, 200)
|
||||||
|
}
|
||||||
|
if(currentConsole == "errors") then {
|
||||||
|
errorConsole.set_size_request(700, 200)
|
||||||
|
errorScroll.set_size_request(700, 200)
|
||||||
|
}
|
||||||
|
|
||||||
|
def cur_page_num = notebook.current_page
|
||||||
|
def cur_scrolled = scrolled_map.get(cur_page_num)
|
||||||
|
def cur_page = editor_map.get(cur_page_num)
|
||||||
|
|
||||||
|
cur_page.set_size_request(700, 400)
|
||||||
|
cur_scrolled.set_size_request(700, 400)
|
||||||
|
|
||||||
|
out := false
|
||||||
|
popped.visible := false
|
||||||
|
}
|
||||||
|
|
||||||
|
clearConsoles()
|
||||||
|
// -------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Patch everything together
|
||||||
|
|
||||||
|
var hSeparator1 := gtk.separator(gtk.GTK_ORIENTATION_HORIZONTAL)
|
||||||
|
var hSeparator2 := gtk.separator(gtk.GTK_ORIENTATION_HORIZONTAL)
|
||||||
|
|
||||||
|
menuBox.add(newButton)
|
||||||
|
menuBox.add(openButton)
|
||||||
|
menuBox.add(saveButton)
|
||||||
|
menuBox.add(saveAsButton)
|
||||||
|
buttonBox.add(runButton)
|
||||||
|
buttonBox.add(closeButton)
|
||||||
|
|
||||||
|
consoleButtons.add(outButton)
|
||||||
|
consoleButtons.add(errorButton)
|
||||||
|
consoleButtons.add(clearButton)
|
||||||
|
consoleButtons.add(popButton)
|
||||||
|
|
||||||
|
consoleBox.add(hSeparator1)
|
||||||
|
consoleBox.add(consoleButtons)
|
||||||
|
consoleBox.add(outScroll)
|
||||||
|
|
||||||
|
editorBox.add(hSeparator2)
|
||||||
|
notebook.add(scrolled_main)
|
||||||
|
notebook.set_tab_label_text(scrolled_main, "Untitled.grace")
|
||||||
|
editorBox.add(notebook)
|
||||||
|
|
||||||
|
splitPane.add1(editorBox)
|
||||||
|
splitPane.add2(consoleBox)
|
||||||
|
|
||||||
|
mBox.add(menuBox)
|
||||||
|
mBox.add(buttonBox)
|
||||||
|
mBox.add(splitPane)
|
||||||
|
|
||||||
|
window.add(mBox)
|
||||||
|
|
||||||
|
def exit = {
|
||||||
|
var x := 0
|
||||||
|
while {x < notebook.n_pages} do {
|
||||||
|
deleteCompileFiles(x)
|
||||||
|
|
||||||
|
x := x + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the compile files of the IDE
|
||||||
|
io.system("rm -f Grace_IDE.gct Grace_IDE.c Grace_IDE.gcn")
|
||||||
|
io.system("rm -f scanner.gct scanner.c scanner.gcn")
|
||||||
|
io.system("rm -f syntax_highlighter.gct syntax_highlighter.c syntax_highlighter.gcn")
|
||||||
|
io.system("rm -f syntax_colors.gct syntax_colors.c syntax_colors.gcn")
|
||||||
|
io.system("rm -f button_factory.gct button_factory.c button_factory.gcn")
|
||||||
|
io.system("rm -f dialog_factory.gct dialog_factory.c dialog_factory.gcn")
|
||||||
|
io.system("rm -f auto_completer.gct auto_completer.c auto_completer.gcn")
|
||||||
|
|
||||||
|
print "Grace IDE Closed Successfully"
|
||||||
|
gtk.main_quit
|
||||||
|
}
|
||||||
|
|
||||||
|
window.connect("destroy", exit)
|
||||||
|
window.show_all
|
||||||
|
|
||||||
|
gtk.main
|
||||||
@@ -277,6 +277,10 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
|
|
||||||
# 'thirdparty' directory
|
# 'thirdparty' directory
|
||||||
assert blob("thirdparty/lib/main.c").vendored?
|
assert blob("thirdparty/lib/main.c").vendored?
|
||||||
|
|
||||||
|
# 'extern(al)' directory
|
||||||
|
assert blob("extern/util/__init__.py").vendored?
|
||||||
|
assert blob("external/jquery.min.js").vendored?
|
||||||
|
|
||||||
# C deps
|
# C deps
|
||||||
assert blob("deps/http_parser/http_parser.c").vendored?
|
assert blob("deps/http_parser/http_parser.c").vendored?
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
require 'linguist/heuristics'
|
require 'linguist/heuristics'
|
||||||
require 'linguist/language'
|
require 'linguist/language'
|
||||||
require 'linguist/samples'
|
require 'linguist/samples'
|
||||||
|
require 'linguist/file_blob'
|
||||||
|
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
@@ -35,7 +36,8 @@ class TestHeuristcs < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_detect_still_works_if_nothing_matches
|
def test_detect_still_works_if_nothing_matches
|
||||||
match = Language.detect("Hello.m", fixture("Objective-C/hello.m"))
|
blob = Linguist::FileBlob.new(File.join(samples_path, "Objective-C/hello.m"))
|
||||||
|
match = Language.detect(blob)
|
||||||
assert_equal Language["Objective-C"], match
|
assert_equal Language["Objective-C"], match
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,22 +3,24 @@ require 'linguist/repository'
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
class TestRepository < Test::Unit::TestCase
|
class TestRepository < Test::Unit::TestCase
|
||||||
include Linguist
|
def rugged_repository
|
||||||
|
@rugged ||= Rugged::Repository.new(File.expand_path("../../.git", __FILE__))
|
||||||
def repo(base_path)
|
|
||||||
Repository.from_directory(base_path)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def linguist_repo
|
def master_oid
|
||||||
repo(File.expand_path("../..", __FILE__))
|
'd40b4a33deba710e2f494db357c654fbe5d4b419'
|
||||||
|
end
|
||||||
|
|
||||||
|
def linguist_repo(oid = master_oid)
|
||||||
|
Linguist::Repository.new(rugged_repository, oid)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_linguist_language
|
def test_linguist_language
|
||||||
# assert_equal Language['Ruby'], linguist_repo.language
|
assert_equal 'Ruby', linguist_repo.language
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_linguist_languages
|
def test_linguist_languages
|
||||||
# assert linguist_repo.languages[Language['Ruby']] > 10_000
|
assert linguist_repo.languages['Ruby'] > 10_000
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_linguist_size
|
def test_linguist_size
|
||||||
@@ -31,7 +33,18 @@ class TestRepository < Test::Unit::TestCase
|
|||||||
assert linguist_repo.breakdown_by_file["Ruby"].include?("lib/linguist/language.rb")
|
assert linguist_repo.breakdown_by_file["Ruby"].include?("lib/linguist/language.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_binary_override
|
def test_incremental_stats
|
||||||
assert_equal repo(File.expand_path("../../samples/Nimrod", __FILE__)).language, Language["Nimrod"]
|
old_commit = '3d7364877d6794f6cc2a86b493e893968a597332'
|
||||||
|
old_repo = linguist_repo(old_commit)
|
||||||
|
|
||||||
|
assert old_repo.languages['Ruby'] > 10_000
|
||||||
|
assert old_repo.size > 30_000
|
||||||
|
|
||||||
|
new_repo = Linguist::Repository.incremental(rugged_repository, master_oid, old_commit, old_repo.cache)
|
||||||
|
|
||||||
|
assert new_repo.languages['Ruby'] > old_repo.languages['Ruby']
|
||||||
|
assert new_repo.size > old_repo.size
|
||||||
|
|
||||||
|
assert_equal linguist_repo.cache, new_repo.cache
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user