How to use with class

Best Mockingbird code snippet using with

JSONKey.swift

Source:JSONKey.swift Github

copy

Full Screen

...4// Copyright (c) 2015-2016 Damien (http://delba.io)5//6// Permission is hereby granted, free of charge, to any person obtaining a copy7// of this software and associated documentation files (the "Software"), to deal8// in the Software without restriction, including without limitation the rights9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10// copies of the Software, and to permit persons to whom the Software is11// furnished to do so, subject to the following conditions:12//13// The above copyright notice and this permission notice shall be included in all14// copies or substantial portions of the Software.15//16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE22// SOFTWARE.23//24// MARK: - JSONKey25private enum KeyType {26    case String(Swift.String)27    case Int(Swift.Int)28    case Path([Any])29}30public class JSONKeys {31    private init() {}32}33public class JSONKey<ValueType>: JSONKeys {34    private let type: KeyType35    36    /**37     Creates a new instance of JSONKey.38     39     - parameter key: A string.40     41     - returns: A new instance of JSONKey.42     */43    public init(_ key: String) {44        self.type = .String(key)45    }46    47    /**48     Creates a new instance of JSONKey.49     50     - parameter key: An integer.51     52     - returns: A new instance of JSONKey.53     */54    public init(_ key: Int) {55        self.type = .Int(key)56    }57    58    /**59     Creates a new instance of JSONKey.60     61     - parameter key: Any62     63     - returns: A new instance of JSONKey.64     */65    public init(path indexes: Any...) {66        self.type = .Path(indexes)67    }68}69private extension JSON {70    subscript(type: KeyType) -> JSON {71        switch type {72        case .String(let key): return self[key]73        case .Int(let key): return self[key]74        case .Path(let indexes): return self[indexes]75        }76    }77}78// MARK: - JSON79extension JSON {80    /**81     Returns the value associated with the given key as JSON.82     83     - parameter key: The key.84     85     - returns: The value associated with the given key as JSON.86     */87    public subscript(key: JSONKey<JSON>) -> JSON {88        return self[key.type]89    }90}91// MARK: - String92extension JSON {93    /**94     Returns the value associated with the given key as a string or nil if not present/convertible.95     96     - parameter key: The key.97     98     - returns: The value associated with the given key as a string or nil if not present/convertible.99     */100    public subscript(key: JSONKey<String?>) -> String? {101        return self[key.type].string102    }103    104    /**105     Returns the value associated with the given key as a string or "" if not present/convertible.106     107     - parameter key: The key.108     109     - returns: The value associated with the given key as a string or "" if not present/convertible.110     */111    public subscript(key: JSONKey<String>) -> String {112        return self[key.type].stringValue113    }114}115// MARK: - Integer116extension JSON {117    /**118     Returns the value associated with the given key as a 64-bit signed integer or nil if not present/convertible.119     120     - parameter key: The key.121     122     - returns: The value associated with the given key as a 64-bit signed integer or nil if not present/convertible.123     */124    public subscript(key: JSONKey<Int?>) -> Int? {125        return self[key.type].int126    }127    128    /**129     Returns the value associated with the given key as a 64-bit signed integer or 0 if not present/convertible.130     131     - parameter key: The key.132     133     - returns: The value associated with the given key as a 64-bit signed integer or 0 if not present/convertible.134     */135    public subscript(key: JSONKey<Int>) -> Int {136        return self[key.type].intValue137    }138}139// MARK: - FloatingPointType140extension JSON {141    /**142     Returns the value associated with the given key as a 64-bit floating-point number or nil if not present/convertible.143     144     - parameter key: The key.145     146     - returns: The value associated with the given key as a 64-bit floating-point number or nil if not present/convertible.147     */148    public subscript(key: JSONKey<Double?>) -> Double? {149        return self[key.type].double150    }151    152    /**153     Returns the value associated with the given key as a 64-bit floating-point number or 0.0 if not present/convertible.154     155     - parameter key: The key.156     157     - returns: The value associated with the given key as a 64-bit floating-point number or 0.0 if not present/convertible.158     */159    public subscript(key: JSONKey<Double>) -> Double {160        return self[key.type].doubleValue161    }162    163    /**164     Returns the value associated with the given key as a 32-bit floating-point number or nil if not present/convertible.165     166     - parameter key: The key.167     168     - returns: The value associated with the given key as a 32-bit floating-point number or nil if not present/convertible.169     */170    public subscript(key: JSONKey<Float?>) -> Float? {171        return self[key.type].float172    }173    174    /**175     Returns the value associated with the given key as a 32-bit floating-point number or 0.0 if not present/convertible.176     177     - parameter key: The key.178     179     - returns: The value associated with the given key as a 32-bit floating-point number or 0.0 if not present/convertible.180     */181    public subscript(key: JSONKey<Float>) -> Float {182        return self[key.type].floatValue183    }184    185    /**186     Returns the value associated with the given key as a NSNumber or nil if not present/convertible.187     188     - parameter key: The key.189     190     - returns: The value associated with the given key as a NSNumber or nil if not present/convertible.191     */192    public subscript(key: JSONKey<NSNumber?>) -> NSNumber? {193        return self[key.type].nsNumber194    }195    196    /**197     Returns the value associated with the given key as a NSNumber or 0 if not present/convertible.198     199     - parameter key: The key.200     201     - returns: The value associated with the given key as a NSNumber or 0 if not present/convertible.202     */203    public subscript(key: JSONKey<NSNumber>) -> NSNumber {204        return self[key.type].nsNumberValue205    }206    207    /**208     Returns the value associated with the given key as a CGFloat or nil if not present/convertible.209     210     - parameter key: The key.211     212     - returns: The value associated with the given key as a CGFloat or nil if not present/convertible.213     */214    public subscript(key: JSONKey<CGFloat?>) -> CGFloat? {215        return self[key.type].cgFloat216    }217    218    /**219     Returns the value associated with the given key as a CGFloat or 0.0 if not present/convertible.220     221     - parameter key: The key.222     223     - returns: The value associated with the given key as a CGFloat or 0.0 if not present/convertible.224     */225    public subscript(key: JSONKey<CGFloat>) -> CGFloat {226        return self[key.type].cgFloatValue227    }228}229// MARK: - Bool230extension JSON {231    /**232     Returns the value associated with the given key as a Bool or nil if not present/convertible.233     234     - parameter key: The key.235     236     - returns: The value associated with the given key as a Bool or nil if not present/convertible.237     */238    public subscript(key: JSONKey<Bool?>) -> Bool? {239        return self[key.type].bool240    }241    242    /**243     Returns the value associated with the given key as a Bool or false if not present/convertible.244     245     - parameter key: The key.246     247     - returns: The value associated with the given key as a Bool or false if not present/convertible.248     */249    public subscript(key: JSONKey<Bool>) -> Bool {250        return self[key.type].boolValue251    }252}253// MARK: - NSDate254extension JSON {255    /**256     Returns the value associated with the given key as a NSDate or nil if not present/convertible.257     258     - parameter key: The key.259     260     - returns: The value associated with the given key as a NSDate or nil if not present/convertible.261     */262    public subscript(key: JSONKey<NSDate?>) -> NSDate? {263        return self[key.type].nsDate264    }265}266// MARK: - NSURL267extension JSON {268    /**269     Returns the value associated with the given key as a NSURL or nil if not present/convertible.270     271     - parameter key: The key.272     273     - returns: The value associated with the given key as a NSURL or nil if not present/convertible.274     */275    public subscript(key: JSONKey<NSURL?>) -> NSURL? {276        return self[key.type].nsURL277    }278}279// MARK: - Dictionary280extension JSON {281    /**282     Returns the value associated with the given key as a dictionary or nil if not present/convertible.283     284     - parameter key: The key.285     286     - returns: The value associated with the given key as a dictionary or nil if not present/convertible.287     */288    public subscript(key: JSONKey<[String: AnyObject]?>) -> [String: AnyObject]? {289        return self[key.type].dictionary290    }291    292    /**293     Returns the value associated with the given key as a dictionary or an empty dictionary if not present/convertible.294     295     - parameter key: The key.296     297     - returns: The value associated with the given key as a dictionary or an empty dictionary if not present/convertible.298     */299    public subscript(key: JSONKey<[String: AnyObject]>) -> [String: AnyObject] {300        return self[key.type].dictionaryValue301    }302    303    /**304     Returns the value associated with the given key as a dictionary or nil if not present/convertible.305     306     - parameter key: The key.307     308     - returns: The value associated with the given key as a dictionary or nil if not present/convertible.309     */310    public subscript(key: JSONKey<[String: JSON]?>) -> [String: JSON]? {311        return self[key.type].jsonDictionary312    }313    314    /**315     Returns the value associated with the given key as a dictionary or an empty dictionary if not present/convertible.316     317     - parameter key: The key.318     319     - returns: The value associated with the given key as a dictionary or an empty dictionary if not present/convertible.320     */321    public subscript(key: JSONKey<[String: JSON]>) -> [String: JSON] {322        return self[key.type].jsonDictionaryValue323    }324    /**325     Returns the value associated with the given key as a dictionary or nil if not present/convertible.326     327     - parameter key: The key.328     329     - returns: The value associated with the given key as a dictionary or nil if not present/convertible.330     */331    public subscript(key: JSONKey<NSDictionary?>) -> NSDictionary? {332        return self[key.type].nsDictionary333    }334    335    /**336     Returns the value associated with the given key as a NSDictionary or an empty NSDictionary if not present/convertible.337     338     - parameter key: The key.339     340     - returns: The value associated with the given key as a NSDictionary or an empty NSDictionary if not present/convertible.341     */342    public subscript(key: JSONKey<NSDictionary>) -> NSDictionary {343        return self[key.type].nsDictionaryValue344    }345}346// MARK: - Array347extension JSON {348    /**349     Returns the value associated with the given key as an array or nil if not present/convertible.350     351     - parameter key: The key.352     353     - returns: The value associated with the given key as an array or nil if not present/convertible.354     */355    public subscript(key: JSONKey<[AnyObject]?>) -> [AnyObject]? {356        return self[key.type].array357    }358    359    /**360     Returns the value associated with the given key as an array or an empty array if not present/convertible.361     362     - parameter key: The key.363     364     - returns: The value associated with the given key as an array or an empty array if not present/convertible.365     */366    public subscript(key: JSONKey<[AnyObject]>) -> [AnyObject] {367        return self[key.type].arrayValue368    }369    370    /**371     Returns the value associated with the given key as an array or nil if not present/convertible.372     373     - parameter key: The key.374     375     - returns: The value associated with the given key as an array or nil if not present/convertible.376     */377    public subscript(key: JSONKey<[JSON]?>) -> [JSON]? {378        return self[key.type].jsonArray379    }380    381    /**382     Returns the value associated with the given key as an array or an empty array if not present/convertible.383     384     - parameter key: The key.385     386     - returns: The value associated with the given key as an array or an empty array if not present/convertible.387     */388    public subscript(key: JSONKey<[JSON]>) -> [JSON] {389        return self[key.type].jsonArrayValue390    }391    392    /**393     Returns the value associated with the given key as a NSArray or nil if not present/convertible.394     395     - parameter key: The key.396     397     - returns: The value associated with the given key as a NSArray or nil if not present/convertible.398     */399    public subscript(key: JSONKey<NSArray?>) -> NSArray? {400        return self[key.type].nsArray401    }402    403    /**404     Returns the value associated with the given key as a NSArray or an empty NSArray if not present/convertible.405     406     - parameter key: The key.407     408     - returns: The value associated with the given key as a NSArray or an empty NSArray if not present/convertible.409     */410    public subscript(key: JSONKey<NSArray>) -> NSArray {411        return self[key.type].nsArrayValue412    }413}...

Full Screen

Full Screen

fgets_variation4-win32-mb.phpt

Source:fgets_variation4-win32-mb.phpt Github

copy

Full Screen

...12include ("file.inc");13$file_modes = array("w+", "w+b", "w+t",14                    "a+", "a+b", "a+t",15                    "x+", "x+b", "x+t");16$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");17echo "*** Testing fgets() : usage variations ***\n";18$filename = __DIR__."/fgets_variation4私はガラスを食べられます.tmp";19foreach($file_modes as $file_mode) {20  echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";21  foreach($file_content_types as $file_content_type) {22    echo "-- File content type : $file_content_type --\n";23    /* create files with $file_content_type */24    $file_handle = fopen($filename, $file_mode);25    $data = fill_file($file_handle, $file_content_type, 50);26    if ( !$file_handle ) {27      echo "Error: failed to open file $filename!";28      exit();29    }30    echo "-- fgets() with location set by fseek() with default length --\n";31    var_dump( fseek($file_handle, 5, SEEK_SET) );32    var_dump( ftell($file_handle) );33    var_dump( fgets($file_handle ) );34    var_dump( ftell($file_handle) ); // ensure the file pointer position35    var_dump( feof($file_handle) );  // ensure if eof set36    echo "-- fgets() with location set by fseek() with length = 20 --\n";37    var_dump( fseek($file_handle, 25, SEEK_SET) );38    var_dump( ftell($file_handle) );39    var_dump( fgets($file_handle, 20 ) ); // expected 19 chars40    var_dump( ftell($file_handle) ); // ensure the file pointer position41    var_dump( feof($file_handle) );  // ensure if eof set42    //close file43    fclose($file_handle);44    // delete file45    delete_file($filename);46  } // file_content_type loop47} // file_mode loop48echo "Done\n";49?>50--EXPECT--51*** Testing fgets() : usage variations ***52-- Testing fgets() with file opened using mode w+ --53-- File content type : numeric --54-- fgets() with location set by fseek() with default length --55int(0)56int(5)57string(45) "222222222222222222222222222222222222222222222"58int(50)59bool(true)60-- fgets() with location set by fseek() with length = 20 --61int(0)62int(25)63string(19) "2222222222222222222"64int(44)65bool(false)66-- File content type : text --67-- fgets() with location set by fseek() with default length --68int(0)69int(5)70string(45) "text text text text text text text text text "71int(50)72bool(true)73-- fgets() with location set by fseek() with length = 20 --74int(0)75int(25)76string(19) "text text text text"77int(44)78bool(false)79-- File content type : text_with_new_line --80-- fgets() with location set by fseek() with default length --81int(0)82int(5)83string(13) "line of text84"85int(18)86bool(false)87-- fgets() with location set by fseek() with length = 20 --88int(0)89int(25)90string(11) "ne of text91"92int(36)93bool(false)94-- File content type : alphanumeric --95-- fgets() with location set by fseek() with default length --96int(0)97int(5)98string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "99int(50)100bool(true)101-- fgets() with location set by fseek() with length = 20 --102int(0)103int(25)104string(19) "ab12 ab12 ab12 ab12"105int(44)106bool(false)107-- Testing fgets() with file opened using mode w+b --108-- File content type : numeric --109-- fgets() with location set by fseek() with default length --110int(0)111int(5)112string(45) "222222222222222222222222222222222222222222222"113int(50)114bool(true)115-- fgets() with location set by fseek() with length = 20 --116int(0)117int(25)118string(19) "2222222222222222222"119int(44)120bool(false)121-- File content type : text --122-- fgets() with location set by fseek() with default length --123int(0)124int(5)125string(45) "text text text text text text text text text "126int(50)127bool(true)128-- fgets() with location set by fseek() with length = 20 --129int(0)130int(25)131string(19) "text text text text"132int(44)133bool(false)134-- File content type : text_with_new_line --135-- fgets() with location set by fseek() with default length --136int(0)137int(5)138string(13) "line of text139"140int(18)141bool(false)142-- fgets() with location set by fseek() with length = 20 --143int(0)144int(25)145string(11) "ne of text146"147int(36)148bool(false)149-- File content type : alphanumeric --150-- fgets() with location set by fseek() with default length --151int(0)152int(5)153string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "154int(50)155bool(true)156-- fgets() with location set by fseek() with length = 20 --157int(0)158int(25)159string(19) "ab12 ab12 ab12 ab12"160int(44)161bool(false)162-- Testing fgets() with file opened using mode w+t --163-- File content type : numeric --164-- fgets() with location set by fseek() with default length --165int(0)166int(5)167string(45) "222222222222222222222222222222222222222222222"168int(50)169bool(true)170-- fgets() with location set by fseek() with length = 20 --171int(0)172int(25)173string(19) "2222222222222222222"174int(44)175bool(false)176-- File content type : text --177-- fgets() with location set by fseek() with default length --178int(0)179int(5)180string(45) "text text text text text text text text text "181int(50)182bool(true)183-- fgets() with location set by fseek() with length = 20 --184int(0)185int(25)186string(19) "text text text text"187int(44)188bool(false)189-- File content type : text_with_new_line --190-- fgets() with location set by fseek() with default length --191int(0)192int(5)193string(1) "194"195int(6)196bool(false)197-- fgets() with location set by fseek() with length = 20 --198int(0)199int(25)200string(12) "ine of text201"202int(37)203bool(false)204-- File content type : alphanumeric --205-- fgets() with location set by fseek() with default length --206int(0)207int(5)208string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "209int(50)210bool(true)211-- fgets() with location set by fseek() with length = 20 --212int(0)213int(25)214string(19) "ab12 ab12 ab12 ab12"215int(44)216bool(false)217-- Testing fgets() with file opened using mode a+ --218-- File content type : numeric --219-- fgets() with location set by fseek() with default length --220int(0)221int(5)222string(45) "222222222222222222222222222222222222222222222"223int(50)224bool(true)225-- fgets() with location set by fseek() with length = 20 --226int(0)227int(25)228string(19) "2222222222222222222"229int(44)230bool(false)231-- File content type : text --232-- fgets() with location set by fseek() with default length --233int(0)234int(5)235string(45) "text text text text text text text text text "236int(50)237bool(true)238-- fgets() with location set by fseek() with length = 20 --239int(0)240int(25)241string(19) "text text text text"242int(44)243bool(false)244-- File content type : text_with_new_line --245-- fgets() with location set by fseek() with default length --246int(0)247int(5)248string(13) "line of text249"250int(18)251bool(false)252-- fgets() with location set by fseek() with length = 20 --253int(0)254int(25)255string(11) "ne of text256"257int(36)258bool(false)259-- File content type : alphanumeric --260-- fgets() with location set by fseek() with default length --261int(0)262int(5)263string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "264int(50)265bool(true)266-- fgets() with location set by fseek() with length = 20 --267int(0)268int(25)269string(19) "ab12 ab12 ab12 ab12"270int(44)271bool(false)272-- Testing fgets() with file opened using mode a+b --273-- File content type : numeric --274-- fgets() with location set by fseek() with default length --275int(0)276int(5)277string(45) "222222222222222222222222222222222222222222222"278int(50)279bool(true)280-- fgets() with location set by fseek() with length = 20 --281int(0)282int(25)283string(19) "2222222222222222222"284int(44)285bool(false)286-- File content type : text --287-- fgets() with location set by fseek() with default length --288int(0)289int(5)290string(45) "text text text text text text text text text "291int(50)292bool(true)293-- fgets() with location set by fseek() with length = 20 --294int(0)295int(25)296string(19) "text text text text"297int(44)298bool(false)299-- File content type : text_with_new_line --300-- fgets() with location set by fseek() with default length --301int(0)302int(5)303string(13) "line of text304"305int(18)306bool(false)307-- fgets() with location set by fseek() with length = 20 --308int(0)309int(25)310string(11) "ne of text311"312int(36)313bool(false)314-- File content type : alphanumeric --315-- fgets() with location set by fseek() with default length --316int(0)317int(5)318string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "319int(50)320bool(true)321-- fgets() with location set by fseek() with length = 20 --322int(0)323int(25)324string(19) "ab12 ab12 ab12 ab12"325int(44)326bool(false)327-- Testing fgets() with file opened using mode a+t --328-- File content type : numeric --329-- fgets() with location set by fseek() with default length --330int(0)331int(5)332string(45) "222222222222222222222222222222222222222222222"333int(50)334bool(true)335-- fgets() with location set by fseek() with length = 20 --336int(0)337int(25)338string(19) "2222222222222222222"339int(44)340bool(false)341-- File content type : text --342-- fgets() with location set by fseek() with default length --343int(0)344int(5)345string(45) "text text text text text text text text text "346int(50)347bool(true)348-- fgets() with location set by fseek() with length = 20 --349int(0)350int(25)351string(19) "text text text text"352int(44)353bool(false)354-- File content type : text_with_new_line --355-- fgets() with location set by fseek() with default length --356int(0)357int(5)358string(1) "359"360int(6)361bool(false)362-- fgets() with location set by fseek() with length = 20 --363int(0)364int(25)365string(12) "ine of text366"367int(37)368bool(false)369-- File content type : alphanumeric --370-- fgets() with location set by fseek() with default length --371int(0)372int(5)373string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "374int(50)375bool(true)376-- fgets() with location set by fseek() with length = 20 --377int(0)378int(25)379string(19) "ab12 ab12 ab12 ab12"380int(44)381bool(false)382-- Testing fgets() with file opened using mode x+ --383-- File content type : numeric --384-- fgets() with location set by fseek() with default length --385int(0)386int(5)387string(45) "222222222222222222222222222222222222222222222"388int(50)389bool(true)390-- fgets() with location set by fseek() with length = 20 --391int(0)392int(25)393string(19) "2222222222222222222"394int(44)395bool(false)396-- File content type : text --397-- fgets() with location set by fseek() with default length --398int(0)399int(5)400string(45) "text text text text text text text text text "401int(50)402bool(true)403-- fgets() with location set by fseek() with length = 20 --404int(0)405int(25)406string(19) "text text text text"407int(44)408bool(false)409-- File content type : text_with_new_line --410-- fgets() with location set by fseek() with default length --411int(0)412int(5)413string(13) "line of text414"415int(18)416bool(false)417-- fgets() with location set by fseek() with length = 20 --418int(0)419int(25)420string(11) "ne of text421"422int(36)423bool(false)424-- File content type : alphanumeric --425-- fgets() with location set by fseek() with default length --426int(0)427int(5)428string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "429int(50)430bool(true)431-- fgets() with location set by fseek() with length = 20 --432int(0)433int(25)434string(19) "ab12 ab12 ab12 ab12"435int(44)436bool(false)437-- Testing fgets() with file opened using mode x+b --438-- File content type : numeric --439-- fgets() with location set by fseek() with default length --440int(0)441int(5)442string(45) "222222222222222222222222222222222222222222222"443int(50)444bool(true)445-- fgets() with location set by fseek() with length = 20 --446int(0)447int(25)448string(19) "2222222222222222222"449int(44)450bool(false)451-- File content type : text --452-- fgets() with location set by fseek() with default length --453int(0)454int(5)455string(45) "text text text text text text text text text "456int(50)457bool(true)458-- fgets() with location set by fseek() with length = 20 --459int(0)460int(25)461string(19) "text text text text"462int(44)463bool(false)464-- File content type : text_with_new_line --465-- fgets() with location set by fseek() with default length --466int(0)467int(5)468string(13) "line of text469"470int(18)471bool(false)472-- fgets() with location set by fseek() with length = 20 --473int(0)474int(25)475string(11) "ne of text476"477int(36)478bool(false)479-- File content type : alphanumeric --480-- fgets() with location set by fseek() with default length --481int(0)482int(5)483string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "484int(50)485bool(true)486-- fgets() with location set by fseek() with length = 20 --487int(0)488int(25)489string(19) "ab12 ab12 ab12 ab12"490int(44)491bool(false)492-- Testing fgets() with file opened using mode x+t --493-- File content type : numeric --494-- fgets() with location set by fseek() with default length --495int(0)496int(5)497string(45) "222222222222222222222222222222222222222222222"498int(50)499bool(true)500-- fgets() with location set by fseek() with length = 20 --501int(0)502int(25)503string(19) "2222222222222222222"504int(44)505bool(false)506-- File content type : text --507-- fgets() with location set by fseek() with default length --508int(0)509int(5)510string(45) "text text text text text text text text text "511int(50)512bool(true)513-- fgets() with location set by fseek() with length = 20 --514int(0)515int(25)516string(19) "text text text text"517int(44)518bool(false)519-- File content type : text_with_new_line --520-- fgets() with location set by fseek() with default length --521int(0)522int(5)523string(1) "524"525int(6)526bool(false)527-- fgets() with location set by fseek() with length = 20 --528int(0)529int(25)530string(12) "ine of text531"532int(37)533bool(false)534-- File content type : alphanumeric --535-- fgets() with location set by fseek() with default length --536int(0)537int(5)538string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "539int(50)540bool(true)541-- fgets() with location set by fseek() with length = 20 --542int(0)543int(25)544string(19) "ab12 ab12 ab12 ab12"545int(44)546bool(false)547Done...

Full Screen

Full Screen

fgets_variation4.phpt

Source:fgets_variation4.phpt Github

copy

Full Screen

...12include ("file.inc");13$file_modes = array("w+", "w+b", "w+t",14                    "a+", "a+b", "a+t",15                    "x+", "x+b", "x+t");16$file_content_types = array("numeric", "text", "text_with_new_line", "alphanumeric");17echo "*** Testing fgets() : usage variations ***\n";18$filename = __DIR__."/fgets_variation4.tmp";19foreach($file_modes as $file_mode) {20  echo "\n-- Testing fgets() with file opened using mode $file_mode --\n";21  foreach($file_content_types as $file_content_type) {22    echo "-- File content type : $file_content_type --\n";23    /* create files with $file_content_type */24    $file_handle = fopen($filename, $file_mode);25    $data = fill_file($file_handle, $file_content_type, 50);26    if ( !$file_handle ) {27      echo "Error: failed to open file $filename!";28      exit();29    }30    echo "-- fgets() with location set by fseek() with default length --\n";31    var_dump( fseek($file_handle, 5, SEEK_SET) );32    var_dump( ftell($file_handle) );33    var_dump( fgets($file_handle ) );34    var_dump( ftell($file_handle) ); // ensure the file pointer position35    var_dump( feof($file_handle) );  // ensure if eof set36    echo "-- fgets() with location set by fseek() with length = 20 --\n";37    var_dump( fseek($file_handle, 25, SEEK_SET) );38    var_dump( ftell($file_handle) );39    var_dump( fgets($file_handle, 20 ) ); // expected 19 chars40    var_dump( ftell($file_handle) ); // ensure the file pointer position41    var_dump( feof($file_handle) );  // ensure if eof set42    //close file43    fclose($file_handle);44    // delete file45    delete_file($filename);46  } // file_content_type loop47} // file_mode loop48echo "Done\n";49?>50--EXPECT--51*** Testing fgets() : usage variations ***52-- Testing fgets() with file opened using mode w+ --53-- File content type : numeric --54-- fgets() with location set by fseek() with default length --55int(0)56int(5)57string(45) "222222222222222222222222222222222222222222222"58int(50)59bool(true)60-- fgets() with location set by fseek() with length = 20 --61int(0)62int(25)63string(19) "2222222222222222222"64int(44)65bool(false)66-- File content type : text --67-- fgets() with location set by fseek() with default length --68int(0)69int(5)70string(45) "text text text text text text text text text "71int(50)72bool(true)73-- fgets() with location set by fseek() with length = 20 --74int(0)75int(25)76string(19) "text text text text"77int(44)78bool(false)79-- File content type : text_with_new_line --80-- fgets() with location set by fseek() with default length --81int(0)82int(5)83string(13) "line of text84"85int(18)86bool(false)87-- fgets() with location set by fseek() with length = 20 --88int(0)89int(25)90string(11) "ne of text91"92int(36)93bool(false)94-- File content type : alphanumeric --95-- fgets() with location set by fseek() with default length --96int(0)97int(5)98string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "99int(50)100bool(true)101-- fgets() with location set by fseek() with length = 20 --102int(0)103int(25)104string(19) "ab12 ab12 ab12 ab12"105int(44)106bool(false)107-- Testing fgets() with file opened using mode w+b --108-- File content type : numeric --109-- fgets() with location set by fseek() with default length --110int(0)111int(5)112string(45) "222222222222222222222222222222222222222222222"113int(50)114bool(true)115-- fgets() with location set by fseek() with length = 20 --116int(0)117int(25)118string(19) "2222222222222222222"119int(44)120bool(false)121-- File content type : text --122-- fgets() with location set by fseek() with default length --123int(0)124int(5)125string(45) "text text text text text text text text text "126int(50)127bool(true)128-- fgets() with location set by fseek() with length = 20 --129int(0)130int(25)131string(19) "text text text text"132int(44)133bool(false)134-- File content type : text_with_new_line --135-- fgets() with location set by fseek() with default length --136int(0)137int(5)138string(13) "line of text139"140int(18)141bool(false)142-- fgets() with location set by fseek() with length = 20 --143int(0)144int(25)145string(11) "ne of text146"147int(36)148bool(false)149-- File content type : alphanumeric --150-- fgets() with location set by fseek() with default length --151int(0)152int(5)153string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "154int(50)155bool(true)156-- fgets() with location set by fseek() with length = 20 --157int(0)158int(25)159string(19) "ab12 ab12 ab12 ab12"160int(44)161bool(false)162-- Testing fgets() with file opened using mode w+t --163-- File content type : numeric --164-- fgets() with location set by fseek() with default length --165int(0)166int(5)167string(45) "222222222222222222222222222222222222222222222"168int(50)169bool(true)170-- fgets() with location set by fseek() with length = 20 --171int(0)172int(25)173string(19) "2222222222222222222"174int(44)175bool(false)176-- File content type : text --177-- fgets() with location set by fseek() with default length --178int(0)179int(5)180string(45) "text text text text text text text text text "181int(50)182bool(true)183-- fgets() with location set by fseek() with length = 20 --184int(0)185int(25)186string(19) "text text text text"187int(44)188bool(false)189-- File content type : text_with_new_line --190-- fgets() with location set by fseek() with default length --191int(0)192int(5)193string(13) "line of text194"195int(18)196bool(false)197-- fgets() with location set by fseek() with length = 20 --198int(0)199int(25)200string(11) "ne of text201"202int(36)203bool(false)204-- File content type : alphanumeric --205-- fgets() with location set by fseek() with default length --206int(0)207int(5)208string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "209int(50)210bool(true)211-- fgets() with location set by fseek() with length = 20 --212int(0)213int(25)214string(19) "ab12 ab12 ab12 ab12"215int(44)216bool(false)217-- Testing fgets() with file opened using mode a+ --218-- File content type : numeric --219-- fgets() with location set by fseek() with default length --220int(0)221int(5)222string(45) "222222222222222222222222222222222222222222222"223int(50)224bool(true)225-- fgets() with location set by fseek() with length = 20 --226int(0)227int(25)228string(19) "2222222222222222222"229int(44)230bool(false)231-- File content type : text --232-- fgets() with location set by fseek() with default length --233int(0)234int(5)235string(45) "text text text text text text text text text "236int(50)237bool(true)238-- fgets() with location set by fseek() with length = 20 --239int(0)240int(25)241string(19) "text text text text"242int(44)243bool(false)244-- File content type : text_with_new_line --245-- fgets() with location set by fseek() with default length --246int(0)247int(5)248string(13) "line of text249"250int(18)251bool(false)252-- fgets() with location set by fseek() with length = 20 --253int(0)254int(25)255string(11) "ne of text256"257int(36)258bool(false)259-- File content type : alphanumeric --260-- fgets() with location set by fseek() with default length --261int(0)262int(5)263string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "264int(50)265bool(true)266-- fgets() with location set by fseek() with length = 20 --267int(0)268int(25)269string(19) "ab12 ab12 ab12 ab12"270int(44)271bool(false)272-- Testing fgets() with file opened using mode a+b --273-- File content type : numeric --274-- fgets() with location set by fseek() with default length --275int(0)276int(5)277string(45) "222222222222222222222222222222222222222222222"278int(50)279bool(true)280-- fgets() with location set by fseek() with length = 20 --281int(0)282int(25)283string(19) "2222222222222222222"284int(44)285bool(false)286-- File content type : text --287-- fgets() with location set by fseek() with default length --288int(0)289int(5)290string(45) "text text text text text text text text text "291int(50)292bool(true)293-- fgets() with location set by fseek() with length = 20 --294int(0)295int(25)296string(19) "text text text text"297int(44)298bool(false)299-- File content type : text_with_new_line --300-- fgets() with location set by fseek() with default length --301int(0)302int(5)303string(13) "line of text304"305int(18)306bool(false)307-- fgets() with location set by fseek() with length = 20 --308int(0)309int(25)310string(11) "ne of text311"312int(36)313bool(false)314-- File content type : alphanumeric --315-- fgets() with location set by fseek() with default length --316int(0)317int(5)318string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "319int(50)320bool(true)321-- fgets() with location set by fseek() with length = 20 --322int(0)323int(25)324string(19) "ab12 ab12 ab12 ab12"325int(44)326bool(false)327-- Testing fgets() with file opened using mode a+t --328-- File content type : numeric --329-- fgets() with location set by fseek() with default length --330int(0)331int(5)332string(45) "222222222222222222222222222222222222222222222"333int(50)334bool(true)335-- fgets() with location set by fseek() with length = 20 --336int(0)337int(25)338string(19) "2222222222222222222"339int(44)340bool(false)341-- File content type : text --342-- fgets() with location set by fseek() with default length --343int(0)344int(5)345string(45) "text text text text text text text text text "346int(50)347bool(true)348-- fgets() with location set by fseek() with length = 20 --349int(0)350int(25)351string(19) "text text text text"352int(44)353bool(false)354-- File content type : text_with_new_line --355-- fgets() with location set by fseek() with default length --356int(0)357int(5)358string(13) "line of text359"360int(18)361bool(false)362-- fgets() with location set by fseek() with length = 20 --363int(0)364int(25)365string(11) "ne of text366"367int(36)368bool(false)369-- File content type : alphanumeric --370-- fgets() with location set by fseek() with default length --371int(0)372int(5)373string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "374int(50)375bool(true)376-- fgets() with location set by fseek() with length = 20 --377int(0)378int(25)379string(19) "ab12 ab12 ab12 ab12"380int(44)381bool(false)382-- Testing fgets() with file opened using mode x+ --383-- File content type : numeric --384-- fgets() with location set by fseek() with default length --385int(0)386int(5)387string(45) "222222222222222222222222222222222222222222222"388int(50)389bool(true)390-- fgets() with location set by fseek() with length = 20 --391int(0)392int(25)393string(19) "2222222222222222222"394int(44)395bool(false)396-- File content type : text --397-- fgets() with location set by fseek() with default length --398int(0)399int(5)400string(45) "text text text text text text text text text "401int(50)402bool(true)403-- fgets() with location set by fseek() with length = 20 --404int(0)405int(25)406string(19) "text text text text"407int(44)408bool(false)409-- File content type : text_with_new_line --410-- fgets() with location set by fseek() with default length --411int(0)412int(5)413string(13) "line of text414"415int(18)416bool(false)417-- fgets() with location set by fseek() with length = 20 --418int(0)419int(25)420string(11) "ne of text421"422int(36)423bool(false)424-- File content type : alphanumeric --425-- fgets() with location set by fseek() with default length --426int(0)427int(5)428string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "429int(50)430bool(true)431-- fgets() with location set by fseek() with length = 20 --432int(0)433int(25)434string(19) "ab12 ab12 ab12 ab12"435int(44)436bool(false)437-- Testing fgets() with file opened using mode x+b --438-- File content type : numeric --439-- fgets() with location set by fseek() with default length --440int(0)441int(5)442string(45) "222222222222222222222222222222222222222222222"443int(50)444bool(true)445-- fgets() with location set by fseek() with length = 20 --446int(0)447int(25)448string(19) "2222222222222222222"449int(44)450bool(false)451-- File content type : text --452-- fgets() with location set by fseek() with default length --453int(0)454int(5)455string(45) "text text text text text text text text text "456int(50)457bool(true)458-- fgets() with location set by fseek() with length = 20 --459int(0)460int(25)461string(19) "text text text text"462int(44)463bool(false)464-- File content type : text_with_new_line --465-- fgets() with location set by fseek() with default length --466int(0)467int(5)468string(13) "line of text469"470int(18)471bool(false)472-- fgets() with location set by fseek() with length = 20 --473int(0)474int(25)475string(11) "ne of text476"477int(36)478bool(false)479-- File content type : alphanumeric --480-- fgets() with location set by fseek() with default length --481int(0)482int(5)483string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "484int(50)485bool(true)486-- fgets() with location set by fseek() with length = 20 --487int(0)488int(25)489string(19) "ab12 ab12 ab12 ab12"490int(44)491bool(false)492-- Testing fgets() with file opened using mode x+t --493-- File content type : numeric --494-- fgets() with location set by fseek() with default length --495int(0)496int(5)497string(45) "222222222222222222222222222222222222222222222"498int(50)499bool(true)500-- fgets() with location set by fseek() with length = 20 --501int(0)502int(25)503string(19) "2222222222222222222"504int(44)505bool(false)506-- File content type : text --507-- fgets() with location set by fseek() with default length --508int(0)509int(5)510string(45) "text text text text text text text text text "511int(50)512bool(true)513-- fgets() with location set by fseek() with length = 20 --514int(0)515int(25)516string(19) "text text text text"517int(44)518bool(false)519-- File content type : text_with_new_line --520-- fgets() with location set by fseek() with default length --521int(0)522int(5)523string(13) "line of text524"525int(18)526bool(false)527-- fgets() with location set by fseek() with length = 20 --528int(0)529int(25)530string(11) "ne of text531"532int(36)533bool(false)534-- File content type : alphanumeric --535-- fgets() with location set by fseek() with default length --536int(0)537int(5)538string(45) "ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 "539int(50)540bool(true)541-- fgets() with location set by fseek() with length = 20 --542int(0)543int(25)544string(19) "ab12 ab12 ab12 ab12"545int(44)546bool(false)547Done...

Full Screen

Full Screen

JASON+JSONKey.swift

Source:JASON+JSONKey.swift Github

copy

Full Screen

...4// Copyright (c) 2015-2016 Damien (http://delba.io)5//6// Permission is hereby granted, free of charge, to any person obtaining a copy7// of this software and associated documentation files (the "Software"), to deal8// in the Software without restriction, including without limitation the rights9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10// copies of the Software, and to permit persons to whom the Software is11// furnished to do so, subject to the following conditions:12//13// The above copyright notice and this permission notice shall be included in all14// copies or substantial portions of the Software.15//16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE22// SOFTWARE.23//24import JASON25// MARK: - Signed Integers26extension JSON {27    /**28     Returns the value associated with the given key as a 8-bit signed integer or nil if not present/convertible.29     30     - parameter key: The key.31     32     - returns: The value associated with the given key as a 8-bit signed integer or nil if not present/convertible.33     */34    public subscript(key: JSONKey<Int8?>) -> Int8? {35        return self[key.type].int836    }37    38    /**39     Returns the value associated with the given key as a 8-bit signed integer or 0 if not present/convertible.40     41     - parameter key: The key.42     43     - returns: The value associated with the given key as a 8-bit signed integer or 0 if not present/convertible.44     */45    public subscript(key: JSONKey<Int8>) -> Int8 {46        return self[key.type].int8Value47    }48    49    /**50     Returns the value associated with the given key as a 16-bit signed integer or nil if not present/convertible.51     52     - parameter key: The key.53     54     - returns: The value associated with the given key as a 16-bit signed integer or nil if not present/convertible.55     */56    public subscript(key: JSONKey<Int16?>) -> Int16? {57        return self[key.type].int1658    }59    60    /**61     Returns the value associated with the given key as a 16-bit signed integer or 0 if not present/convertible.62     63     - parameter key: The key.64     65     - returns: The value associated with the given key as a 16-bit signed integer or 0 if not present/convertible.66     */67    public subscript(key: JSONKey<Int16>) -> Int16 {68        return self[key.type].int16Value69    }70    71    /**72     Returns the value associated with the given key as a 32-bit signed integer or nil if not present/convertible.73     74     - parameter key: The key.75     76     - returns: The value associated with the given key as a 32-bit signed integer or nil if not present/convertible.77     */78    public subscript(key: JSONKey<Int32?>) -> Int32? {79        return self[key.type].int3280    }81    82    /**83     Returns the value associated with the given key as a 32-bit signed integer or 0 if not present/convertible.84     85     - parameter key: The key.86     87     - returns: The value associated with the given key as a 32-bit signed integer or 0 if not present/convertible.88     */89    public subscript(key: JSONKey<Int32>) -> Int32 {90        return self[key.type].int32Value91    }92    93    /**94     Returns the value associated with the given key as a 64-bit signed integer or nil if not present/convertible.95     96     - parameter key: The key.97     98     - returns: The value associated with the given key as a 64-bit signed integer or nil if not present/convertible.99     */100    public subscript(key: JSONKey<Int64?>) -> Int64? {101        return self[key.type].int64102    }103    104    /**105     Returns the value associated with the given key as a 64-bit signed integer or 0 if not present/convertible.106     107     - parameter key: The key.108     109     - returns: The value associated with the given key as a 64-bit signed integer or 0 if not present/convertible.110     */111    public subscript(key: JSONKey<Int64>) -> Int64 {112        return self[key.type].int64Value113    }114}115// MARK: - Unsigned Integers116extension JSON {117    /**118     Returns the value associated with the given key as a 64-bit unsigned integer or nil if not present/convertible.119     120     - parameter key: The key.121     122     - returns: The value associated with the given key as a 64-bit unsigned integer or nil if not present/convertible.123     */124    public subscript(key: JSONKey<UInt?>) -> UInt? {125        return self[key.type].uInt126    }127    128    /**129     Returns the value associated with the given key as a 64-bit unsigned integer or 0 if not present/convertible.130     131     - parameter key: The key.132     133     - returns: The value associated with the given key as a 64-bit unsigned integer or 0 if not present/convertible.134     */135    public subscript(key: JSONKey<UInt>) -> UInt {136        return self[key.type].uIntValue137    }138    139    /**140     Returns the value associated with the given key as a 8-bit unsigned integer or nil if not present/convertible.141     142     - parameter key: The key.143     144     - returns: The value associated with the given key as a 8-bit unsigned integer or nil if not present/convertible.145     */146    public subscript(key: JSONKey<UInt8?>) -> UInt8? {147        return self[key.type].uInt8148    }149    150    /**151     Returns the value associated with the given key as a 8-bit unsigned integer or 0 if not present/convertible.152     153     - parameter key: The key.154     155     - returns: The value associated with the given key as a 8-bit unsigned integer or 0 if not present/convertible.156     */157    public subscript(key: JSONKey<UInt8>) -> UInt8 {158        return self[key.type].uInt8Value159    }160    161    /**162     Returns the value associated with the given key as a 16-bit unsigned integer or nil if not present/convertible.163     164     - parameter key: The key.165     166     - returns: The value associated with the given key as a 16-bit unsigned integer or nil if not present/convertible.167     */168    public subscript(key: JSONKey<UInt16?>) -> UInt16? {169        return self[key.type].uInt16170    }171    172    /**173     Returns the value associated with the given key as a 16-bit unsigned integer or 0 if not present/convertible.174     175     - parameter key: The key.176     177     - returns: The value associated with the given key as a 16-bit unsigned integer or 0 if not present/convertible.178     */179    public subscript(key: JSONKey<UInt16>) -> UInt16 {180        return self[key.type].uInt16Value181    }182    183    /**184     Returns the value associated with the given key as a 32-bit unsigned integer or nil if not present/convertible.185     186     - parameter key: The key.187     188     - returns: The value associated with the given key as a 32-bit unsigned integer or nil if not present/convertible.189     */190    public subscript(key: JSONKey<UInt32?>) -> UInt32? {191        return self[key.type].uInt32192    }193    194    /**195     Returns the value associated with the given key as a 32-bit unsigned integer or 0 if not present/convertible.196     197     - parameter key: The key.198     199     - returns: The value associated with the given key as a 32-bit unsigned integer or 0 if not present/convertible.200     */201    public subscript(key: JSONKey<UInt32>) -> UInt32 {202        return self[key.type].uInt32Value203    }204    205    /**206     Returns the value associated with the given key as a 64-bit unsigned integer or nil if not present/convertible.207     208     - parameter key: The key.209     210     - returns: The value associated with the given key as a 64-bit unsigned integer or nil if not present/convertible.211     */212    public subscript(key: JSONKey<UInt64?>) -> UInt64? {213        return self[key.type].uInt64214    }215    216    /**217     Returns the value associated with the given key as a 64-bit unsigned integer or 0 if not present/convertible.218     219     - parameter key: The key.220     221     - returns: The value associated with the given key as a 64-bit unsigned integer or 0 if not present/convertible.222     */223    public subscript(key: JSONKey<UInt64>) -> UInt64 {224        return self[key.type].uInt64Value225    }226}...

Full Screen

Full Screen

DownloaderTests.swift

Source:DownloaderTests.swift Github

copy

Full Screen

...36        }37        func didFinishDownloadTask(_ task: URLSessionDownloadTask, to location: URL, sender: Downloader) {38            didFinishExpectation?.fulfill()39        }40        func didFailDownloadTask(_ task: URLSessionTask, with error: Error?, sender: Downloader) {41            didFailExpectation?.fulfill()42        }43    }44    // MARK: Properties45    let downloader = Downloader(configuration: .default)46    let url1: URL = "https://httpbin.org/image/png"47    let url2: URL = "https://httpbin.org/image/jpeg"48    let url3: URL = "https://test.test"49    // MARK: Setup50    override func setUp() {51        super.setUp()52        downloader.delegate = self53    }54    // MARK: Tests55    func testStartAndStopDownload() {56        downloader.start(with: url1)57        XCTAssertEqual(downloader.items.count, 1, "Should have 1 item.")58        XCTAssertNotNil(downloader.item(with: url1), "Should be able to find item with url.")59        XCTAssertEqual(downloader.tasks.count, 1, "Should have 1 download task.")60        XCTAssertNotNil(downloader.task(with: url1), "Should be able to find task with url.")61        let item2 = Item(url: url2)62        item2.startDownload(with: downloader)63        XCTAssertEqual(downloader.items.count, 2, "Should have 2 download items.")64        XCTAssertNotNil(downloader.item(with: url2), "Should be able to find item with url.")65        XCTAssertEqual(downloader.tasks.count, 2, "Should have 2 download tasks.")66        XCTAssertNotNil(downloader.task(with: url2), "Should be able to find task with url.")67        downloader.stop(for: url1)68        XCTAssertEqual(downloader.items.count, 1, "Should have 1 item.")69        XCTAssertNil(downloader.item(with: url1), "Should not be able to find item with url.")70        XCTAssertEqual(downloader.tasks.count, 1, "Should have 1 download task.")71        XCTAssertNil(downloader.task(with: url1), "Should not be able to find task with url.")72        item2.stopDownload(with: downloader)73        XCTAssertEqual(downloader.items.count, 0, "Should have 0 download items.")74        XCTAssertNil(downloader.item(with: url2), "Should not be able to find item with url.")75        XCTAssertEqual(downloader.tasks.count, 0, "Should have 0 download tasks.")76        XCTAssertNil(downloader.task(with: url2), "Should not be able to find task with url.")77    }78    var downloadFinishedExpectation: XCTestExpectation?79    func testDownloadFinished() {80        downloadFinishedExpectation = expectation(description: "Download Finished")81        downloadFinishedExpectation?.assertForOverFulfill = false82        downloader.start(with: url1)83        wait(for: [downloadFinishedExpectation!], timeout: 5)84        var item = Item(url: url2)85        item.didStartExpectation = expectation(description: "Item Started Download")86        item.didUpdateExpectation = expectation(description: "Item Updated Download")87        item.didUpdateExpectation?.assertForOverFulfill = false88        item.didFinishExpectation = expectation(description: "Item Finished Download")89        item.startDownload(with: downloader)90        let expectations = [item.didStartExpectation!, item.didUpdateExpectation!, item.didFinishExpectation!]91        wait(for: expectations, timeout: 5)92    }93    var downloadFailedExpectation: XCTestExpectation?94    func testDownloadFailed() {95        downloadFailedExpectation = expectation(description: "Download Failed")96        downloadFailedExpectation?.assertForOverFulfill = false97        downloader.start(with: url3)98        wait(for: [downloadFailedExpectation!], timeout: 5)99        var item = Item(url: url3)100        item.didStartExpectation = expectation(description: "Item Started Download")101        item.didFailExpectation = expectation(description: "Item Failed Download")102        item.startDownload(with: downloader)103        wait(for: [item.didStartExpectation!, item.didFailExpectation!], timeout: 5)104    }105    func testReplaceItem() {106        let item1 = Item(url: url1)107        downloader.start(with: item1)108        let item2 = Item(url: url2)109        downloader.replaceItem(at: 0, with: item2)110        XCTAssertNil(downloader.item(with: url1), "Should not be able to find item with url.")111        XCTAssertNotNil(downloader.item(with: url2), "Should be able to find item with url.")112        XCTAssertEqual(downloader.items.count, 1, "Should have 1 download item.")113    }114}115extension DownloaderTests: DownloaderDelegate {116    func didStartDownloadTask(_ task: URLSessionDownloadTask, sender: Downloader) {117        XCTAssertNotNil(downloader.tasks.firstIndex(of: task), "Should have this task in tasks.")118    }119    func didUpdateDownloadTask(_ task: URLSessionDownloadTask, progress: Float, sender: Downloader) {120        let message = "Progress should be between 0 and 1."121        XCTAssertGreaterThanOrEqual(progress, 0, message)122        XCTAssertLessThanOrEqual(progress, 1, message)123    }124    func didStopDownloadTask(_ task: URLSessionDownloadTask, sender: Downloader) {125        XCTAssertNil(downloader.tasks.firstIndex(of: task), "Should not have this task in tasks.")126    }127    func didFinishDownloadTask(_ task: URLSessionDownloadTask, to location: URL, sender: Downloader) {128        let isDownloaded = FileManager.default.fileExists(atPath: location.path)129        XCTAssertTrue(isDownloaded, "Should have downloaded file at location: \(location).")130        downloadFinishedExpectation?.fulfill()131    }132    func didFailDownloadTask(_ task: URLSessionTask, with error: Error?, sender: Downloader) {133        if task.originalRequest?.url == url3 {134            XCTAssertNotNil(error, "Should have error: \(String(describing: error?.localizedDescription))")135            downloadFailedExpectation?.fulfill()136        }137    }138}...

Full Screen

Full Screen

round_basic.phpt

Source:round_basic.phpt Github

copy

Full Screen

...29for ($i = 0; $i < count($values); $i++) {30    echo "round: $values[$i]\n";31    for ($j = 0; $j < count($precision); $j++) {32        $res = round($values[$i], $precision[$j]);33        echo "...with precision $precision[$j]-> ";34        var_dump($res);35    }36}37?>38--EXPECT--39*** Testing round() : basic functionality ***40round: 12345678941...with precision 2-> float(123456789)42...with precision 8-> float(123456789)43...with precision 3-> float(123456789)44...with precision 4-> float(123456789)45...with precision 3.6-> float(123456789)46...with precision 2-> float(123456789)47...with precision 04-> float(123456789)48...with precision 3.6-> float(123456789)49...with precision 2.1e1-> float(123456789)50...with precision -> float(123456789)51...with precision 1-> float(123456789)52...with precision -> float(123456789)53round: 123.45678954...with precision 2-> float(123.46)55...with precision 8-> float(123.456789)56...with precision 3-> float(123.457)57...with precision 4-> float(123.4568)58...with precision 3.6-> float(123.457)59...with precision 2-> float(123.46)60...with precision 04-> float(123.4568)61...with precision 3.6-> float(123.457)62...with precision 2.1e1-> float(123.456789)63...with precision -> float(123)64...with precision 1-> float(123.5)65...with precision -> float(123)66round: -4.567912367...with precision 2-> float(-4.57)68...with precision 8-> float(-4.5679123)69...with precision 3-> float(-4.568)70...with precision 4-> float(-4.5679)71...with precision 3.6-> float(-4.568)72...with precision 2-> float(-4.57)73...with precision 04-> float(-4.5679)74...with precision 3.6-> float(-4.568)75...with precision 2.1e1-> float(-4.5679123)76...with precision -> float(-5)77...with precision 1-> float(-4.6)78...with precision -> float(-5)79round: 1230080...with precision 2-> float(12300)81...with precision 8-> float(12300)82...with precision 3-> float(12300)83...with precision 4-> float(12300)84...with precision 3.6-> float(12300)85...with precision 2-> float(12300)86...with precision 04-> float(12300)87...with precision 3.6-> float(12300)88...with precision 2.1e1-> float(12300)89...with precision -> float(12300)90...with precision 1-> float(12300)91...with precision -> float(12300)92round: -456793...with precision 2-> float(-4567)94...with precision 8-> float(-4567)95...with precision 3-> float(-4567)96...with precision 4-> float(-4567)97...with precision 3.6-> float(-4567)98...with precision 2-> float(-4567)99...with precision 04-> float(-4567)100...with precision 3.6-> float(-4567)101...with precision 2.1e1-> float(-4567)102...with precision -> float(-4567)103...with precision 1-> float(-4567)104...with precision -> float(-4567)105round: 2311527106...with precision 2-> float(2311527)107...with precision 8-> float(2311527)108...with precision 3-> float(2311527)109...with precision 4-> float(2311527)110...with precision 3.6-> float(2311527)111...with precision 2-> float(2311527)112...with precision 04-> float(2311527)113...with precision 3.6-> float(2311527)114...with precision 2.1e1-> float(2311527)115...with precision -> float(2311527)116...with precision 1-> float(2311527)117...with precision -> float(2311527)118round: 14680063119...with precision 2-> float(14680063)120...with precision 8-> float(14680063)121...with precision 3-> float(14680063)122...with precision 4-> float(14680063)123...with precision 3.6-> float(14680063)124...with precision 2-> float(14680063)125...with precision 04-> float(14680063)126...with precision 3.6-> float(14680063)127...with precision 2.1e1-> float(14680063)128...with precision -> float(14680063)129...with precision 1-> float(14680063)130...with precision -> float(14680063)131round: 1.234567132...with precision 2-> float(1.23)133...with precision 8-> float(1.234567)134...with precision 3-> float(1.235)135...with precision 4-> float(1.2346)136...with precision 3.6-> float(1.235)137...with precision 2-> float(1.23)138...with precision 04-> float(1.2346)139...with precision 3.6-> float(1.235)140...with precision 2.1e1-> float(1.234567)141...with precision -> float(1)142...with precision 1-> float(1.2)143...with precision -> float(1)144round: 2.3456789e8145...with precision 2-> float(234567890)146...with precision 8-> float(234567890)147...with precision 3-> float(234567890)148...with precision 4-> float(234567890)149...with precision 3.6-> float(234567890)150...with precision 2-> float(234567890)151...with precision 04-> float(234567890)152...with precision 3.6-> float(234567890)153...with precision 2.1e1-> float(234567890)154...with precision -> float(234567890)155...with precision 1-> float(234567890)156...with precision -> float(234567890)...

Full Screen

Full Screen

with

Using AI Code Generation

copy

Full Screen

1import Foundation2import Mockingbird3import MockingbirdFramework4class Class1 {5    func method1() {6        print("method1")7    }8}9import Foundation10import Mockingbird11import MockingbirdFramework12class Class2 {13    func method2() {14        print("method2")15    }16}17import Foundation18import Mockingbird19import MockingbirdFramework20class Class3 {21    func method3() {22        print("method3")23    }24}25import Foundation26import Mockingbird27import MockingbirdFramework28class Class4 {29    func method4() {30        print("method4")31    }32}33import Foundation34import Mockingbird35import MockingbirdFramework36class Class5 {37    func method5() {38        print("method5")39    }40}41import Foundation42import Mockingbird43import MockingbirdFramework44class Class6 {45    func method6() {46        print("method6")47    }48}49import Foundation50import Mockingbird51import MockingbirdFramework52class Class7 {53    func method7() {54        print("method7")55    }56}57import Foundation58import Mockingbird59import MockingbirdFramework60class Class8 {61    func method8() {62        print("method8")63    }64}65import Foundation66import Mockingbird67import MockingbirdFramework68class Class9 {69    func method9() {70        print("method9")71    }72}73import Foundation74import Mockingbird75import MockingbirdFramework76class Class10 {77    func method10() {78        print("method10")79    }80}

Full Screen

Full Screen

with

Using AI Code Generation

copy

Full Screen

1import Foundation2import Mockingbird3class A {4    func foo() {5        print("foo")6    }7}8class B {9    func bar() {10        print("bar")11    }12}13class C {14    func baz() {15        print("baz")16    }17}18import Foundation19import Mockingbird20class D {21    func qux() {22        print("qux")23    }24}25class E {26    func quux() {27        print("quux")28    }29}30class F {31    func quuz() {32        print("quuz")33    }34}35import Foundation36import Mockingbird37class G {38    func corge() {39        print("corge")40    }41}42class H {43    func grault() {44        print("grault")45    }46}47class I {48    func garply() {49        print("garply")50    }51}52import Foundation53import Mockingbird54class J {55    func waldo() {56        print("waldo")57    }58}59class K {60    func fred() {61        print("fred")62    }63}64class L {65    func plugh() {66        print("plugh")67    }68}69import Foundation70import Mockingbird71class M {72    func xyzzy() {73        print("xyzzy")74    }75}76class N {77    func thud() {78        print("thud")79    }80}81class O {82    func thud() {83        print("thud")84    }85}86import Foundation87import Mockingbird88class P {89    func thud() {90        print("thud")91    }92}93class Q {94    func thud() {95        print("thud")96    }97}98class R {99    func thud() {100        print("thud")101    }102}103import Foundation104import Mockingbird105class S {106    func thud() {107        print("thud")108    }109}110class T {111    func thud() {112        print("thud")113    }114}115class U {116    func thud() {117        print("thud")118    }119}120import Foundation121import Mockingbird122class V {123    func thud() {124        print("thud")125    }126}127class W {

Full Screen

Full Screen

with

Using AI Code Generation

copy

Full Screen

1import Foundation2class MyClass {3    func myMethod() {4        print("Hello World")5    }6}7import Foundation8import Mockingbird9let mock = mock(MyClass.self)10let stub = stub(mock)11stub.myMethod().thenReturn("Hello World")12import Foundation13import Mockingbird14let mock = mock(MyClass.self)15let stub = stub(mock)16stub.myMethod().thenReturn("Hello World")17import Foundation18import Mockingbird19let mock = mock(MyClass.self)20let stub = stub(mock)21stub.myMethod().thenReturn("Hello World")22import Foundation23import Mockingbird24let mock = mock(MyClass.self)25let stub = stub(mock)26stub.myMethod().thenReturn("Hello World")27import Foundation28import Mockingbird29let mock = mock(MyClass.self)30let stub = stub(mock)31stub.myMethod().thenReturn("Hello World")32import Foundation33import Mockingbird34let mock = mock(MyClass.self)35let stub = stub(mock)36stub.myMethod().thenReturn("Hello World")37import Foundation38import Mockingbird39let mock = mock(MyClass.self)40let stub = stub(mock)41stub.myMethod().thenReturn("Hello World")42import Foundation43import Mockingbird44let mock = mock(MyClass.self)45let stub = stub(mock)46stub.myMethod().thenReturn("Hello World")47import Foundation48import Mockingbird49let mock = mock(MyClass.self)50let stub = stub(mock)51stub.myMethod().thenReturn("Hello World")52import Foundation53import Mockingbird54let mock = mock(MyClass.self)55let stub = stub(mock)56stub.myMethod().thenReturn("Hello World")

Full Screen

Full Screen

with

Using AI Code Generation

copy

Full Screen

1class Mockingbird {2    func sing() {3        print("I am singing")4    }5}6let mockingbird = Mockingbird()7mockingbird.sing()8import Foundation9import Mockingbird10let mockingbird = Mockingbird()11mockingbird.sing()12import Foundation13import Mockingbird14let mockingbird = Mockingbird()15mockingbird.sing()16import Foundation17import Mockingbird18let mockingbird = Mockingbird()19mockingbird.sing()20import Foundation21import Mockingbird22let mockingbird = Mockingbird()23mockingbird.sing()24import Foundation25import Mockingbird26let mockingbird = Mockingbird()27mockingbird.sing()28import Foundation29import Mockingbird30let mockingbird = Mockingbird()31mockingbird.sing()32import Foundation33import Mockingbird34let mockingbird = Mockingbird()35mockingbird.sing()36import Foundation37import Mockingbird38let mockingbird = Mockingbird()39mockingbird.sing()40import Foundation41import Mockingbird42let mockingbird = Mockingbird()43mockingbird.sing()44import Foundation45import Mockingbird46let mockingbird = Mockingbird()47mockingbird.sing()48import Foundation49import Mockingbird50let mockingbird = Mockingbird()51mockingbird.sing()

Full Screen

Full Screen

with

Using AI Code Generation

copy

Full Screen

1import Foundation2import Mockingbird3class MyMockingbirdClass {4    func myFunction() {5        print("myFunction called")6    }7    func myFunction2() {8        print("myFunction2 called")9    }10}11let mockingbird = MyMockingbirdClass()12mockingbird.myFunction()13mockingbird.myFunction2()14import Foundation15import Mockingbird16class MyMockingbirdClass {17    func myFunction() {18        print("myFunction called")19    }20    func myFunction2() {21        print("myFunction2 called")22    }23}24let mockingbird = MyMockingbirdClass()25mockingbird.myFunction()26mockingbird.myFunction2()27import Foundation28import Mockingbird29class MyMockingbirdClass {30    func myFunction() {31        print("myFunction called")32    }33    func myFunction2() {34        print("myFunction2 called")35    }36}37let mockingbird = MyMockingbirdClass()38mockingbird.myFunction()39mockingbird.myFunction2()40import Foundation41import Mockingbird42class MyMockingbirdClass {43    func myFunction() {44        print("myFunction called")45    }46    func myFunction2() {47        print("myFunction2 called")48    }49}50let mockingbird = MyMockingbirdClass()51mockingbird.myFunction()52mockingbird.myFunction2()53import Foundation54import Mockingbird55class MyMockingbirdClass {56    func myFunction() {57        print("myFunction called")58    }59    func myFunction2() {60        print("myFunction2 called")61    }62}63let mockingbird = MyMockingbirdClass()64mockingbird.myFunction()65mockingbird.myFunction2()66import Foundation67import Mockingbird68class MyMockingbirdClass {69    func myFunction() {70        print("myFunction called")71    }72    func myFunction2()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mockingbird automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful