git-graph/git-graph-tests.el

71 lines
3.1 KiB
EmacsLisp

;;; git-graph-tests.el ---Tests for git-graph.el -*- lexical-binding: t -*-
;; Copyright (c) 2015 Correl Roush <correl@gmail.com>
;;; License:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;; Code:
(require 'ert)
(require 'stream)
(require 'git-graph)
;; 1---2---5---6---7 [master]
;; \ /
;; 3---4 [topic]
(ert-deftest automatically-group-nodes-list ()
(let* ((example-graph
(git-graph/group-topo
(list (git-graph/make-node 7 '(6) '((label . master)))
(git-graph/make-node 6 '(5 4))
(git-graph/make-node 5 '(2))
(git-graph/make-node 4 '(3) '((label . topic)))
(git-graph/make-node 3 '(2))
(git-graph/make-node 2 '(1))
(git-graph/make-node 1 '()))))
(master-nodes (seq-map #'git-graph/node-id
(seq-filter (lambda (node) (eq 7 (git-graph/node-group node)))
example-graph)))
(topic-nodes (seq-map #'git-graph/node-id
(seq-filter (lambda (node) (eq 4 (git-graph/node-group node)))
example-graph))))
(should (equal '(7 6 5 2 1) (seq-into-sequence master-nodes)))
(should (equal '(4 3) (seq-into-sequence topic-nodes)))))
(ert-deftest automatically-group-nodes-stream ()
(let* ((example-graph
(git-graph/group-topo
(stream (list (git-graph/make-node 7 '(6) '((label . master)))
(git-graph/make-node 6 '(5 4))
(git-graph/make-node 5 '(2))
(git-graph/make-node 4 '(3) '((label . topic)))
(git-graph/make-node 3 '(2))
(git-graph/make-node 2 '(1))
(git-graph/make-node 1 '())))))
(master-nodes (seq-map #'git-graph/node-id
(seq-filter (lambda (node) (eq 7 (git-graph/node-group node)))
example-graph)))
(topic-nodes (seq-map #'git-graph/node-id
(seq-filter (lambda (node) (eq 4 (git-graph/node-group node)))
example-graph))))
(should (equal '(7 6 5 2 1) (seq-into-sequence master-nodes)))
(should (equal '(4 3) (seq-into-sequence topic-nodes)))))
;;; git-graph-tests.el ends here