jsfmt.spec.js.snap 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. // Jest Snapshot v1, https://goo.gl/fbAQLP
  2. exports[`functional_compose.js 1`] = `
  3. compose(
  4. sortBy(x => x),
  5. flatten,
  6. map(x => [x, x*2])
  7. );
  8. somelib.compose(
  9. sortBy(x => x),
  10. flatten,
  11. map(x => [x, x*2])
  12. );
  13. composeFlipped(
  14. sortBy(x => x),
  15. flatten,
  16. map(x => [x, x*2])
  17. );
  18. somelib.composeFlipped(
  19. sortBy(x => x),
  20. flatten,
  21. map(x => [x, x*2])
  22. );
  23. // no regression (#4602)
  24. const hasValue = hasOwnProperty(a, b);
  25. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. compose(
  27. sortBy(x => x),
  28. flatten,
  29. map(x => [x, x * 2])
  30. );
  31. somelib.compose(
  32. sortBy(x => x),
  33. flatten,
  34. map(x => [x, x * 2])
  35. );
  36. composeFlipped(
  37. sortBy(x => x),
  38. flatten,
  39. map(x => [x, x * 2])
  40. );
  41. somelib.composeFlipped(
  42. sortBy(x => x),
  43. flatten,
  44. map(x => [x, x * 2])
  45. );
  46. // no regression (#4602)
  47. const hasValue = hasOwnProperty(a, b);
  48. `;
  49. exports[`lodash_flow.js 1`] = `
  50. import { flow } from "lodash";
  51. const foo = flow(
  52. x => x + 1,
  53. x => x * 3,
  54. x => x - 6,
  55. );
  56. foo(6);
  57. import * as _ from "lodash";
  58. const foo = _.flow(
  59. x => x + 1,
  60. x => x * 3,
  61. x => x - 6,
  62. );
  63. foo(6);
  64. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65. import { flow } from "lodash";
  66. const foo = flow(
  67. x => x + 1,
  68. x => x * 3,
  69. x => x - 6
  70. );
  71. foo(6);
  72. import * as _ from "lodash";
  73. const foo = _.flow(
  74. x => x + 1,
  75. x => x * 3,
  76. x => x - 6
  77. );
  78. foo(6);
  79. `;
  80. exports[`lodash_flow_right.js 1`] = `
  81. import { flowRight } from "lodash";
  82. const foo = flowRight(
  83. x => x + 1,
  84. x => x * 3,
  85. x => x - 6,
  86. );
  87. foo(6);
  88. import * as _ from "lodash";
  89. const foo = _.flowRight(
  90. x => x + 1,
  91. x => x * 3,
  92. x => x - 6,
  93. );
  94. foo(6);
  95. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  96. import { flowRight } from "lodash";
  97. const foo = flowRight(
  98. x => x + 1,
  99. x => x * 3,
  100. x => x - 6
  101. );
  102. foo(6);
  103. import * as _ from "lodash";
  104. const foo = _.flowRight(
  105. x => x + 1,
  106. x => x * 3,
  107. x => x - 6
  108. );
  109. foo(6);
  110. `;
  111. exports[`ramda_compose.js 1`] = `
  112. var classyGreeting = (firstName, lastName) =>
  113. "The name's " + lastName + ", " + firstName + " " + lastName;
  114. var yellGreeting = R.compose(R.toUpper, classyGreeting);
  115. yellGreeting("James", "Bond"); //=> "THE NAME'S BOND, JAMES BOND"
  116. R.compose(Math.abs, R.add(1), R.multiply(2))(-4); //=> 7
  117. // get :: String -> Object -> Maybe *
  118. var get = R.curry((propName, obj) => Maybe(obj[propName]));
  119. // getStateCode :: Maybe String -> Maybe String
  120. var getStateCode = R.composeK(
  121. R.compose(Maybe.of, R.toUpper),
  122. get("state"),
  123. get("address"),
  124. get("user")
  125. );
  126. getStateCode({ user: { address: { state: "ny" } } }); //=> Maybe.Just("NY")
  127. getStateCode({}); //=> Maybe.Nothing()
  128. var db = {
  129. users: {
  130. JOE: {
  131. name: "Joe",
  132. followers: ["STEVE", "SUZY"]
  133. }
  134. }
  135. };
  136. // We'll pretend to do a db lookup which returns a promise
  137. var lookupUser = userId => Promise.resolve(db.users[userId]);
  138. var lookupFollowers = user => Promise.resolve(user.followers);
  139. lookupUser("JOE").then(lookupFollowers);
  140. // followersForUser :: String -> Promise [UserId]
  141. var followersForUser = R.composeP(lookupFollowers, lookupUser);
  142. followersForUser("JOE").then(followers => console.log("Followers:", followers));
  143. // Followers: ["STEVE","SUZY"]
  144. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  145. var classyGreeting = (firstName, lastName) =>
  146. "The name's " + lastName + ", " + firstName + " " + lastName;
  147. var yellGreeting = R.compose(
  148. R.toUpper,
  149. classyGreeting
  150. );
  151. yellGreeting("James", "Bond"); //=> "THE NAME'S BOND, JAMES BOND"
  152. R.compose(
  153. Math.abs,
  154. R.add(1),
  155. R.multiply(2)
  156. )(-4); //=> 7
  157. // get :: String -> Object -> Maybe *
  158. var get = R.curry((propName, obj) => Maybe(obj[propName]));
  159. // getStateCode :: Maybe String -> Maybe String
  160. var getStateCode = R.composeK(
  161. R.compose(
  162. Maybe.of,
  163. R.toUpper
  164. ),
  165. get("state"),
  166. get("address"),
  167. get("user")
  168. );
  169. getStateCode({ user: { address: { state: "ny" } } }); //=> Maybe.Just("NY")
  170. getStateCode({}); //=> Maybe.Nothing()
  171. var db = {
  172. users: {
  173. JOE: {
  174. name: "Joe",
  175. followers: ["STEVE", "SUZY"]
  176. }
  177. }
  178. };
  179. // We'll pretend to do a db lookup which returns a promise
  180. var lookupUser = userId => Promise.resolve(db.users[userId]);
  181. var lookupFollowers = user => Promise.resolve(user.followers);
  182. lookupUser("JOE").then(lookupFollowers);
  183. // followersForUser :: String -> Promise [UserId]
  184. var followersForUser = R.composeP(
  185. lookupFollowers,
  186. lookupUser
  187. );
  188. followersForUser("JOE").then(followers => console.log("Followers:", followers));
  189. // Followers: ["STEVE","SUZY"]
  190. `;
  191. exports[`ramda_pipe.js 1`] = `
  192. var f = R.pipe(Math.pow, R.negate, R.inc);
  193. f(3, 4); // -(3^4) + 1
  194. // parseJson :: String -> Maybe *
  195. // get :: String -> Object -> Maybe *
  196. // getStateCode :: Maybe String -> Maybe String
  197. var getStateCode = R.pipeK(
  198. parseJson,
  199. get("user"),
  200. get("address"),
  201. get("state"),
  202. R.compose(Maybe.of, R.toUpper)
  203. );
  204. getStateCode('{"user":{"address":{"state":"ny"}}}');
  205. //=> Just('NY')
  206. getStateCode("[Invalid JSON]");
  207. //=> Nothing()
  208. // followersForUser :: String -> Promise [User]
  209. var followersForUser = R.pipeP(db.getUserById, db.getFollowers);
  210. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  211. var f = R.pipe(
  212. Math.pow,
  213. R.negate,
  214. R.inc
  215. );
  216. f(3, 4); // -(3^4) + 1
  217. // parseJson :: String -> Maybe *
  218. // get :: String -> Object -> Maybe *
  219. // getStateCode :: Maybe String -> Maybe String
  220. var getStateCode = R.pipeK(
  221. parseJson,
  222. get("user"),
  223. get("address"),
  224. get("state"),
  225. R.compose(
  226. Maybe.of,
  227. R.toUpper
  228. )
  229. );
  230. getStateCode('{"user":{"address":{"state":"ny"}}}');
  231. //=> Just('NY')
  232. getStateCode("[Invalid JSON]");
  233. //=> Nothing()
  234. // followersForUser :: String -> Promise [User]
  235. var followersForUser = R.pipeP(
  236. db.getUserById,
  237. db.getFollowers
  238. );
  239. `;
  240. exports[`redux_compose.js 1`] = `
  241. import { createStore, applyMiddleware, compose } from 'redux';
  242. import thunk from 'redux-thunk';
  243. import DevTools from './containers/DevTools';
  244. import reducer from '../reducers';
  245. const store = createStore(
  246. reducer,
  247. compose(
  248. applyMiddleware(thunk),
  249. DevTools.instrument()
  250. )
  251. )
  252. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  253. import { createStore, applyMiddleware, compose } from "redux";
  254. import thunk from "redux-thunk";
  255. import DevTools from "./containers/DevTools";
  256. import reducer from "../reducers";
  257. const store = createStore(
  258. reducer,
  259. compose(
  260. applyMiddleware(thunk),
  261. DevTools.instrument()
  262. )
  263. );
  264. `;
  265. exports[`redux_connect.js 1`] = `
  266. const ArtistInput = connect(mapStateToProps, mapDispatchToProps, mergeProps)(Component);
  267. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  268. const ArtistInput = connect(
  269. mapStateToProps,
  270. mapDispatchToProps,
  271. mergeProps
  272. )(Component);
  273. `;
  274. exports[`rxjs_pipe.js 1`] = `
  275. import { range } from 'rxjs/observable/range';
  276. import { map, filter, scan } from 'rxjs/operators';
  277. const source$ = range(0, 10);
  278. source$.pipe(
  279. filter(x => x % 2 === 0),
  280. map(x => x + x),
  281. scan((acc, x) => acc + x, 0)
  282. )
  283. .subscribe(x => console.log(x))
  284. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  285. import { range } from "rxjs/observable/range";
  286. import { map, filter, scan } from "rxjs/operators";
  287. const source$ = range(0, 10);
  288. source$
  289. .pipe(
  290. filter(x => x % 2 === 0),
  291. map(x => x + x),
  292. scan((acc, x) => acc + x, 0)
  293. )
  294. .subscribe(x => console.log(x));
  295. `;