
"use strict"


var example = require("washington")
var Sydney  = require("../sydney")


example("#unlink: remove from venue", function () {
  var mother    = new Sydney
  var daughter  = new Sydney

  mother.link(daughter)

  mother.unlink(daughter)

  return mother.subscribers.length === 0
})


example("#unlink: remove venue from subscriber", function () {
  var mother    = new Sydney
  var daughter  = new Sydney

  mother.link(daughter)

  mother.unlink(daughter)

  return daughter.subscribers.length === 0
})


example("#unlink: @function remove from venue", function () {
  var mother            = new Sydney
  var daughterCallback  = function () {}

  mother.link(daughterCallback)

  mother.unlink(daughterCallback)

  return mother.subscribers.length === 0
})


example("#unlink: @function remove venue from subscriber", function () {
  var mother            = new Sydney
  var daughterCallback  = function () {}
  var daughter          = undefined

  mother.link(daughterCallback)

  daughter = Sydney.find(daughterCallback, mother)

  mother.unlink(daughterCallback)

  return daughter.subscribers.length === 0
})


example("#unlink: @endpoint remove from venue", function () {
  var mother            = new Sydney
  var endpoint          = { match: function () {} }
  var daughterCallback  = function () {}

  mother.link(endpoint, daughterCallback)

  mother.unlink(endpoint)

  return mother.subscribers.length === 0
})


example("#unlink: @endpoint remove venue from subscriber", function () {
  var mother            = new Sydney
  var endpoint          = { match: function () {} }
  var daughterCallback  = function () {}
  var daughter          = undefined

  mother.link(endpoint, daughterCallback)

  daughter = Sydney.find(daughterCallback, mother)

  mother.unlink(endpoint)

  return daughter.subscribers.length === 0
})


example("#unlink: chainable", function () {
  var mother    = new Sydney
  var daughter  = new Sydney

  mother.link(daughter)

  return mother.unlink(daughter) === mother
})


example("#unlink: @no-subscribers won't fail", function () {
  new Sydney().unlink(new Sydney)
})


example("#unlink: @vanilla is also unlinked")

@@ -2151,23 +2151,1892 @@
 lla 
-is also unlinked%22
+@callback remove from venue%22, function () %7B%0A  var venue = new Sydney%0A  var subscriber = %7B%0A    callback: function () %7B%7D%0A  %7D%0A%0A  venue.link(subscriber)%0A%0A  venue.unlink(subscriber)%0A%0A  return venue.subscribers.length === 0%0A%7D)%0A%0A%0Aexample(%22#unlink: @vanilla @callback remove from subscriber%22, function () %7B%0A  var shadowSubscriber;%0A  var venue = new Sydney%0A  var subscriber = %7B%0A    callback: function () %7B%7D%0A  %7D%0A%0A  venue.link(subscriber)%0A%0A  shadowSubscriber = venue.subscribers%5B0%5D%0A%0A  venue.unlink(subscriber)%0A%0A  return shadowSubscriber.subscribers.length === 0%0A%7D)%0A%0A%0Aexample(%22#unlink: @vanilla @endpoint remove from venue%22, function () %7B%0A  var venue = new Sydney%0A  var subscriber = %7B%0A    endpoint: %7B%0A      match: function () %7B%7D%0A    %7D%0A  %7D%0A%0A  venue.link(subscriber)%0A%0A  venue.unlink(subscriber)%0A%0A  return venue.subscribers.length === 0%0A%7D)%0A%0A%0Aexample(%22#unlink: @vanilla @endpoint remove from subscriber%22, function () %7B%0A  var shadowSubscriber;%0A  var venue = new Sydney%0A  var subscriber = %7B%0A    endpoint: %7B%0A      match: function () %7B%7D%0A    %7D%0A  %7D%0A%0A  venue.link(subscriber)%0A%0A  shadowSubscriber = venue.subscribers%5B0%5D%0A%0A  venue.unlink(subscriber)%0A%0A  return shadowSubscriber.subscribers.length === 0%0A%7D)%0A%0A%0Aexample(%22#unlink: @vanilla @endpoint & @callback remove from venue%22, function () %7B%0A  var venue = new Sydney%0A  var subscriber = %7B%0A    callback: function () %7B%7D,%0A    endpoint: %7B%0A      match: function () %7B%7D%0A    %7D%0A  %7D%0A%0A  venue.link(subscriber)%0A%0A  venue.unlink(subscriber)%0A%0A  return venue.subscribers.length === 0%0A%7D)%0A%0A%0Aexample(%22#unlink: @vanilla @endpoint & @callback remove from subscriber%22, function () %7B%0A  var shadowSubscriber;%0A  var venue = new Sydney%0A  var subscriber = %7B%0A    callback: function () %7B%7D,%0A    endpoint: %7B%0A      match: function () %7B%7D%0A    %7D%0A  %7D%0A%0A  venue.link(subscriber)%0A%0A  shadowSubscriber = venue.subscribers%5B0%5D%0A%0A  venue.unlink(subscriber)%0A%0A  return shadowSubscriber.subscribers.length === 0%0A%7D
 )%0A

Support @vanilla in #unlink