Skip to content

Commit

Permalink
objc travis support
Browse files Browse the repository at this point in the history
  • Loading branch information
jakl committed Dec 4, 2014
1 parent 200efe1 commit 1a76ce5
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 98 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

3 changes: 3 additions & 0 deletions .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ case $TWITTER_TEXT_DIR in
rake test:conformance:prepare
grunt qunit && node test/node_tests.js
;;
objc)
rake
;;
esac
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
language: ruby
language: objective-c
matrix:
include:
- env: TWITTER_TEXT_DIR=rb
rvm: 1.8.7
- env: TWITTER_TEXT_DIR=rb
rvm: 1.9.3
- env: TWITTER_TEXT_DIR=rb
rvm: 2.0.0
- env: TWITTER_TEXT_DIR=rb
rvm: 2.1.1
rvm: 2.1.3
- env: TWITTER_TEXT_DIR=java
- env: TWITTER_TEXT_DIR=js
- env: TWITTER_TEXT_DIR=objc
script: "./.travis.sh"
5 changes: 0 additions & 5 deletions java/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ require 'yaml'
require 'json'
require 'date'

def conformance_version(dir)
require 'digest'
Dir[File.join(dir, '*')].inject(Digest::SHA1.new){|digest, file| digest.update(Digest::SHA1.file(file).hexdigest) }
end

namespace :test do
namespace :conformance do
desc "Run conformance test suite"
Expand Down
4 changes: 0 additions & 4 deletions js/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ require 'json'
require 'date'
require 'digest'

def conformance_version(dir)
Dir[File.join(dir, '*')].inject(Digest::SHA1.new){|digest, file| digest.update(Digest::SHA1.file(file).hexdigest) }
end

namespace :test do
namespace :conformance do
desc "Prepare JS conformance test suite"
Expand Down
File renamed without changes.
122 changes: 61 additions & 61 deletions objc/Rakefile
Original file line number Diff line number Diff line change
@@ -1,71 +1,46 @@
task :default => ['test:conformance']
task :clean => ['test:clean']

def conformance_version(dir)
require 'digest'
Dir[File.join(dir, '*')].inject(Digest::SHA1.new){|digest, file| digest.update(Digest::SHA1.file(file).hexdigest) }
end

def format_tlds(tlds, max_length = 100)
tlds_group = tlds.each_with_object([[]]) do |tld, o|
if (o.last + [tld]).join('|').size > max_length
o << []
end
o.last << tld
end
tlds_group.map do |tlds|
" @\"" + tlds.join('|') + "|\" \\\n"
end.join('').sub(/\|[^|]*\Z/) {|m| m[1..-1]}.sub(/\n\Z/, '')
end
require 'yaml'
require 'rubygems'
require 'json'
require 'fileutils'

def replace_tlds(source_code, name, tlds)
source_code.sub(/#{Regexp.quote('#define ' + name)}.*?#{Regexp.quote('@")"')}\n/m, <<-D)
#define #{name} \\
@"(?:" \\
#{tlds}
@")"
D
end
task :default => ['test:conformance:run']
task :clean => ['test:clean']

namespace :test do
namespace :conformance do
desc "Update conformance testing data"
task :update do
puts "Updating conformance data ... "
system("git submodule init") || raise("Failed to init submodule")
system("git submodule update") || raise("Failed to update submodule")
puts "Updating conformance data ... DONE"
end

desc "Change conformance test data to the lastest version"
task :latest => [:update] do
current_dir = File.dirname(__FILE__)
submodule_dir = File.join(File.dirname(__FILE__), "test", "twitter-text-conformance")
version_before = conformance_version(submodule_dir)
system("cd #{submodule_dir} && git pull origin master") || raise("Failed to pull submodule version")
system("cd #{current_dir}")
if conformance_version(submodule_dir) != version_before
system("cd #{current_dir} && git add #{submodule_dir}") || raise("Failed to add upgrade files")
system("git commit -m \"Upgraded to the latest conformance suite\" #{submodule_dir}") || raise("Failed to commit upgraded conformacne data")
puts "Upgraded conformance suite."
else
puts "No conformance suite changes."
end
desc "Objective-C conformance test suite"
task :run => [:convert_tests] do
system("xctool test -scheme TwitterTextTests -project testproject/TwitterText.xcodeproj")
end

desc "Convert testing data from YAML to JSON"
task :convert_tests do
system("cd test/ && ruby convert_tests.rb")
end
INPUT_PATH = repo_path('../conformance/')
OUTPUT_PATH = repo_path('test/json-conformance/')

desc "Objective-C conformance test suite"
task :run => [:convert_tests] do
system("cd testproject/ && xcodebuild test -scheme TwitterTextTests")
end
end
FILES = [
'extract.yml',
'validate.yml',
'tlds.yml',
]

FILES.each do |filename|
filename = INPUT_PATH + filename
content = YAML.load(File.open(filename).read)
s = JSON.pretty_generate(content)

desc "Run conformance test suite"
task :conformance => ['conformance:latest', 'conformance:run'] do
output_filename = File.basename(filename)
output_filename.gsub!(/\.[a-zA-Z0-9]+$/, '');
output_filename += '.json'

FileUtils.mkdir_p(OUTPUT_PATH)

File.open(OUTPUT_PATH + output_filename, 'w') do |f|
f.truncate(0)
f.write(s)
end
end
end
end

desc "Clean build and tests"
Expand All @@ -78,13 +53,38 @@ end
desc "Update TLDs"
task :update_tlds do
require 'yaml'
tlds = YAML.load_file('test/twitter-text-conformance/tld_lib.yml')
tlds = YAML.load_file(repo_path('../conformance/tld_lib.yml'))
cctlds = format_tlds(tlds["country"])
gtlds = format_tlds(tlds["generic"])
twitter_text_m = File.read('lib/TwitterText.m')
twitter_text_m = File.read(repo_path('lib/TwitterText.m'))
twitter_text_m = replace_tlds(twitter_text_m, 'TWUValidCCTLD', cctlds)
twitter_text_m = replace_tlds(twitter_text_m, 'TWUValidGTLD', gtlds)
File.open('lib/TwitterText.m', 'w') do |file|
File.open(repo_path('lib/TwitterText.m'), 'w') do |file|
file.write twitter_text_m
end
end

def repo_path(*path)
File.join(File.dirname(__FILE__), *path)
end

def format_tlds(tlds, max_length = 100)
tlds_group = tlds.each_with_object([[]]) do |tld, o|
if (o.last + [tld]).join('|').size > max_length
o << []
end
o.last << tld
end
tlds_group.map do |tlds|
" @\"" + tlds.join('|') + "|\" \\\n"
end.join('').sub(/\|[^|]*\Z/) {|m| m[1..-1]}.sub(/\n\Z/, '')
end

def replace_tlds(source_code, name, tlds)
source_code.sub(/#{Regexp.quote('#define ' + name)}.*?#{Regexp.quote('@")"')}\n/m, <<-D)
#define #{name} \\
@"(?:" \\
#{tlds}
@")"
D
end
21 changes: 0 additions & 21 deletions objc/test/json-conformance/extract.json
Original file line number Diff line number Diff line change
Expand Up @@ -804,27 +804,6 @@
"http://twitter.com/"
]
},
{
"description": "DO NOT extract URL with leading hyphen inside CJK text",
"text": "ル-twpf.jpル",
"expected": [

]
},
{
"description": "DO NOT extract URLs without protocol with a trailing dash in the domain regardless of CJK and path",
"text": "tw-.com t-.co tw-.com/home t-.co/home ルtw-.comルt-.coルtw-.com/homeルt-.co/homeル",
"expected": [

]
},
{
"description": "Extract URL with interior hyphen, subdomain, and numbers",
"text": "www.123-hyphenated-url.com",
"expected": [
"www.123-hyphenated-url.com"
]
},
{
"description": "Extract a URL with '?' in fragment",
"text": "http://tn.com.ar/show/00056158/la-estrella-del-certamen-el-turno-de-pamela-anderson?fb_xd_fragment#?=&cb=fe17523f223b7&relation=parent.parent&transport=fragment&type=resize&height=20&ackdata",
Expand Down

0 comments on commit 1a76ce5

Please sign in to comment.