diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index b7c892743..000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "test/twitter-text-conformance"] - path = test/twitter-text-conformance - url = https://github.com/twitter/twitter-text-conformance.git diff --git a/.travis.sh b/.travis.sh index c1eee0df3..97a3f290c 100755 --- a/.travis.sh +++ b/.travis.sh @@ -18,4 +18,7 @@ case $TWITTER_TEXT_DIR in rake test:conformance:prepare grunt qunit && node test/node_tests.js ;; + objc) + rake + ;; esac diff --git a/.travis.yml b/.travis.yml index df859032f..e90bd861b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/java/Rakefile b/java/Rakefile index 91468b002..63830de3d 100644 --- a/java/Rakefile +++ b/java/Rakefile @@ -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" diff --git a/js/Rakefile b/js/Rakefile index b6b950d50..629619513 100644 --- a/js/Rakefile +++ b/js/Rakefile @@ -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" diff --git a/.gitignore b/objc/.gitignore similarity index 100% rename from .gitignore rename to objc/.gitignore diff --git a/objc/Rakefile b/objc/Rakefile index 251d467c2..9c6b30d9a 100644 --- a/objc/Rakefile +++ b/objc/Rakefile @@ -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" @@ -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 diff --git a/objc/test/json-conformance/extract.json b/objc/test/json-conformance/extract.json index 70e45903f..d90394b88 100644 --- a/objc/test/json-conformance/extract.json +++ b/objc/test/json-conformance/extract.json @@ -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",