<commit_before>//
//  TKShareHelperTest.swift
//  TripKit
//
//  Created by <NAME> on 29/08/2016.
//  Copyright © 2016 SkedGo. All rights reserved.
//

import XCTest

import RxBlocking

@testable import TripKit

class TKShareHelperTest: XCTestCase {
  
  let geocoder: SGBuzzGeocoder? = {
    let env = ProcessInfo.processInfo.environment
    if let apiKey = env["TRIPGO_API_KEY"], !apiKey.isEmpty {
      TripKit.apiKey = apiKey
      return SGBuzzGeocoder()
    } else {
      return nil
    }
  }()
  
  func testQueryUrlWithW3W() throws {
    guard let geocoder = geocoder else {
      XCTFail("Could not construct SGBuzzGeocoder. Check environment variables.")
      return
    }

    let url = URL(string: "tripgo:///go?tname=dragon.letter.spoke")!
    
    guard let result = try TKShareHelper.queryDetails(for: url, using: geocoder).toBlocking().first() else { XCTFail(); return }
    
    XCTAssertNil(result.start)
    XCTAssertTrue(result.end.isValid)
    XCTAssertEqual(result.title, "dragon.letter.spoke")
    if case .leaveASAP = result.timeType {
      XCTAssertTrue(true)
    } else {
      XCTFail()
    }
    
  }

  func testW3WQueryUrlWithLatLng() throws {
    let geocoder = SGAppleGeocoder()
    let url = URL(string: "tripgo:///go?tlat=-33.94501&tlng=151.25807&type=1&time=1385535734")!
    
    guard let result = try TKShareHelper.queryDetails(for: url, using: geocoder).toBlocking().first() else { XCTFail(); return }
    
    XCTAssertNil(result.start)
    XCTAssertTrue(result.end.isValid)
    XCTAssertNil(result.title)
    XCTAssertEqual(result.end.latitude,  -33.94501, accuracy: 0.001)
    XCTAssertEqual(result.end.longitude, 151.25807, accuracy: 0.001)
    if case .leaveAfter(let time) = result.timeType {
      XCTAssertEqual(time.timeIntervalSince1970, 1385535734, accuracy: 1)
    } else {
      XCTFail()
    }
  }
  <commit_msg>Crash to get more test failure details<commit_after>//
//  TKShareHelperTest.swift
//  TripKit
//
//  Created by <NAME> on 29/08/2016.
//  Copyright © 2016 SkedGo. All rights reserved.
//

import XCTest

import RxBlocking

@testable import TripKit

class TKShareHelperTest: XCTestCase {
  
  let geocoder: SGBuzzGeocoder? = {
    let env = ProcessInfo.processInfo.environment
    if let apiKey = env["TRIPGO_API_KEY"], !apiKey.isEmpty {
      TripKit.apiKey = apiKey
      return SGBuzzGeocoder()
    } else {
      return nil
    }
  }()
  
  func testQueryUrlWithW3W() throws {
    guard let geocoder = geocoder else {
      XCTFail("Could not construct SGBuzzGeocoder. Check environment variables.")
      return
    }

    let url = URL(string: "tripgo:///go?tname=dragon.letter.spoke")!
    
    guard let result = try! TKShareHelper.queryDetails(for: url, using: geocoder).toBlocking().first() else { XCTFail(); return }
    
    XCTAssertNil(result.start)
    XCTAssertTrue(result.end.isValid)
    XCTAssertEqual(result.title, "dragon.letter.spoke")
    if case .leaveASAP = result.timeType {
      XCTAssertTrue(true)
    } else {
      XCTFail()
    }
    
  }

  func testW3WQueryUrlWithLatLng() throws {
    let geocoder = SGAppleGeocoder()
    let url = URL(string: "tripgo:///go?tlat=-33.94501&tlng=151.25807&type=1&time=1385535734")!
    
    guard let result = try TKShareHelper.queryDetails(for: url, using: geocoder).toBlocking().first() else { XCTFail(); return }
    
    XCTAssertNil(result.start)
    XCTAssertTrue(result.end.isValid)
    XCTAssertNil(result.title)
    XCTAssertEqual(result.end.latitude,  -33.94501, accuracy: 0.001)
    XCTAssertEqual(result.end.longitude, 151.25807, accuracy: 0.001)
    if case .leaveAfter(let time) = result.timeType {
      XCTAssertEqual(time.timeIntervalSince1970, 1385535734, accuracy: 1)
    } else {
      XCTFail()
    }
  }
  
{'fraction_non_alphanumeric': 0.11722488038277512, 'fraction_numerical': 0.04146730462519936, 'mean_word_length': 3.1672203765227023, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5390540', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1324, 'n_words': 262}