view rust/hg-core/src/testing.rs @ 45956:40f79997e81f

rust: fix non-utf8 char in requirements.rs Apparently Phabricator detect `rust/hg-core/src/requirements.rs` file as non utf8 ‽, and mark it as binary. During application it ended up being non-utf8 and this made Rust (and as a result heptapod) very angry:: error: couldn't read hg-core/src/requirements.rs: stream did not contain valid UTF-8 --> hg-core/src/lib.rs:11:9 | 11 | pub mod requirements; | ^^^^^^^^^^^^ error: aborting due to previous error error: could not compile `hg-core`. The after "fixing", the file content has no character matching the following regexp: [^0-9-a-zA-Z /(|).,{}!\[\]:"&=>?_*-;<`'#] So we should be fine, unless Phabricator does something funny again. Differential Revision: https://phab.mercurial-scm.org/D9444
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 28 Nov 2020 14:29:50 +0100
parents 168041fa6d5f
children 4c5f6e95df84
line wrap: on
line source

// testing.rs
//
// Copyright 2018 Georges Racinet <georges.racinet@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.

use crate::{Graph, GraphError, Revision, NULL_REVISION};

/// A stub `Graph`, same as the one from `test-ancestor.py`
///
/// o  13
/// |
/// | o  12
/// | |
/// | | o    11
/// | | |\
/// | | | | o  10
/// | | | | |
/// | o---+ |  9
/// | | | | |
/// o | | | |  8
///  / / / /
/// | | o |  7
/// | | | |
/// o---+ |  6
///  / / /
/// | | o  5
/// | |/
/// | o  4
/// | |
/// o |  3
/// | |
/// | o  2
/// |/
/// o  1
/// |
/// o  0
#[derive(Clone, Debug)]
pub struct SampleGraph;

impl Graph for SampleGraph {
    fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {
        match rev {
            0 => Ok([NULL_REVISION, NULL_REVISION]),
            1 => Ok([0, NULL_REVISION]),
            2 => Ok([1, NULL_REVISION]),
            3 => Ok([1, NULL_REVISION]),
            4 => Ok([2, NULL_REVISION]),
            5 => Ok([4, NULL_REVISION]),
            6 => Ok([4, NULL_REVISION]),
            7 => Ok([4, NULL_REVISION]),
            8 => Ok([NULL_REVISION, NULL_REVISION]),
            9 => Ok([6, 7]),
            10 => Ok([5, NULL_REVISION]),
            11 => Ok([3, 7]),
            12 => Ok([9, NULL_REVISION]),
            13 => Ok([8, NULL_REVISION]),
            r => Err(GraphError::ParentOutOfRange(r)),
        }
    }
}

// A Graph represented by a vector whose indices are revisions
// and values are parents of the revisions
pub type VecGraph = Vec<[Revision; 2]>;

impl Graph for VecGraph {
    fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError> {
        Ok(self[rev as usize])
    }
}